diff --git a/go.mod b/go.mod index aa96706e67..5b617e901d 100644 --- a/go.mod +++ b/go.mod @@ -14,9 +14,10 @@ require ( github.com/klauspost/compress v1.10.11 github.com/mattn/go-sqlite3 v1.11.0 // indirect github.com/prometheus/procfs v0.3.0 // indirect - github.com/quay/claircore v0.1.20 + github.com/quay/claircore v0.2.0 + github.com/quay/zlog v0.0.0-20210113185248-ce16eed1dcec github.com/remind101/migrate v0.0.0-20170729031349-52c1edff7319 - github.com/rs/zerolog v1.16.0 + github.com/rs/zerolog v1.20.0 github.com/streadway/amqp v1.0.0 github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 github.com/urfave/cli/v2 v2.2.0 diff --git a/go.sum b/go.sum index 774b13b1bb..59d3610c73 100644 --- a/go.sum +++ b/go.sum @@ -621,10 +621,12 @@ github.com/prometheus/procfs v0.3.0 h1:Uehi/mxLK0eiUc0H0++5tpMGTexB8wZ598MIgU8Vp github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/quay/alas v1.0.1 h1:MuFpGGXyZlDD7+F/hrnMZmzhS8P2bjRzX9DyGmyLA+0= github.com/quay/alas v1.0.1/go.mod h1:pseepSrG9pwry1joG7RO/RNRFJaWqiqx9qeoomeYwEk= -github.com/quay/claircore v0.1.20 h1:vAghvmmS6dqph7/dYXFYQdC68jo0J9elcMOilQ6ag4M= -github.com/quay/claircore v0.1.20/go.mod h1:Q40RR0jWuYSg5qLglCX7WT5Q9yzmvnr0JkgBNRxPmoo= +github.com/quay/claircore v0.2.0 h1:UwxaWG7Jd0cSpsGfsmtqTkBXdVmbvTIXSpHtmjqlBOQ= +github.com/quay/claircore v0.2.0/go.mod h1:gDvglP5JVrQcH0ErSjcXtcqzub1aIkqUgeOfm8uoPRg= github.com/quay/goval-parser v0.8.6 h1:h1Xg3SZR/6I7UVa1LcsQZvQft/q7sJbosmFrjzSmdqE= github.com/quay/goval-parser v0.8.6/go.mod h1:Y0NTNfPYOC7yxsYKzJOrscTWUPq1+QbtHw4XpPXWPMc= +github.com/quay/zlog v0.0.0-20210113185248-ce16eed1dcec h1:v6gbUFTnms8pwArSDyE4rVK1ySLbxy9EQrbQqdOhAyY= +github.com/quay/zlog v0.0.0-20210113185248-ce16eed1dcec/go.mod h1:g+MQjOhV/hDsUIIRvp6JxM3RqCY3vcDgRO/xznpyv1o= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/remind101/migrate v0.0.0-20170729031349-52c1edff7319 h1:ukjThsA2ou7AmovpwtMVkNQSuoN/v5U16+JomTz3c7o= github.com/remind101/migrate v0.0.0-20170729031349-52c1edff7319/go.mod h1:rhSvwcijY9wfmrBYrfCvapX8/xOTV46NAUjBRgUyJqc= @@ -634,8 +636,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= -github.com/rs/zerolog v1.16.0 h1:AaELmZdcJHT8m6oZ5py4213cdFK8XGXkB3dFdAQ+P7Q= -github.com/rs/zerolog v1.16.0/go.mod h1:9nvC1axdVrAHcu/s9taAVfBuIdTZLVQmKQyvrUjF5+I= +github.com/rs/zerolog v1.20.0 h1:38k9hgtUBdxFwE34yS8rTHmHBa4eN16E4DJlv177LNs= +github.com/rs/zerolog v1.20.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo= github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= @@ -734,6 +736,7 @@ go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0. go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.16.0/go.mod h1:P5mQmVnXk429V+RQnY79cRDxP7KeFqEirKBXwQkvfPA= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.16.0 h1:hPbUH5fugPACtUdBWGL5glNqzowwHvnOdnwvQOATWgM= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.16.0/go.mod h1:dNF4PMGeouMEPAWDwgEjsGFlod9hAU8oj0TU0w2J19g= +go.opentelemetry.io/otel v0.15.0/go.mod h1:e4GKElweB8W2gWUqbghw0B8t5MCTccc9212eNHnOHwA= go.opentelemetry.io/otel v0.16.0 h1:uIWEbdeb4vpKPGITLsRVUS44L5oDbDUCZxn8lkxhmgw= go.opentelemetry.io/otel v0.16.0/go.mod h1:e4GKElweB8W2gWUqbghw0B8t5MCTccc9212eNHnOHwA= go.opentelemetry.io/otel/exporters/metric/prometheus v0.16.0 h1:0tB24Dht89vSfsD9JXO5HeEfan/Tb6eQk4U6s9a23qE= @@ -1139,7 +1142,6 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20191010095647-fc94e3f71652/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200506231410-2ff61e1afc86 h1:OfFoIUYv/me30yv7XlMy4F9RJw8DEm8WQ6QG1Ph4bH0= gopkg.in/yaml.v3 v3.0.0-20200506231410-2ff61e1afc86/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/httptransport/affectedmanifesthandler_test.go b/httptransport/affectedmanifesthandler_test.go index c7f0b4e032..47d8fad495 100644 --- a/httptransport/affectedmanifesthandler_test.go +++ b/httptransport/affectedmanifesthandler_test.go @@ -13,17 +13,6 @@ import ( "github.com/quay/claircore" ) -var _ indexer.Affected = (*affected)(nil) - -// affected implements indexer.Affected by calling the func members -type affected struct { - affectedManifests func(context.Context, []claircore.Vulnerability) (claircore.AffectedManifests, error) -} - -func (a *affected) AffectedManifests(ctx context.Context, v []claircore.Vulnerability) (claircore.AffectedManifests, error) { - return a.affectedManifests(ctx, v) -} - // TestAffectedManifestHandler is a parallel harness for testing an AffectedManifest handler. func TestAffectedManifestHandler(t *testing.T) { t.Run("IndexerOK", testAffectedManifestHandlerIndexerOK) @@ -33,9 +22,9 @@ func TestAffectedManifestHandler(t *testing.T) { func testAffectedManifestHandlerIndexerOK(t *testing.T) { t.Parallel() - h := AffectedManifestHandler(&affected{ - affectedManifests: func(context.Context, []claircore.Vulnerability) (claircore.AffectedManifests, error) { - return claircore.NewAffectedManifests(), nil + h := AffectedManifestHandler(&indexer.Mock{ + AffectedManifests_: func(context.Context, []claircore.Vulnerability) (*claircore.AffectedManifests, error) { + return &claircore.AffectedManifests{}, nil }, }) @@ -68,9 +57,9 @@ func testAffectedManifestHandlerIndexerOK(t *testing.T) { func testAffectedManifestHandlerIndexerErr(t *testing.T) { t.Parallel() - h := AffectedManifestHandler(&affected{ - affectedManifests: func(context.Context, []claircore.Vulnerability) (claircore.AffectedManifests, error) { - return claircore.NewAffectedManifests(), fmt.Errorf("error") + h := AffectedManifestHandler(&indexer.Mock{ + AffectedManifests_: func(context.Context, []claircore.Vulnerability) (*claircore.AffectedManifests, error) { + return nil, fmt.Errorf("failed") }, }) @@ -103,9 +92,9 @@ func testAffectedManifestHandlerIndexerErr(t *testing.T) { func testAffectedManifestHandlerMethods(t *testing.T) { t.Parallel() - h := AffectedManifestHandler(&affected{ - affectedManifests: func(context.Context, []claircore.Vulnerability) (claircore.AffectedManifests, error) { - return claircore.NewAffectedManifests(), nil + h := AffectedManifestHandler(&indexer.Mock{ + AffectedManifests_: func(context.Context, []claircore.Vulnerability) (*claircore.AffectedManifests, error) { + return &claircore.AffectedManifests{}, nil }, }) srv := httptest.NewServer(h) diff --git a/httptransport/client/indexer.go b/httptransport/client/indexer.go index 707bae00d5..fc1e40f393 100644 --- a/httptransport/client/indexer.go +++ b/httptransport/client/indexer.go @@ -17,7 +17,7 @@ import ( var _ indexer.Service = (*HTTP)(nil) -func (s *HTTP) AffectedManifests(ctx context.Context, v []claircore.Vulnerability) (claircore.AffectedManifests, error) { +func (s *HTTP) AffectedManifests(ctx context.Context, v []claircore.Vulnerability) (*claircore.AffectedManifests, error) { var affected claircore.AffectedManifests buf := bytes.NewBuffer([]byte{}) err := json.NewEncoder(buf).Encode(struct { @@ -26,29 +26,29 @@ func (s *HTTP) AffectedManifests(ctx context.Context, v []claircore.Vulnerabilit v, }) if err != nil { - return affected, &clairerror.ErrBadVulnerabilities{err} + return nil, &clairerror.ErrBadVulnerabilities{err} } u, err := s.addr.Parse(httptransport.AffectedManifestAPIPath) if err != nil { - return affected, fmt.Errorf("failed to parse api address: %v", err) + return nil, fmt.Errorf("failed to parse api address: %v", err) } req, err := http.NewRequestWithContext(ctx, "POST", u.String(), buf) if err != nil { - return affected, fmt.Errorf("failed to create request: %v", err) + return nil, fmt.Errorf("failed to create request: %v", err) } resp, err := s.c.Do(req) if resp != nil { defer resp.Body.Close() } if err != nil { - return affected, &clairerror.ErrRequestFail{Code: resp.StatusCode, Status: resp.Status} + return nil, &clairerror.ErrRequestFail{Code: resp.StatusCode, Status: resp.Status} } err = json.NewDecoder(resp.Body).Decode(&affected) if err != nil { - return affected, &clairerror.ErrBadAffectedManifests{err} + return nil, &clairerror.ErrBadAffectedManifests{err} } - return affected, nil + return &affected, nil } // Index receives a Manifest and returns a IndexReport providing the indexed diff --git a/httptransport/client/matcher.go b/httptransport/client/matcher.go index 170070d8ab..49f3ac72bb 100644 --- a/httptransport/client/matcher.go +++ b/httptransport/client/matcher.go @@ -57,10 +57,10 @@ func (c *HTTP) Scan(ctx context.Context, ir *claircore.IndexReport) (*claircore. } // DeleteUpdateOperations attempts to delete the referenced update operations. -func (c *HTTP) DeleteUpdateOperations(ctx context.Context, ref ...uuid.UUID) error { +func (c *HTTP) DeleteUpdateOperations(ctx context.Context, ref ...uuid.UUID) (int64, error) { u, err := c.addr.Parse(httptransport.UpdateOperationAPIPath) if err != nil { - return err + return 0, err } // Spawn a few requests that will write their result into "errs". @@ -110,8 +110,10 @@ func (c *HTTP) DeleteUpdateOperations(ctx context.Context, ref ...uuid.UUID) err var b strings.Builder var errd bool + var deleted = int64(len(ref)) for _, err := range errs { if err != nil { + deleted-- if errd { b.WriteByte('\n') } @@ -121,9 +123,9 @@ func (c *HTTP) DeleteUpdateOperations(ctx context.Context, ref ...uuid.UUID) err } if errd { - return errors.New("deletion errors: " + b.String()) + return deleted, errors.New("deletion errors: " + b.String()) } - return nil + return deleted, nil } // LatestUpdateOperation shouldn't be used by client code and is implemented diff --git a/httptransport/client/matcher_test.go b/httptransport/client/matcher_test.go index 45a61089f7..623d866f71 100644 --- a/httptransport/client/matcher_test.go +++ b/httptransport/client/matcher_test.go @@ -63,9 +63,13 @@ func TestDiffer(t *testing.T) { } // Do the call. - if err := c.DeleteUpdateOperations(ctx, refs...); err != nil { + deleted, err := c.DeleteUpdateOperations(ctx, refs...) + if err != nil { t.Error(err) } + if deleted != int64(len(refs)) { + t.Errorf("got: %v, want: %v", deleted, len(refs)) + } }) t.Run("Latest", func(t *testing.T) { diff --git a/httptransport/mock.go b/httptransport/mock.go deleted file mode 100644 index 498380a3af..0000000000 --- a/httptransport/mock.go +++ /dev/null @@ -1,81 +0,0 @@ -package httptransport - -import ( - "context" - - "github.com/google/uuid" - "github.com/quay/clair/v4/indexer" - "github.com/quay/claircore" - "github.com/quay/claircore/libvuln/driver" -) - -var _ indexer.Service = (*indexerMock)(nil) - -type indexerMock struct { - index func(ctx context.Context, manifest *claircore.Manifest) (*claircore.IndexReport, error) - report func(ctx context.Context, digest claircore.Digest) (*claircore.IndexReport, bool, error) - state func(ctx context.Context) (string, error) - affected func(ctx context.Context, vulns []claircore.Vulnerability) (claircore.AffectedManifests, error) -} - -func (i *indexerMock) Index(ctx context.Context, manifest *claircore.Manifest) (*claircore.IndexReport, error) { - return i.index(ctx, manifest) -} - -func (i *indexerMock) IndexReport(ctx context.Context, digest claircore.Digest) (*claircore.IndexReport, bool, error) { - return i.report(ctx, digest) -} - -func (i *indexerMock) State(ctx context.Context) (string, error) { - return i.state(ctx) -} - -func (i *indexerMock) AffectedManifests(ctx context.Context, vulns []claircore.Vulnerability) (claircore.AffectedManifests, error) { - return i.affected(ctx, vulns) -} - -// scanner implements the matcher.Scanner interface -type scanner struct { - scan func(context.Context, *claircore.IndexReport) (*claircore.VulnerabilityReport, error) -} - -func (s *scanner) Scan(ctx context.Context, ir *claircore.IndexReport) (*claircore.VulnerabilityReport, error) { - return s.scan(ctx, ir) -} - -// Differ implements matcher.Differ by calling the func members. -type differ struct { - delete func(context.Context, ...uuid.UUID) error - ops func(context.Context, ...string) (map[string][]driver.UpdateOperation, error) - latestOp func(context.Context) (uuid.UUID, error) - latestOps func(context.Context) (map[string][]driver.UpdateOperation, error) - updateDiff func(context.Context, uuid.UUID, uuid.UUID) (*driver.UpdateDiff, error) -} - -// DeleteUpdateOperations marks the provided refs as seen and processed. -func (d *differ) DeleteUpdateOperations(ctx context.Context, refs ...uuid.UUID) error { - return d.delete(ctx, refs...) -} - -// UpdateDiff reports the differences between the provided refs. -// -// "Prev" can be `uuid.Nil` to indicate "earliest known ref." -func (d *differ) UpdateDiff(ctx context.Context, prev uuid.UUID, cur uuid.UUID) (*driver.UpdateDiff, error) { - return d.updateDiff(ctx, prev, cur) -} - -// UpdateOperations returns all the known UpdateOperations per updater. -func (d *differ) UpdateOperations(ctx context.Context, updaters ...string) (map[string][]driver.UpdateOperation, error) { - return d.ops(ctx, updaters...) -} - -// LatestUpdateOperations returns the most recent UpdateOperation per updater. -func (d *differ) LatestUpdateOperations(ctx context.Context) (map[string][]driver.UpdateOperation, error) { - return d.latestOps(ctx) -} - -// LatestUpdateOperation returns a ref for the most recent update operation -// across all updaters. -func (d *differ) LatestUpdateOperation(ctx context.Context) (uuid.UUID, error) { - return d.latestOp(ctx) -} diff --git a/httptransport/server_test.go b/httptransport/server_test.go index 81c6297d2c..d42d6f6491 100644 --- a/httptransport/server_test.go +++ b/httptransport/server_test.go @@ -9,62 +9,45 @@ import ( "testing" "github.com/google/uuid" + "github.com/quay/clair/v4/indexer" + "github.com/quay/clair/v4/matcher" "github.com/quay/claircore" "github.com/quay/claircore/libvuln/driver" - "github.com/quay/claircore/test/log" + "github.com/quay/zlog" othttp "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" "go.opentelemetry.io/otel" ) -type testMatcher struct { - scanner - differ -} - -// NewTestMatcher returns a testMatcher with all functions set to non-nil stubs. -func newTestMatcher() *testMatcher { - return &testMatcher{ - scanner: scanner{ - scan: func(context.Context, *claircore.IndexReport) (*claircore.VulnerabilityReport, error) { return nil, nil }, - }, - differ: differ{ - delete: func(context.Context, ...uuid.UUID) error { return nil }, - ops: func(context.Context, ...string) (map[string][]driver.UpdateOperation, error) { return nil, nil }, - latestOp: func(context.Context) (uuid.UUID, error) { return uuid.Nil, nil }, - latestOps: func(context.Context) (map[string][]driver.UpdateOperation, error) { return nil, nil }, - updateDiff: func(context.Context, uuid.UUID, uuid.UUID) (*driver.UpdateDiff, error) { return nil, nil }, - }, +// TestUpdateEndpoints registers the handlers and tests that they're registered +// at the correct endpoint. +func TestUpdateEndpoints(t *testing.T) { + m := &matcher.Mock{ + DeleteUpdateOperations_: func(context.Context, ...uuid.UUID) (int64, error) { return 0, nil }, + UpdateOperations_: func(context.Context, ...string) (map[string][]driver.UpdateOperation, error) { return nil, nil }, + LatestUpdateOperation_: func(context.Context) (uuid.UUID, error) { return uuid.Nil, nil }, + LatestUpdateOperations_: func(context.Context) (map[string][]driver.UpdateOperation, error) { return nil, nil }, + UpdateDiff_: func(context.Context, uuid.UUID, uuid.UUID) (*driver.UpdateDiff, error) { return nil, nil }, + Scan_: func(context.Context, *claircore.IndexReport) (*claircore.VulnerabilityReport, error) { return nil, nil }, } -} - -func newTestIndexer() *indexerMock { - return &indexerMock{ - index: func(ctx context.Context, manifest *claircore.Manifest) (*claircore.IndexReport, error) { + i := &indexer.Mock{ + Index_: func(ctx context.Context, manifest *claircore.Manifest) (*claircore.IndexReport, error) { return nil, nil }, - report: func(ctx context.Context, digest claircore.Digest) (*claircore.IndexReport, bool, error) { + IndexReport_: func(ctx context.Context, digest claircore.Digest) (*claircore.IndexReport, bool, error) { return nil, true, nil }, - state: func(ctx context.Context) (string, error) { return "", nil }, - affected: func(ctx context.Context, vulns []claircore.Vulnerability) (claircore.AffectedManifests, error) { - return claircore.NewAffectedManifests(), nil + State_: func(ctx context.Context) (string, error) { return "", nil }, + AffectedManifests_: func(ctx context.Context, vulns []claircore.Vulnerability) (*claircore.AffectedManifests, error) { + return nil, nil }, } -} - -// TestUpdateEndpoints registers the handlers and tests that they're registered -// at the correct endpoint. -func TestUpdateEndpoints(t *testing.T) { - m := newTestMatcher() - i := newTestIndexer() s := &Server{ matcher: m, indexer: i, ServeMux: http.NewServeMux(), traceOpt: othttp.WithTracerProvider(otel.GetTracerProvider()), } - ctx, done := log.TestLogger(context.Background(), t) - defer done() + ctx := zlog.Test(context.Background(), t) if err := s.configureMatcherMode(ctx); err != nil { t.Error(err) } diff --git a/httptransport/updatediffhandler_test.go b/httptransport/updatediffhandler_test.go index 484da3e889..92fc7b2d93 100644 --- a/httptransport/updatediffhandler_test.go +++ b/httptransport/updatediffhandler_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/google/uuid" + "github.com/quay/clair/v4/matcher" "github.com/quay/claircore/libvuln/driver" ) @@ -23,11 +24,11 @@ func TestUpdateDiffHandler(t *testing.T) { // the correct status codes when a matcher returns an error or success func testUpdateDiffMatcher(t *testing.T) { t.Parallel() - hOK := UpdateDiffHandler(&differ{ - updateDiff: func(context.Context, uuid.UUID, uuid.UUID) (*driver.UpdateDiff, error) { return nil, nil }, + hOK := UpdateDiffHandler(&matcher.Mock{ + UpdateDiff_: func(context.Context, uuid.UUID, uuid.UUID) (*driver.UpdateDiff, error) { return nil, nil }, }) - hErr := UpdateDiffHandler(&differ{ - updateDiff: func(context.Context, uuid.UUID, uuid.UUID) (*driver.UpdateDiff, error) { + hErr := UpdateDiffHandler(&matcher.Mock{ + UpdateDiff_: func(context.Context, uuid.UUID, uuid.UUID) (*driver.UpdateDiff, error) { return nil, fmt.Errorf("expected error") }, }) @@ -119,8 +120,8 @@ func testUpdateDiffHandlerParams(t *testing.T) { }, } - h := UpdateDiffHandler(&differ{ - updateDiff: func(context.Context, uuid.UUID, uuid.UUID) (*driver.UpdateDiff, error) { return nil, nil }, + h := UpdateDiffHandler(&matcher.Mock{ + UpdateDiff_: func(context.Context, uuid.UUID, uuid.UUID) (*driver.UpdateDiff, error) { return nil, nil }, }) srv := httptest.NewServer(h) defer srv.Close() @@ -157,8 +158,8 @@ func testUpdateDiffHandlerParams(t *testing.T) { // to unaccepted HTTP methods. func testUpdateDiffHandlerMethods(t *testing.T) { t.Parallel() - h := UpdateDiffHandler(&differ{ - updateDiff: func(context.Context, uuid.UUID, uuid.UUID) (*driver.UpdateDiff, error) { return nil, nil }, + h := UpdateDiffHandler(&matcher.Mock{ + UpdateDiff_: func(context.Context, uuid.UUID, uuid.UUID) (*driver.UpdateDiff, error) { return nil, nil }, }) srv := httptest.NewServer(h) defer srv.Close() diff --git a/httptransport/updateoperationhandler.go b/httptransport/updateoperationhandler.go index 7e59ff64ec..8c9449d137 100644 --- a/httptransport/updateoperationhandler.go +++ b/httptransport/updateoperationhandler.go @@ -107,7 +107,7 @@ func (h *UOHandler) Delete(w http.ResponseWriter, r *http.Request) { return } - err = h.serv.DeleteUpdateOperations(ctx, uuid) + _, err = h.serv.DeleteUpdateOperations(ctx, uuid) if err != nil { resp := &je.Response{ Code: "internal server error", diff --git a/httptransport/updateoperationhandler_test.go b/httptransport/updateoperationhandler_test.go index a26c0e4fbd..01a89395e6 100644 --- a/httptransport/updateoperationhandler_test.go +++ b/httptransport/updateoperationhandler_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/google/uuid" + "github.com/quay/clair/v4/matcher" "github.com/quay/claircore/libvuln/driver" ) @@ -27,16 +28,16 @@ func testUpdateOperationHandlerErrors(t *testing.T) { id := uuid.New().String() var ErrExpected error = fmt.Errorf("expected error") - h := UpdateOperationHandler(&differ{ - delete: func(context.Context, ...uuid.UUID) error { return ErrExpected }, - // this will not immediately faile the handler - latestOp: func(context.Context) (uuid.UUID, error) { + h := UpdateOperationHandler(&matcher.Mock{ + DeleteUpdateOperations_: func(context.Context, ...uuid.UUID) (int64, error) { return 0, ErrExpected }, + // this will not immediately fail the handler + LatestUpdateOperation_: func(context.Context) (uuid.UUID, error) { return uuid.Nil, ErrExpected }, - latestOps: func(context.Context) (map[string][]driver.UpdateOperation, error) { + LatestUpdateOperations_: func(context.Context) (map[string][]driver.UpdateOperation, error) { return nil, ErrExpected }, - ops: func(context.Context, ...string) (map[string][]driver.UpdateOperation, error) { + UpdateOperations_: func(context.Context, ...string) (map[string][]driver.UpdateOperation, error) { return nil, ErrExpected }, }) @@ -76,7 +77,7 @@ func testUpdateOperationHandlerErrors(t *testing.T) { // to the desired methods. func testUpdateOperationHandlerMethods(t *testing.T) { t.Parallel() - h := UpdateOperationHandler(&differ{}) + h := UpdateOperationHandler(&matcher.Mock{}) srv := httptest.NewServer(h) defer srv.Close() c := srv.Client() @@ -109,8 +110,8 @@ func testUpdateOperationHandlerMethods(t *testing.T) { func testUpdateOperationDelete(t *testing.T) { t.Parallel() - h := UpdateOperationHandler(&differ{ - delete: func(context.Context, ...uuid.UUID) error { return nil }, + h := UpdateOperationHandler(&matcher.Mock{ + DeleteUpdateOperations_: func(context.Context, ...uuid.UUID) (int64, error) { return 0, nil }, }) srv := httptest.NewServer(h) defer srv.Close() @@ -141,15 +142,15 @@ func testUpdateOperationHandlerGet(t *testing.T) { idStr := "\"" + id.String() + "\"" var called bool var latestCalled bool - h := UpdateOperationHandler(&differ{ - latestOp: func(context.Context) (uuid.UUID, error) { + h := UpdateOperationHandler(&matcher.Mock{ + LatestUpdateOperation_: func(context.Context) (uuid.UUID, error) { return id, nil }, - latestOps: func(context.Context) (map[string][]driver.UpdateOperation, error) { + LatestUpdateOperations_: func(context.Context) (map[string][]driver.UpdateOperation, error) { latestCalled = true return nil, nil }, - ops: func(context.Context, ...string) (map[string][]driver.UpdateOperation, error) { + UpdateOperations_: func(context.Context, ...string) (map[string][]driver.UpdateOperation, error) { called = true return nil, nil }, diff --git a/indexer/mock.go b/indexer/mock.go index bde309de55..8e0bd1f223 100644 --- a/indexer/mock.go +++ b/indexer/mock.go @@ -9,25 +9,40 @@ import ( var _ Service = (*Mock)(nil) // Mock implements a mock indexer Service +// +// If a particular method is not provided an implementation to a constructed Mock +// an "unexpected call" panic will occur. type Mock struct { Index_ func(ctx context.Context, manifest *claircore.Manifest) (*claircore.IndexReport, error) IndexReport_ func(ctx context.Context, digest claircore.Digest) (*claircore.IndexReport, bool, error) State_ func(ctx context.Context) (string, error) - AffectedManifests_ func(ctx context.Context, vulns []claircore.Vulnerability) (claircore.AffectedManifests, error) + AffectedManifests_ func(ctx context.Context, vulns []claircore.Vulnerability) (*claircore.AffectedManifests, error) } func (i *Mock) Index(ctx context.Context, manifest *claircore.Manifest) (*claircore.IndexReport, error) { + if i.Index_ == nil { + panic("mock indexer: unexpected call to Index") + } return i.Index_(ctx, manifest) } func (i *Mock) IndexReport(ctx context.Context, digest claircore.Digest) (*claircore.IndexReport, bool, error) { + if i.IndexReport_ == nil { + panic("mock indexer: unexpected call to IndexReport") + } return i.IndexReport_(ctx, digest) } func (i *Mock) State(ctx context.Context) (string, error) { + if i.State_ == nil { + panic("mock indexer: unexpected call to State") + } return i.State_(ctx) } -func (i *Mock) AffectedManifests(ctx context.Context, vulns []claircore.Vulnerability) (claircore.AffectedManifests, error) { +func (i *Mock) AffectedManifests(ctx context.Context, vulns []claircore.Vulnerability) (*claircore.AffectedManifests, error) { + if i.AffectedManifests_ == nil { + panic("mock indexer: unexpected call to AffectedManifests") + } return i.AffectedManifests_(ctx, vulns) } diff --git a/indexer/service.go b/indexer/service.go index 81e29beca2..d39f437640 100644 --- a/indexer/service.go +++ b/indexer/service.go @@ -48,5 +48,5 @@ type Stater interface { // Affected is an interface for reporting the manifests affected by a set of vulnerabilities. type Affected interface { - AffectedManifests(ctx context.Context, vulns []claircore.Vulnerability) (claircore.AffectedManifests, error) + AffectedManifests(ctx context.Context, vulns []claircore.Vulnerability) (*claircore.AffectedManifests, error) } diff --git a/matcher/mock.go b/matcher/mock.go index bec8c8a243..b7af11c618 100644 --- a/matcher/mock.go +++ b/matcher/mock.go @@ -12,8 +12,11 @@ import ( var _ Service = (*Mock)(nil) // Mock implements a mock matcher service +// +// If a method is not provided to a constructed Mock a panic +// will occur on call. type Mock struct { - DeleteUpdateOperations_ func(context.Context, ...uuid.UUID) error + DeleteUpdateOperations_ func(context.Context, ...uuid.UUID) (int64, error) UpdateOperations_ func(context.Context, ...string) (map[string][]driver.UpdateOperation, error) LatestUpdateOperation_ func(context.Context) (uuid.UUID, error) LatestUpdateOperations_ func(context.Context) (map[string][]driver.UpdateOperation, error) @@ -26,7 +29,10 @@ type Mock struct { } // DeleteUpdateOperations marks the provided refs as seen and processed. -func (d *Mock) DeleteUpdateOperations(ctx context.Context, refs ...uuid.UUID) error { +func (d *Mock) DeleteUpdateOperations(ctx context.Context, refs ...uuid.UUID) (int64, error) { + if d.DeleteUpdateOperations_ == nil { + panic("mock matcher: unexpected call to DeleteUpdateOperations") + } return d.DeleteUpdateOperations_(ctx, refs...) } @@ -34,25 +40,40 @@ func (d *Mock) DeleteUpdateOperations(ctx context.Context, refs ...uuid.UUID) er // // "Prev" can be `uuid.Nil` to indicate "earliest known ref." func (d *Mock) UpdateDiff(ctx context.Context, prev uuid.UUID, cur uuid.UUID) (*driver.UpdateDiff, error) { + if d.UpdateDiff_ == nil { + panic("mock matcher: unexpected call to UpdateDiff") + } return d.UpdateDiff_(ctx, prev, cur) } // UpdateOperations returns all the known UpdateOperations per updater. func (d *Mock) UpdateOperations(ctx context.Context, updaters ...string) (map[string][]driver.UpdateOperation, error) { + if d.UpdateOperations_ == nil { + panic("mock matcher: unexpected call to UpdateOperations") + } return d.UpdateOperations_(ctx, updaters...) } // LatestUpdateOperations returns the most recent UpdateOperation per updater. func (d *Mock) LatestUpdateOperations(ctx context.Context) (map[string][]driver.UpdateOperation, error) { + if d.LatestUpdateOperations_ == nil { + panic("mock matcher: unexpected call to LatestUpdateOperations") + } return d.LatestUpdateOperations_(ctx) } // LatestUpdateOperation returns a ref for the most recent update operation // across all updaters. func (d *Mock) LatestUpdateOperation(ctx context.Context) (uuid.UUID, error) { + if d.LatestUpdateOperation_ == nil { + panic("mock matcher: unexpected call to LatestUpdateOperation") + } return d.LatestUpdateOperation_(ctx) } -func (s *Mock) Scan(ctx context.Context, ir *claircore.IndexReport) (*claircore.VulnerabilityReport, error) { - return s.Scan_(ctx, ir) +func (d *Mock) Scan(ctx context.Context, ir *claircore.IndexReport) (*claircore.VulnerabilityReport, error) { + if d.Scan_ == nil { + panic("mock matcher: unexpected call to Scan") + } + return d.Scan_(ctx, ir) } diff --git a/matcher/service.go b/matcher/service.go index 2893c4e182..d6033d8814 100644 --- a/matcher/service.go +++ b/matcher/service.go @@ -25,7 +25,7 @@ type Scanner interface { // Differ is an interface providing information on update operations. type Differ interface { // DeleteUpdateOperations marks the provided refs as seen and processed. - DeleteUpdateOperations(context.Context, ...uuid.UUID) error + DeleteUpdateOperations(context.Context, ...uuid.UUID) (int64, error) // UpdateDiff reports the differences between the provided refs. // // "Prev" can be `uuid.Nil` to indicate "earliest known ref." diff --git a/notifier/postgres/keystore_test.go b/notifier/postgres/keystore_test.go index 9e228a7d32..e37af57fdd 100644 --- a/notifier/postgres/keystore_test.go +++ b/notifier/postgres/keystore_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/uuid" "github.com/quay/claircore/test/integration" - "github.com/quay/claircore/test/log" + "github.com/quay/zlog" clairerror "github.com/quay/clair/v4/clair-error" "github.com/quay/clair/v4/notifier/keymanager" @@ -52,8 +52,7 @@ func TestKeyStore(t *testing.T) { func testKeyStoreGC(t *testing.T) { integration.Skip(t) t.Parallel() - ctx, done := log.TestLogger(context.Background(), t) - defer done() + ctx := zlog.Test(context.Background(), t) db, _, keystore, teardown := postgres.TestStore(ctx, t) defer teardown() @@ -106,8 +105,7 @@ func testKeyStoreGC(t *testing.T) { func testKeyStore(t *testing.T) { integration.Skip(t) t.Parallel() - ctx, done := log.TestLogger(context.Background(), t) - defer done() + ctx := zlog.Test(context.Background(), t) _, _, keystore, teardown := postgres.TestStore(ctx, t) defer teardown() diff --git a/notifier/postgres/notification_pagination_test.go b/notifier/postgres/notification_pagination_test.go index b2f4e494dc..0323a263e6 100644 --- a/notifier/postgres/notification_pagination_test.go +++ b/notifier/postgres/notification_pagination_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/uuid" "github.com/quay/claircore" "github.com/quay/claircore/test/integration" - "github.com/quay/claircore/test/log" + "github.com/quay/zlog" "github.com/quay/clair/v4/notifier" ) @@ -72,8 +72,7 @@ func TestNotePagination(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() ctx := context.Background() - ctx, done := log.TestLogger(ctx, t) - defer done() + ctx = zlog.Test(ctx, t) _, store, _, _ := TestStore(ctx, t) noteID := uuid.New() diff --git a/notifier/processor.go b/notifier/processor.go index c3055c0683..8c30633a1a 100644 --- a/notifier/processor.go +++ b/notifier/processor.go @@ -151,7 +151,7 @@ func (p *Processor) create(ctx context.Context, e Event, prev uuid.UUID) error { } notifications := []Notification{} - create := func(r Reason, affected claircore.AffectedManifests) error { + create := func(r Reason, affected *claircore.AffectedManifests) error { for manifest, vulns := range affected.VulnerableManifests { digest, err := claircore.ParseDigest(manifest) if err != nil { diff --git a/notifier/processor_create_test.go b/notifier/processor_create_test.go index 57c15c35c0..c8b1c8ecc8 100644 --- a/notifier/processor_create_test.go +++ b/notifier/processor_create_test.go @@ -32,7 +32,7 @@ var ( vulnAdd.ID: vulnAdd, }, VulnerableManifests: map[string][]string{ - manifestAdd: []string{vulnAdd.ID}, + manifestAdd: {vulnAdd.ID}, }, } affectedManifestsRemoved = &claircore.AffectedManifests{ @@ -40,7 +40,7 @@ var ( vulnRemoved.ID: vulnRemoved, }, VulnerableManifests: map[string][]string{ - manifestRemoved: []string{vulnRemoved.ID}, + manifestRemoved: {vulnRemoved.ID}, }, } notifications = []Notification{ @@ -90,11 +90,11 @@ func testProcessorStoreErr(t *testing.T) { }, } im := &indexer.Mock{ - AffectedManifests_: func(ctx context.Context, vulns []claircore.Vulnerability) (claircore.AffectedManifests, error) { + AffectedManifests_: func(ctx context.Context, vulns []claircore.Vulnerability) (*claircore.AffectedManifests, error) { // needs to be populated. // create method needs at least one affected manifest // for the code path to invoke store.PutNotifications() - return *affectedManifestsAdd, nil + return affectedManifestsAdd, nil }, } // perform bulk of checks in this mock method. @@ -135,8 +135,8 @@ func testProcessorIndexerErr(t *testing.T) { }, } im := &indexer.Mock{ - AffectedManifests_: func(ctx context.Context, vulns []claircore.Vulnerability) (claircore.AffectedManifests, error) { - return claircore.AffectedManifests{}, fmt.Errorf("expected") + AffectedManifests_: func(ctx context.Context, vulns []claircore.Vulnerability) (*claircore.AffectedManifests, error) { + return nil, fmt.Errorf("expected") }, } // perform bulk of checks in this mock method. @@ -174,8 +174,8 @@ func testProcessorMatcherErr(t *testing.T) { }, } im := &indexer.Mock{ - AffectedManifests_: func(ctx context.Context, vulns []claircore.Vulnerability) (claircore.AffectedManifests, error) { - return claircore.AffectedManifests{}, nil + AffectedManifests_: func(ctx context.Context, vulns []claircore.Vulnerability) (*claircore.AffectedManifests, error) { + return &claircore.AffectedManifests{}, nil }, } // perform bulk of checks in this mock method. @@ -216,15 +216,15 @@ func testProcessorCreate(t *testing.T) { } count := 0 im := &indexer.Mock{ - AffectedManifests_: func(ctx context.Context, vulns []claircore.Vulnerability) (claircore.AffectedManifests, error) { + AffectedManifests_: func(ctx context.Context, vulns []claircore.Vulnerability) (*claircore.AffectedManifests, error) { switch count { case 0: count++ - return *affectedManifestsAdd, nil + return affectedManifestsAdd, nil case 1: - return *affectedManifestsRemoved, nil + return affectedManifestsRemoved, nil default: - return claircore.AffectedManifests{}, fmt.Errorf("unexpected number of calls") + return nil, fmt.Errorf("unexpected number of calls") } }, } diff --git a/notifier/service/service.go b/notifier/service/service.go index 895e93ef75..ac093627b1 100644 --- a/notifier/service/service.go +++ b/notifier/service/service.go @@ -2,6 +2,7 @@ package service import ( "context" + "database/sql" "fmt" "net/http" "os" @@ -9,7 +10,7 @@ import ( "github.com/google/uuid" "github.com/jackc/pgx/v4/pgxpool" - "github.com/jmoiron/sqlx" + _ "github.com/jackc/pgx/v4/stdlib" pgdl "github.com/quay/claircore/pkg/distlock/postgres" "github.com/remind101/migrate" "github.com/rs/zerolog" @@ -121,7 +122,7 @@ func New(ctx context.Context, opts Opts) (*service, error) { log.Info().Int("count", processors).Msg("initializing processors") for i := 0; i < processors; i++ { // processors only use try locks - distLock := pgdl.NewLock(lockPool, 0) + distLock := pgdl.NewPool(lockPool, 0) p := notifier.NewProcessor( i, distLock, @@ -168,7 +169,7 @@ func testModeInit(ctx context.Context, opts *Opts) error { return nil } -func storeInit(ctx context.Context, opts Opts) (*postgres.Store, *postgres.KeyStore, *sqlx.DB, error) { +func storeInit(ctx context.Context, opts Opts) (*postgres.Store, *postgres.KeyStore, *pgxpool.Pool, error) { log := zerolog.Ctx(ctx).With(). Str("component", "notifier/service/storeInit"). Logger() @@ -184,15 +185,16 @@ func storeInit(ctx context.Context, opts Opts) (*postgres.Store, *postgres.KeySt return nil, nil, nil, fmt.Errorf("failed to create ConnPool: %v", err) } - lockPool, err := sqlx.Connect("pgx", opts.ConnString) + db, err := sql.Open("pgx", opts.ConnString) if err != nil { - return nil, nil, nil, fmt.Errorf("failed to create lock ConnPool: %v", err) + return nil, nil, nil, fmt.Errorf("failed to open db: %v", err) } + defer db.Close() // do migrations if requested if opts.Migrations { log.Info().Msg("performing notifier migrations") - migrator := migrate.NewPostgresMigrator(lockPool.DB) + migrator := migrate.NewPostgresMigrator(db) migrator.Table = migrations.MigrationTable err := migrator.Exec(migrate.Up, migrations.Migrations...) if err != nil { @@ -203,7 +205,7 @@ func storeInit(ctx context.Context, opts Opts) (*postgres.Store, *postgres.KeySt log.Info().Msg("initializing notifier store") store := postgres.NewStore(pool) keystore := postgres.NewKeyStore(pool) - return store, keystore, lockPool, nil + return store, keystore, pool, nil } func keyManagerInit(ctx context.Context, keystore notifier.KeyStore) (*keymanager.Manager, error) { @@ -220,7 +222,7 @@ func keyManagerInit(ctx context.Context, keystore notifier.KeyStore) (*keymanage return mgr, nil } -func webhookDeliveries(ctx context.Context, opts Opts, lockPool *sqlx.DB, store notifier.Store, keymanager *keymanager.Manager) error { +func webhookDeliveries(ctx context.Context, opts Opts, lockPool *pgxpool.Pool, store notifier.Store, keymanager *keymanager.Manager) error { log := zerolog.Ctx(ctx).With(). Str("component", "notifier/service/webhookInit"). Logger() @@ -234,7 +236,7 @@ func webhookDeliveries(ctx context.Context, opts Opts, lockPool *sqlx.DB, store ds := make([]*notifier.Delivery, 0, deliveries) for i := 0; i < deliveries; i++ { - distLock := pgdl.NewLock(lockPool, 0) + distLock := pgdl.NewPool(lockPool, 0) wh, err := webhook.New(conf, opts.Client, keymanager) if err != nil { return fmt.Errorf("failed to create webhook deliverer: %v", err) @@ -248,7 +250,7 @@ func webhookDeliveries(ctx context.Context, opts Opts, lockPool *sqlx.DB, store return nil } -func amqpDeliveries(ctx context.Context, opts Opts, lockPool *sqlx.DB, store notifier.Store) error { +func amqpDeliveries(ctx context.Context, opts Opts, lockPool *pgxpool.Pool, store notifier.Store) error { log := zerolog.Ctx(ctx).With(). Str("component", "notifier/service/amqpInit"). Logger() @@ -266,7 +268,7 @@ func amqpDeliveries(ctx context.Context, opts Opts, lockPool *sqlx.DB, store not ds := make([]*notifier.Delivery, 0, deliveries) for i := 0; i < deliveries; i++ { - distLock := pgdl.NewLock(lockPool, 0) + distLock := pgdl.NewPool(lockPool, 0) if conf.Direct { q, err := namqp.NewDirectDeliverer(conf) if err != nil { @@ -290,7 +292,7 @@ func amqpDeliveries(ctx context.Context, opts Opts, lockPool *sqlx.DB, store not return nil } -func stompDeliveries(ctx context.Context, opts Opts, lockPool *sqlx.DB, store notifier.Store) error { +func stompDeliveries(ctx context.Context, opts Opts, lockPool *pgxpool.Pool, store notifier.Store) error { log := zerolog.Ctx(ctx).With(). Str("component", "notifier/service/stompInit"). Logger() @@ -308,7 +310,7 @@ func stompDeliveries(ctx context.Context, opts Opts, lockPool *sqlx.DB, store no ds := make([]*notifier.Delivery, 0, deliveries) for i := 0; i < deliveries; i++ { - distLock := pgdl.NewLock(lockPool, 0) + distLock := pgdl.NewPool(lockPool, 0) if conf.Direct { q, err := stomp.NewDirectDeliverer(conf) if err != nil { diff --git a/notifier/service/testmode.go b/notifier/service/testmode.go index 3eeca6a32c..4df588744c 100644 --- a/notifier/service/testmode.go +++ b/notifier/service/testmode.go @@ -18,26 +18,26 @@ import ( // in notifier test mode a notifier.Processor will request "indexer.AffectedManifest" with a // set of vulnerabilities at which point we will return a mock affected vulnerability. func indexerForTestMode(mock *indexer.Mock) { - affectedManifests := func(ctx context.Context, vulns []claircore.Vulnerability) (claircore.AffectedManifests, error) { + affectedManifests := func(ctx context.Context, vulns []claircore.Vulnerability) (*claircore.AffectedManifests, error) { if len(vulns) == 0 { - return claircore.NewAffectedManifests(), nil + return &claircore.AffectedManifests{}, nil } data := make([]byte, sha256.Size) _, err := rand.Read(data) if err != nil { - return claircore.AffectedManifests{}, err + return nil, err } digest, err := claircore.NewDigest("sha256", data) if err != nil { - return claircore.AffectedManifests{}, err + return nil, err } - am := claircore.AffectedManifests{ + am := &claircore.AffectedManifests{ Vulnerabilities: map[string]*claircore.Vulnerability{ vulns[0].ID: &(vulns[0]), }, VulnerableManifests: map[string][]string{ - digest.String(): []string{vulns[0].ID}, + digest.String(): {vulns[0].ID}, }, } return am, nil diff --git a/notifier/stomp/deliverer_integration_test.go b/notifier/stomp/deliverer_integration_test.go index ce79003f65..6e71fa15f8 100644 --- a/notifier/stomp/deliverer_integration_test.go +++ b/notifier/stomp/deliverer_integration_test.go @@ -8,7 +8,7 @@ import ( "github.com/google/uuid" "github.com/quay/claircore/test/integration" - "github.com/quay/claircore/test/log" + "github.com/quay/zlog" "golang.org/x/sync/errgroup" ) @@ -20,8 +20,7 @@ const ( // callback is successfully delivered to the stomp broker. func TestDeliverer(t *testing.T) { integration.Skip(t) - ctx, done := log.TestLogger(context.Background(), t) - defer done() + ctx := zlog.Test(context.Background(), t) const ( callback = "http://clair-notifier/notifier/api/v1/notifications" ) diff --git a/notifier/stomp/directdeliverer_integration_test.go b/notifier/stomp/directdeliverer_integration_test.go index cb68ff22d1..4b3fac5f7c 100644 --- a/notifier/stomp/directdeliverer_integration_test.go +++ b/notifier/stomp/directdeliverer_integration_test.go @@ -9,7 +9,7 @@ import ( "github.com/google/uuid" "github.com/quay/claircore" "github.com/quay/claircore/test/integration" - "github.com/quay/claircore/test/log" + "github.com/quay/zlog" "golang.org/x/sync/errgroup" "github.com/quay/clair/v4/notifier" @@ -68,8 +68,7 @@ func TestDirectDeliverer(t *testing.T) { } for _, tt := range table { t.Run(tt.name, func(t *testing.T) { - ctx, done := log.TestLogger(context.Background(), t) - defer done() + ctx := zlog.Test(context.Background(), t) // deliverer test conf := Config{ Direct: true, diff --git a/notifier/summary_test.go b/notifier/summary_test.go index 38854902f7..2ad1b542fa 100644 --- a/notifier/summary_test.go +++ b/notifier/summary_test.go @@ -7,16 +7,14 @@ import ( "github.com/google/uuid" "github.com/quay/claircore" "github.com/quay/claircore/libvuln/driver" - "github.com/quay/claircore/test/log" + "github.com/quay/zlog" "github.com/quay/clair/v4/indexer" "github.com/quay/clair/v4/matcher" ) func TestNotificationSummary(t *testing.T) { - ctx := context.Background() - ctx, done := log.TestLogger(ctx, t) - defer done() + ctx := zlog.Test(context.Background(), t) // This is a bunch of supporting data structures. updater := uuid.New().String() @@ -32,7 +30,7 @@ func TestNotificationSummary(t *testing.T) { {ID: "🖳", Name: "uncool vulnerability"}, {ID: "☃", Name: "cool vulnerability", NormalizedSeverity: claircore.Critical}, } - am := claircore.AffectedManifests{ + am := &claircore.AffectedManifests{ Vulnerabilities: map[string]*claircore.Vulnerability{ "☃": &vs[0], "🖳": &vs[1], @@ -55,13 +53,13 @@ func TestNotificationSummary(t *testing.T) { }, }, indexer: &indexer.Mock{ - AffectedManifests_: func(_ context.Context, vs []claircore.Vulnerability) (claircore.AffectedManifests, error) { + AffectedManifests_: func(_ context.Context, vs []claircore.Vulnerability) (*claircore.AffectedManifests, error) { if len(vs) > 0 { // Needs at least one affected manifest // for the code path to invoke store.PutNotifications() return am, nil } - return claircore.NewAffectedManifests(), nil + return &claircore.AffectedManifests{}, nil }, }, } diff --git a/notifier/webhook/deliverer_test.go b/notifier/webhook/deliverer_test.go index db6e54cfb3..6167105640 100644 --- a/notifier/webhook/deliverer_test.go +++ b/notifier/webhook/deliverer_test.go @@ -16,12 +16,12 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/uuid" - "github.com/quay/claircore/test/log" "gopkg.in/square/go-jose.v2" "gopkg.in/square/go-jose.v2/jwt" "github.com/quay/clair/v4/notifier" "github.com/quay/clair/v4/notifier/keymanager" + "github.com/quay/zlog" ) var ( @@ -51,8 +51,7 @@ func testSign(t *testing.T) { t.Fatalf("failed to create request: %v", err) } - ctx, done := log.TestLogger(context.Background(), t) - defer done() + ctx := zlog.Test(context.Background(), t) err = d.sign(ctx, req, kp) if err != nil { t.Fatalf("failed to sign request: %v", err) @@ -127,8 +126,7 @@ func testDeliverer(t *testing.T) { return }, )) - ctx, done := log.TestLogger(context.Background(), t) - defer done() + ctx := zlog.Test(context.Background(), t) conf := Config{ Callback: callback, Target: server.URL,