Skip to content

Commit

Permalink
epss: test enrich with fakeGetter
Browse files Browse the repository at this point in the history
Signed-off-by: daynewlee <[email protected]>
  • Loading branch information
daynewlee committed Nov 19, 2024
1 parent c9af788 commit a01fa33
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions enricher/epss/epss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package epss
import (
"compress/gzip"
"context"
"encoding/json"
"errors"
"fmt"
"github.com/quay/claircore/libvuln/driver"
"github.com/quay/zlog"
"io"
Expand Down Expand Up @@ -266,3 +268,26 @@ func (tc parseTestcase) Run(ctx context.Context, srv *httptest.Server) func(*tes
tc.Check(t, rs, err)
}
}

type fakeGetter struct {
items []map[string]string
res []driver.EnrichmentRecord
}

func (f *fakeGetter) GetEnrichment(ctx context.Context, tags []string) ([]driver.EnrichmentRecord, error) {
id := tags[0]
for _, item := range f.items {
if value, ok := item["id"]; ok && value == id {
enrichment, err := json.Marshal(item)
if err != nil {
return nil, fmt.Errorf("failed to encode enrichment: %w", err)
}
r := driver.EnrichmentRecord{
Tags: []string{item["cve"]},
Enrichment: enrichment,
}
f.res = []driver.EnrichmentRecord{r}
}
}
return f.res, nil
}

0 comments on commit a01fa33

Please sign in to comment.