diff --git a/pkg/extensions/monitoring/monitoring_test.go b/pkg/extensions/monitoring/monitoring_test.go index 4eb34edc..76c9e4cc 100644 --- a/pkg/extensions/monitoring/monitoring_test.go +++ b/pkg/extensions/monitoring/monitoring_test.go @@ -453,17 +453,17 @@ func TestPopulateStorageMetrics(t *testing.T) { So(ctlr, ShouldNotBeNil) ctlr.Log = log.NewLoggerWithWriter("debug", writers) - cm := test.NewControllerManager(ctlr) - cm.StartAndWait(port) - defer cm.StopServer() - - // write a couple of images + // Write images before starting controller to avoid race condition with garbage collection srcStorageCtlr := ociutils.GetDefaultStoreController(rootDir, ctlr.Log) err = WriteImageToFileSystem(CreateDefaultImage(), "alpine", "0.0.1", srcStorageCtlr) So(err, ShouldBeNil) err = WriteImageToFileSystem(CreateDefaultImage(), "busybox", "0.0.1", srcStorageCtlr) So(err, ShouldBeNil) + cm := test.NewControllerManager(ctlr) + cm.StartAndWait(port) + defer cm.StopServer() + metrics := monitoring.NewMetricsServer(true, ctlr.Log) sch := scheduler.NewScheduler(conf, metrics, ctlr.Log) sch.RunScheduler() diff --git a/pkg/extensions/sync/sync_test.go b/pkg/extensions/sync/sync_test.go index 0bbe232e..b90d0e4e 100644 --- a/pkg/extensions/sync/sync_test.go +++ b/pkg/extensions/sync/sync_test.go @@ -1461,18 +1461,22 @@ func TestDockerImagesAreSkipped(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - Convey("trigger config blob upstream error", func() { - // remove synced image - err := os.RemoveAll(path.Join(destDir, testImage)) - So(err, ShouldBeNil) + // trigger config blob upstream error + // remove synced image + err = os.RemoveAll(path.Join(destDir, testImage)) + So(err, ShouldBeNil) - err = os.Chmod(path.Join(srcDir, testImage, "blobs/sha256", configBlobDigest.Encoded()), 0o000) - So(err, ShouldBeNil) + configBlobPath := path.Join(srcDir, testImage, "blobs/sha256", configBlobDigest.Encoded()) + err = os.Chmod(configBlobPath, 0o000) + So(err, ShouldBeNil) - resp, err = resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) - So(err, ShouldBeNil) - So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - }) + defer func() { + _ = os.Chmod(configBlobPath, storageConstants.DefaultFilePerms) + }() + + resp, err = resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag) + So(err, ShouldBeNil) + So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) Convey("skipping already synced multiarch docker image", func() { @@ -1627,18 +1631,22 @@ func TestDockerImagesAreSkipped(t *testing.T) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - Convey("trigger config blob upstream error", func() { - // remove synced image - err := os.RemoveAll(path.Join(destDir, indexRepoName)) - So(err, ShouldBeNil) + // trigger config blob upstream error + // remove synced image + err = os.RemoveAll(path.Join(destDir, indexRepoName)) + So(err, ShouldBeNil) - err = os.Chmod(path.Join(srcDir, indexRepoName, "blobs/sha256", configBlobDigest.Encoded()), 0o000) - So(err, ShouldBeNil) + configBlobPath := path.Join(srcDir, indexRepoName, "blobs/sha256", configBlobDigest.Encoded()) + err = os.Chmod(configBlobPath, 0o000) + So(err, ShouldBeNil) - resp, err = resty.R().Get(destBaseURL + "/v2/" + indexRepoName + "/manifests/" + "latest") - So(err, ShouldBeNil) - So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - }) + defer func() { + _ = os.Chmod(configBlobPath, storageConstants.DefaultFilePerms) + }() + + resp, err = resty.R().Get(destBaseURL + "/v2/" + indexRepoName + "/manifests/" + "latest") + So(err, ShouldBeNil) + So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) }) }) } @@ -4855,7 +4863,18 @@ func TestSignatures(t *testing.T) { So(err, ShouldBeNil) So(len(index.Manifests), ShouldEqual, 2) - So(index.Manifests[1].Digest, ShouldEqual, ociRefDigest) + + foundOCIRef := false + + for _, manifest := range index.Manifests { + if manifest.Digest == ociRefDigest { + foundOCIRef = true + + break + } + } + + So(foundOCIRef, ShouldBeTrue) // test negative cases (trigger errors) // test notary signatures errors diff --git a/pkg/meta/redis/redis.go b/pkg/meta/redis/redis.go index d44eb0f3..91435a3b 100644 --- a/pkg/meta/redis/redis.go +++ b/pkg/meta/redis/redis.go @@ -1296,7 +1296,7 @@ func (rc *RedisDB) GetMultipleRepoMeta(ctx context.Context, filter func(repoMeta } } - return foundRepos, err + return foundRepos, nil } // AddManifestSignature adds signature metadata to a given manifest in the database.