Skip to content

Commit

Permalink
epss: test parse
Browse files Browse the repository at this point in the history
Signed-off-by: daynewlee <[email protected]>
  • Loading branch information
daynewlee committed Nov 14, 2024
1 parent 0497214 commit dd2772f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
51 changes: 51 additions & 0 deletions enricher/epss/epss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,54 @@ func (tc fetchTestcase) Run(ctx context.Context, srv *httptest.Server) func(*tes
}
}
}

func TestParse(t *testing.T) {
t.Parallel()
ctx := zlog.Test(context.Background(), t)
srv := mockServer(t)
tt := []parseTestcase{
{
Name: "OK",
},
}
for _, tc := range tt {
t.Run(tc.Name, tc.Run(ctx, srv))
}
}

type parseTestcase struct {
Check func(*testing.T, []driver.EnrichmentRecord, error)
Name string
}

func (tc parseTestcase) Run(ctx context.Context, srv *httptest.Server) func(*testing.T) {
e := &Enricher{}
return func(t *testing.T) {
ctx := zlog.Test(ctx, t)
f := func(i interface{}) error {
cfg, ok := i.(*Config)
if !ok {
t.Fatal("assertion failed")
}
u := srv.URL + "/data.csv.gz"
cfg.FeedRoot = &u
return nil
}
if err := e.Configure(ctx, f, srv.Client()); err != nil {
t.Errorf("unexpected error: %v", err)
}
rc, _, err := e.FetchEnrichment(ctx, "")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
defer rc.Close()
rs, err := e.ParseEnrichment(ctx, rc)
if tc.Check == nil {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
return
}
tc.Check(t, rs, err)
}
}
3 changes: 0 additions & 3 deletions enricher/epss/testdata/data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ CVE-2024-9972,0.00091,0.39923
CVE-2024-9973,0.00063,0.28042
CVE-2024-9974,0.00063,0.28042
CVE-2024-9975,0.00063,0.28515
CVE-2024-9976,0.00063,0.28042
CVE-2024-9977,0.00046,0.17291
CVE-2024-9979,0.00045,0.16569
CVE-2024-9980,0.00050,0.20281
CVE-2024-9981,0.00050,0.20281
CVE-2024-9982,0.00091,0.39923
Expand Down

0 comments on commit dd2772f

Please sign in to comment.