From dd2772f93129d1cc182f55a7f6abafe5af22ab6b Mon Sep 17 00:00:00 2001 From: daynewlee Date: Thu, 14 Nov 2024 14:55:29 -0600 Subject: [PATCH] epss: test parse Signed-off-by: daynewlee --- enricher/epss/epss_test.go | 51 +++++++++++++++++++++++++++++++++ enricher/epss/testdata/data.csv | 3 -- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/enricher/epss/epss_test.go b/enricher/epss/epss_test.go index a7c7f9beb..72ef5b505 100644 --- a/enricher/epss/epss_test.go +++ b/enricher/epss/epss_test.go @@ -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) + } +} diff --git a/enricher/epss/testdata/data.csv b/enricher/epss/testdata/data.csv index e65c76241..55c1eedc8 100644 --- a/enricher/epss/testdata/data.csv +++ b/enricher/epss/testdata/data.csv @@ -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