Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libvuln: implement DeltaUpdateVulnerabilities for jsonblob store #1345

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libvuln/jsonblob/jsonblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,11 @@ func (s *Store) RecordUpdaterSetStatus(ctx context.Context, updaterSet string, u
return nil
}

// DeltaUpdateVulnerabilities is a noop
// DeltaUpdateVulnerabilities just calls UpdateVulnerabilities. In the jsonblob flow it is assumed that
// we're always starting from zero.
// Note: deleted is ignored.
func (s *Store) DeltaUpdateVulnerabilities(ctx context.Context, updater string, fingerprint driver.Fingerprint, vulns []*claircore.Vulnerability, deleted []string) (uuid.UUID, error) {
return uuid.Nil, nil
return s.UpdateVulnerabilities(ctx, updater, fingerprint, vulns)
}

// UpdateEnrichmentsIter is unimplemented.
Expand Down
29 changes: 29 additions & 0 deletions libvuln/jsonblob/jsonblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,32 @@ func TestEnrichments(t *testing.T) {
}
t.Logf("wrote:\n%s", buf.String())
}

func TestDeltaUpdaters(t *testing.T) {
s, err := New()
if err != nil {
t.Fatal(err)
}
ctx := context.Background()

numVulns := 10
vs := test.GenUniqueVulnerabilities(numVulns, "test")
ref, err := s.DeltaUpdateVulnerabilities(ctx, "test", "", vs, []string{})
if err != nil {
t.Error(err)
}
t.Logf("ref: %v", ref)

var buf bytes.Buffer
if err := s.Store(&buf); err != nil {
t.Error(err)
}
t.Logf("wrote:\n%s", buf.String())
lnCt := 0
for _, err := buf.ReadBytes('\n'); err == nil; _, err = buf.ReadBytes('\n') {
lnCt++
}
if lnCt != numVulns {
t.Errorf("expected %d vulns but got %d", numVulns, lnCt)
}
}
Loading