diff --git a/pkg/api/controller_test.go b/pkg/api/controller_test.go index b1bb6185..6ed9a1c4 100644 --- a/pkg/api/controller_test.go +++ b/pkg/api/controller_test.go @@ -922,27 +922,13 @@ func TestBlobReferenced(t *testing.T) { repoName := "repo" - cfg, layers, manifest, err := test.GetImageComponents(2) + img := test.CreateRandomImage() + + err = test.UploadImage(img, baseURL, repoName, "1.0") So(err, ShouldBeNil) - err = test.UploadImage( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "1.0", - }, baseURL, repoName) - So(err, ShouldBeNil) - - manifestContent, err := json.Marshal(manifest) - So(err, ShouldBeNil) - manifestDigest := godigest.FromBytes(manifestContent) - So(manifestDigest, ShouldNotBeNil) - - configContent, err := json.Marshal(cfg) - So(err, ShouldBeNil) - configDigest := godigest.FromBytes(configContent) - So(configDigest, ShouldNotBeNil) + manifestDigest := img.ManifestDescriptor.Digest + configDigest := img.ConfigDescriptor.Digest // delete manifest blob resp, err = resty.R().Delete(baseURL + "/v2/" + repoName + "/blobs/" + manifestDigest.String()) @@ -2123,10 +2109,9 @@ func TestGroupsPermissionsForLDAP(t *testing.T) { img := test.CreateDefaultImage() - err = test.UploadImageWithBasicAuthRef( + err = test.UploadImageWithBasicAuth( img, baseURL, repo, img.DigestStr(), username, passphrase) - So(err, ShouldBeNil) }) } @@ -4795,23 +4780,13 @@ func TestImageSignatures(t *testing.T) { defer cm.StopServer() repoName := "signed-repo" - cfg, layers, manifest, err := test.GetImageComponents(2) - So(err, ShouldBeNil) + img := test.CreateRandomImage() + content := img.ManifestDescriptor.Data + digest := img.ManifestDescriptor.Digest - err = test.UploadImage( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "1.0", - }, baseURL, repoName) + err := test.UploadImage(img, baseURL, repoName, "1.0") So(err, ShouldBeNil) - content, err := json.Marshal(manifest) - So(err, ShouldBeNil) - digest := godigest.FromBytes(content) - So(digest, ShouldNotBeNil) - Convey("Validate cosign signatures", func() { cwd, err := os.Getwd() So(err, ShouldBeNil) @@ -5043,28 +5018,15 @@ func TestManifestValidation(t *testing.T) { blobDigest := godigest.FromBytes(blobContent) So(blobDigest, ShouldNotBeNil) - cfg, layers, manifest, err := test.GetImageComponents(2) - So(err, ShouldBeNil) + img := test.CreateRandomImage() + content := img.ManifestDescriptor.Data + digest := img.ManifestDescriptor.Digest + configDigest := img.ConfigDescriptor.Digest + configBlob := img.ConfigDescriptor.Data - err = test.UploadImage( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "1.0", - }, baseURL, repoName) + err := test.UploadImage(img, baseURL, repoName, "1.0") So(err, ShouldBeNil) - content, err := json.Marshal(manifest) - So(err, ShouldBeNil) - digest := godigest.FromBytes(content) - So(digest, ShouldNotBeNil) - - configBlob, err := json.Marshal(cfg) - So(err, ShouldBeNil) - - configDigest := godigest.FromBytes(configBlob) - Convey("empty layers should pass validation", func() { // create a manifest manifest := ispec.Manifest{ @@ -5276,16 +5238,15 @@ func TestArtifactReferences(t *testing.T) { digest := godigest.FromBytes(content) So(digest, ShouldNotBeNil) - cfg, layers, manifest, err := test.GetImageComponents(2) + cfg, layers, manifest, err := test.GetImageComponents(2) //nolint:staticcheck So(err, ShouldBeNil) err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "1.0", - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, "1.0") So(err, ShouldBeNil) content, err = json.Marshal(manifest) @@ -6116,7 +6077,7 @@ func TestStorageCommit(t *testing.T) { Convey("Manifests", func() { _, _ = Print("\nManifests") - cfg, layers, manifest, err := test.GetImageComponents(2) + cfg, layers, manifest, err := test.GetImageComponents(2) //nolint:staticcheck So(err, ShouldBeNil) content := []byte("this is a blob5") @@ -6131,11 +6092,10 @@ func TestStorageCommit(t *testing.T) { repoName := "repo7" err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:1.0", - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, "test:1.0") So(err, ShouldBeNil) _, err = os.Stat(path.Join(dir, "repo7")) @@ -6166,23 +6126,21 @@ func TestStorageCommit(t *testing.T) { err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:1.0.1", - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, "test:1.0.1") So(err, ShouldBeNil) - cfg, layers, manifest, err = test.GetImageComponents(1) + cfg, layers, manifest, err = test.GetImageComponents(1) //nolint:staticcheck So(err, ShouldBeNil) err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:2.0", - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, "test:2.0") So(err, ShouldBeNil) resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). @@ -6272,7 +6230,7 @@ func TestManifestImageIndex(t *testing.T) { rthdlr := api.NewRouteHandler(ctlr) - cfg, layers, manifest, err := test.GetImageComponents(2) + cfg, layers, manifest, err := test.GetImageComponents(2) //nolint:staticcheck So(err, ShouldBeNil) content := []byte("this is a blob1") @@ -6288,11 +6246,10 @@ func TestManifestImageIndex(t *testing.T) { repoName := "index" err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:1.0", - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, "test:1.0") So(err, ShouldBeNil) _, err = os.Stat(path.Join(dir, "index")) @@ -6317,21 +6274,15 @@ func TestManifestImageIndex(t *testing.T) { resp, err = resty.R().Post(baseURL + "/v2/index/blobs/uploads/") So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusAccepted) - cfg, layers, manifest, err = test.GetImageComponents(1) + + img := test.CreateRandomImage() + + err = test.UploadImage(img, baseURL, repoName, img.DigestStr()) So(err, ShouldBeNil) - err = test.UploadImage( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - }, baseURL, repoName) - So(err, ShouldBeNil) + content = img.ManifestDescriptor.Data + digest = img.ManifestDescriptor.Digest - content, err = json.Marshal(manifest) - So(err, ShouldBeNil) - digest = godigest.FromBytes(content) - So(digest, ShouldNotBeNil) m2dgst := digest m2size := len(content) resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). @@ -6343,20 +6294,14 @@ func TestManifestImageIndex(t *testing.T) { So(digestHdr, ShouldEqual, digest.String()) Convey("Image index", func() { - cfg, layers, manifest, err = test.GetImageComponents(3) - So(err, ShouldBeNil) - err = test.UploadImage( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - }, baseURL, repoName) + img := test.CreateRandomImage() + + err = test.UploadImage(img, baseURL, repoName, img.DigestStr()) So(err, ShouldBeNil) - content, err = json.Marshal(manifest) - So(err, ShouldBeNil) - digest = godigest.FromBytes(content) - So(digest, ShouldNotBeNil) + content := img.ManifestDescriptor.Data + digest = img.ManifestDescriptor.Digest + resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(content).Put(baseURL + fmt.Sprintf("/v2/index/manifests/%s", digest.String())) So(err, ShouldBeNil) @@ -6399,19 +6344,14 @@ func TestManifestImageIndex(t *testing.T) { So(resp.Body(), ShouldNotBeEmpty) So(resp.Header().Get("Content-Type"), ShouldNotBeEmpty) - cfg, layers, manifest, err = test.GetImageComponents(4) + img = test.CreateRandomImage() + + err = test.UploadImage(img, baseURL, repoName, img.DigestStr()) So(err, ShouldBeNil) - err = test.UploadImage( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - }, baseURL, repoName) - So(err, ShouldBeNil) - content, err = json.Marshal(manifest) - So(err, ShouldBeNil) - digest = godigest.FromBytes(content) - So(digest, ShouldNotBeNil) + + content = img.ManifestDescriptor.Data + digest = img.ManifestDescriptor.Digest + m4dgst := digest m4size := len(content) resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). @@ -6572,19 +6512,14 @@ func TestManifestImageIndex(t *testing.T) { }) Convey("Update an index tag with different manifest", func() { - cfg, layers, manifest, err = test.GetImageComponents(5) + img := test.CreateRandomImage() + + err = test.UploadImage(img, baseURL, repoName, img.DigestStr()) So(err, ShouldBeNil) - err = test.UploadImage( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - }, baseURL, repoName) - So(err, ShouldBeNil) - content, err = json.Marshal(manifest) - So(err, ShouldBeNil) - digest = godigest.FromBytes(content) - So(digest, ShouldNotBeNil) + + content = img.ManifestDescriptor.Data + digest = img.ManifestDescriptor.Digest + resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(content).Put(baseURL + fmt.Sprintf("/v2/index/manifests/%s", digest)) So(err, ShouldBeNil) @@ -6711,16 +6646,15 @@ func TestManifestCollision(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - cfg, layers, manifest, err := test.GetImageComponents(2) + cfg, layers, manifest, err := test.GetImageComponents(2) //nolint:staticcheck So(err, ShouldBeNil) err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:1.0", - }, baseURL, "index") + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, "index", "test:1.0") So(err, ShouldBeNil) _, err = os.Stat(path.Join(dir, "index")) @@ -6743,11 +6677,10 @@ func TestManifestCollision(t *testing.T) { err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:2.0", - }, baseURL, "index") + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, "index", "test:2.0") So(err, ShouldBeNil) // Deletion should fail if using digest @@ -7378,16 +7311,9 @@ func TestGCSignaturesAndUntaggedManifests(t *testing.T) { So(err, ShouldBeNil) // trigger gc - cfg, layers, manifest, err := test.GetImageComponents(3) - So(err, ShouldBeNil) + img := test.CreateRandomImage() - err = test.UploadImage( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: tag, - }, baseURL, repoName) + err = test.UploadImage(img, baseURL, repoName, img.DigestStr()) So(err, ShouldNotBeNil) err = os.Chmod(path.Join(dir, repoName, "blobs", "sha256", refs.Manifests[0].Digest.Encoded()), 0o755) @@ -7398,13 +7324,7 @@ func TestGCSignaturesAndUntaggedManifests(t *testing.T) { err = os.WriteFile(path.Join(dir, repoName, "blobs", "sha256", refs.Manifests[0].Digest.Encoded()), []byte("corrupt"), 0o600) //nolint:lll So(err, ShouldBeNil) - err = test.UploadImage( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: tag, - }, baseURL, repoName) + err = test.UploadImage(img, baseURL, repoName, tag) So(err, ShouldNotBeNil) err = os.WriteFile(path.Join(dir, repoName, "blobs", "sha256", refs.Manifests[0].Digest.Encoded()), content, 0o600) @@ -7412,7 +7332,7 @@ func TestGCSignaturesAndUntaggedManifests(t *testing.T) { }) // push an image without tag - cfg, layers, manifest, err := test.GetImageComponents(2) + cfg, layers, manifest, err := test.GetImageComponents(2) //nolint:staticcheck So(err, ShouldBeNil) manifestBuf, err := json.Marshal(manifest) @@ -7421,24 +7341,22 @@ func TestGCSignaturesAndUntaggedManifests(t *testing.T) { err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: untaggedManifestDigest.String(), - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, untaggedManifestDigest.String()) So(err, ShouldBeNil) // overwrite image so that signatures will get invalidated and gc'ed - cfg, layers, manifest, err = test.GetImageComponents(3) + cfg, layers, manifest, err = test.GetImageComponents(3) //nolint:staticcheck So(err, ShouldBeNil) err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: tag, - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, tag) So(err, ShouldBeNil) manifestBuf, err = json.Marshal(manifest) @@ -7500,7 +7418,7 @@ func TestGCSignaturesAndUntaggedManifests(t *testing.T) { // upload multiple manifests for i := 0; i < 4; i++ { - config, layers, manifest, err := test.GetImageComponents(1000 + i) + config, layers, manifest, err := test.GetImageComponents(1000 + i) //nolint:staticcheck So(err, ShouldBeNil) manifestContent, err := json.Marshal(manifest) @@ -7510,13 +7428,10 @@ func TestGCSignaturesAndUntaggedManifests(t *testing.T) { err = test.UploadImage( test.Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: manifestDigest.String(), - }, - baseURL, - repoName) + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, manifestDigest.String()) So(err, ShouldBeNil) index.Manifests = append(index.Manifests, ispec.Descriptor{ @@ -7690,30 +7605,28 @@ func TestSearchRoutes(t *testing.T) { repoName := "testrepo" //nolint:goconst inaccessibleRepo := "inaccessible" - cfg, layers, manifest, err := test.GetImageComponents(10000) + cfg, layers, manifest, err := test.GetImageComponents(10000) //nolint:staticcheck So(err, ShouldBeNil) err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "latest", - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, "latest") So(err, ShouldBeNil) // data for the inaccessible repo - cfg, layers, manifest, err = test.GetImageComponents(10000) + cfg, layers, manifest, err = test.GetImageComponents(10000) //nolint:staticcheck So(err, ShouldBeNil) err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "latest", - }, baseURL, inaccessibleRepo) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, inaccessibleRepo, "latest") So(err, ShouldBeNil) @@ -7778,33 +7691,29 @@ func TestSearchRoutes(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - cfg, layers, manifest, err := test.GetImageComponents(10000) + cfg, layers, manifest, err := test.GetImageComponents(10000) //nolint:staticcheck So(err, ShouldBeNil) err = test.UploadImageWithBasicAuth( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "latest", - }, baseURL, repoName, + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, "latest", user1, password1) - So(err, ShouldBeNil) // data for the inaccessible repo - cfg, layers, manifest, err = test.GetImageComponents(10000) + cfg, layers, manifest, err = test.GetImageComponents(10000) //nolint:staticcheck So(err, ShouldBeNil) err = test.UploadImageWithBasicAuth( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "latest", - }, baseURL, inaccessibleRepo, + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, inaccessibleRepo, "latest", user1, password1) - So(err, ShouldBeNil) query := ` @@ -7927,17 +7836,9 @@ func TestSearchRoutes(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - cfg, layers, manifest, err := test.GetImageComponents(10000) - So(err, ShouldBeNil) - - err = test.UploadImageWithBasicAuth( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - }, baseURL, repoName, - user1, password1) + img := test.CreateRandomImage() + err = test.UploadImageWithBasicAuth(img, baseURL, repoName, img.DigestStr(), user1, password1) So(err, ShouldBeNil) query := ` @@ -8022,17 +7923,9 @@ func TestSearchRoutes(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - cfg, layers, manifest, err := test.GetImageComponents(10000) - So(err, ShouldBeNil) - - err = test.UploadImageWithBasicAuth( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - }, baseURL, repoName, - user1, password1) + img := test.CreateRandomImage() + err = test.UploadImageWithBasicAuth(img, baseURL, repoName, img.DigestStr(), user1, password1) So(err, ShouldNotBeNil) }) @@ -8098,17 +7991,9 @@ func TestSearchRoutes(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - cfg, layers, manifest, err := test.GetImageComponents(10000) - So(err, ShouldBeNil) - - err = test.UploadImageWithBasicAuth( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - }, baseURL, repoName, - user1, password1) + img := test.CreateRandomImage() + err = test.UploadImageWithBasicAuth(img, baseURL, repoName, img.DigestStr(), user1, password1) So(err, ShouldBeNil) }) @@ -8174,17 +8059,9 @@ func TestSearchRoutes(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - cfg, layers, manifest, err := test.GetImageComponents(10000) - So(err, ShouldBeNil) - - err = test.UploadImageWithBasicAuth( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - }, baseURL, repoName, - user1, password1) + img := test.CreateRandomImage() + err = test.UploadImageWithBasicAuth(img, baseURL, repoName, img.DigestStr(), user1, password1) So(err, ShouldBeNil) }) @@ -8236,17 +8113,9 @@ func TestSearchRoutes(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - cfg, layers, manifest, err := test.GetImageComponents(10000) - So(err, ShouldBeNil) - - err = test.UploadImageWithBasicAuth( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - }, baseURL, repoName, - user1, password1) + img := test.CreateRandomImage() + err = test.UploadImageWithBasicAuth(img, baseURL, repoName, img.DigestStr(), user1, password1) So(err, ShouldBeNil) }) @@ -8308,17 +8177,9 @@ func TestSearchRoutes(t *testing.T) { cm.StartAndWait(port) defer cm.StopServer() - cfg, layers, manifest, err := test.GetImageComponents(10000) - So(err, ShouldBeNil) - - err = test.UploadImageWithBasicAuth( - test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - }, baseURL, repoName, - "", "") + img := test.CreateRandomImage() + err = test.UploadImageWithBasicAuth(img, baseURL, repoName, img.DigestStr(), "", "") So(err, ShouldBeNil) }) }) diff --git a/pkg/cli/cve_cmd_test.go b/pkg/cli/cve_cmd_test.go index 420f6b89..44e4c4b7 100644 --- a/pkg/cli/cve_cmd_test.go +++ b/pkg/cli/cve_cmd_test.go @@ -473,16 +473,15 @@ func TestNegativeServerResponse(t *testing.T) { } num := 10 - config, layers, manifest, err := test.GetRandomImageComponents(num) + config, layers, manifest, err := test.GetRandomImageComponents(num) //nolint:staticcheck So(err, ShouldBeNil) err = test.WriteImageToFileSystem( test.Image{ - Manifest: manifest, - Layers: layers, - Config: config, - Reference: "0.0.1", - }, "zot-cve-test", storeController, + Manifest: manifest, + Layers: layers, + Config: config, + }, "zot-cve-test", "0.0.1", storeController, ) So(err, ShouldBeNil) @@ -614,7 +613,7 @@ func TestServerCVEResponse(t *testing.T) { test.WaitTillServerReady(url) - config, layers, manifest, err := test.GetImageComponents(100) + config, layers, manifest, err := test.GetImageComponents(100) //nolint:staticcheck if err != nil { panic(err) } diff --git a/pkg/cli/image_cmd_test.go b/pkg/cli/image_cmd_test.go index 70fa6848..82c4c9d5 100644 --- a/pkg/cli/image_cmd_test.go +++ b/pkg/cli/image_cmd_test.go @@ -281,17 +281,16 @@ func TestSignature(t *testing.T) { cm.StartAndWait(conf.HTTP.Port) defer cm.StopServer() - cfg, layers, manifest, err := test.GetImageComponents(1) + cfg, layers, manifest, err := test.GetImageComponents(1) //nolint:staticcheck So(err, ShouldBeNil) repoName := "repo7" err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:1.0", - }, url, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, url, repoName, "test:1.0") So(err, ShouldBeNil) content, err := json.Marshal(manifest) @@ -375,17 +374,16 @@ func TestSignature(t *testing.T) { cm.StartAndWait(conf.HTTP.Port) defer cm.StopServer() - cfg, layers, manifest, err := test.GetImageComponents(1) + cfg, layers, manifest, err := test.GetImageComponents(1) //nolint:staticcheck So(err, ShouldBeNil) repoName := "repo7" err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "0.0.1", - }, url, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, url, repoName, "0.0.1") So(err, ShouldBeNil) content, err := json.Marshal(manifest) @@ -1578,9 +1576,9 @@ func uploadTestMultiarch(baseURL string) { // ------- Upload The multiarch image - multiarch := test.GetMultiarchImageForImages([]test.Image{image1, image2}) + multiarch := test.GetMultiarchImageForImages([]test.Image{image1, image2}) //nolint:staticcheck - err := test.UploadMultiarchImageWithRef(multiarch, baseURL, "repo", "multi-arch") + err := test.UploadMultiarchImage(multiarch, baseURL, "repo", "multi-arch") So(err, ShouldBeNil) } diff --git a/pkg/cli/search_cmd_referrers_test.go b/pkg/cli/search_cmd_referrers_test.go index aa3cdcc6..9bff88c0 100644 --- a/pkg/cli/search_cmd_referrers_test.go +++ b/pkg/cli/search_cmd_referrers_test.go @@ -206,7 +206,7 @@ func TestReferrerCLI(t *testing.T) { repo := repoName image := test.CreateRandomImage() - err := test.UploadImageWithRef(image, baseURL, repo, "tag") + err := test.UploadImage(image, baseURL, repo, "tag") So(err, ShouldBeNil) ref1 := test.CreateImageWith(). @@ -225,13 +225,13 @@ func TestReferrerCLI(t *testing.T) { ArtifactType(customArtTypeV2). Subject(image.DescriptorRef()).Build() - err = test.UploadImage(ref1, baseURL, repo) + err = test.UploadImage(ref1, baseURL, repo, ref1.DigestStr()) So(err, ShouldBeNil) - err = test.UploadImage(ref2, baseURL, repo) + err = test.UploadImage(ref2, baseURL, repo, ref2.DigestStr()) So(err, ShouldBeNil) - err = test.UploadImage(ref3, baseURL, repo) + err = test.UploadImage(ref3, baseURL, repo, ref3.DigestStr()) So(err, ShouldBeNil) args := []string{"reftest", "--subject", repo + "@" + image.DigestStr()} @@ -303,7 +303,7 @@ func TestReferrerCLI(t *testing.T) { repo := repoName image := test.CreateRandomImage() - err := test.UploadImageWithRef(image, baseURL, repo, "tag") + err := test.UploadImage(image, baseURL, repo, "tag") So(err, ShouldBeNil) ref1 := test.CreateImageWith(). @@ -322,13 +322,13 @@ func TestReferrerCLI(t *testing.T) { ArtifactType(customArtTypeV2). Subject(image.DescriptorRef()).Build() - err = test.UploadImage(ref1, baseURL, repo) + err = test.UploadImage(ref1, baseURL, repo, ref1.DigestStr()) So(err, ShouldBeNil) - err = test.UploadImage(ref2, baseURL, repo) + err = test.UploadImage(ref2, baseURL, repo, ref2.DigestStr()) So(err, ShouldBeNil) - err = test.UploadImage(ref3, baseURL, repo) + err = test.UploadImage(ref3, baseURL, repo, ref3.DigestStr()) So(err, ShouldBeNil) // get referrers by digest @@ -398,7 +398,7 @@ func TestFormatsReferrersCLI(t *testing.T) { repo := repoName image := test.CreateRandomImage() - err := test.UploadImageWithRef(image, baseURL, repo, "tag") + err := test.UploadImage(image, baseURL, repo, "tag") So(err, ShouldBeNil) // add referrers @@ -418,13 +418,13 @@ func TestFormatsReferrersCLI(t *testing.T) { ArtifactType(customArtTypeV2). Subject(image.DescriptorRef()).Build() - err = test.UploadImage(ref1, baseURL, repo) + err = test.UploadImage(ref1, baseURL, repo, ref1.DigestStr()) So(err, ShouldBeNil) - err = test.UploadImage(ref2, baseURL, repo) + err = test.UploadImage(ref2, baseURL, repo, ref2.DigestStr()) So(err, ShouldBeNil) - err = test.UploadImage(ref3, baseURL, repo) + err = test.UploadImage(ref3, baseURL, repo, ref3.DigestStr()) So(err, ShouldBeNil) Convey("JSON format", func() { diff --git a/pkg/cli/search_cmd_test.go b/pkg/cli/search_cmd_test.go index 57cb9643..1c276b33 100644 --- a/pkg/cli/search_cmd_test.go +++ b/pkg/cli/search_cmd_test.go @@ -120,31 +120,19 @@ func TestSearchCLI(t *testing.T) { Build() formatterDigest2 := image2.Digest().Encoded()[:8] - // repo1 - image1.Reference = r1tag1 - err := test.UploadImage(image1, baseURL, repo1) + err := test.UploadImage(image1, baseURL, repo1, r1tag1) + So(err, ShouldBeNil) + err = test.UploadImage(image2, baseURL, repo1, r1tag2) So(err, ShouldBeNil) - image2.Reference = r1tag2 - err = test.UploadImage(image2, baseURL, repo1) + err = test.UploadImage(image1, baseURL, repo2, r2tag1) + So(err, ShouldBeNil) + err = test.UploadImage(image2, baseURL, repo2, r2tag2) So(err, ShouldBeNil) - // repo2 - image1.Reference = r2tag1 - err = test.UploadImage(image1, baseURL, repo2) + err = test.UploadImage(image1, baseURL, repo3, r3tag1) So(err, ShouldBeNil) - - image2.Reference = r2tag2 - err = test.UploadImage(image2, baseURL, repo2) - So(err, ShouldBeNil) - - // repo3 - image1.Reference = r3tag1 - err = test.UploadImage(image1, baseURL, repo3) - So(err, ShouldBeNil) - - image2.Reference = r3tag2 - err = test.UploadImage(image2, baseURL, repo3) + err = test.UploadImage(image2, baseURL, repo3, r3tag2) So(err, ShouldBeNil) // search by repos @@ -232,34 +220,21 @@ func TestFormatsSearchCLI(t *testing.T) { ) image1 := test.CreateImageWith().RandomLayers(1, 10).DefaultConfig().Build() - image2 := test.CreateImageWith().RandomLayers(1, 10).DefaultConfig().Build() - // repo1 - image1.Reference = r1tag1 - err := test.UploadImage(image1, baseURL, repo1) + err := test.UploadImage(image1, baseURL, repo1, r1tag1) + So(err, ShouldBeNil) + err = test.UploadImage(image2, baseURL, repo1, r1tag2) So(err, ShouldBeNil) - image2.Reference = r1tag2 - err = test.UploadImage(image2, baseURL, repo1) + err = test.UploadImage(image1, baseURL, repo2, r2tag1) + So(err, ShouldBeNil) + err = test.UploadImage(image2, baseURL, repo2, r2tag2) So(err, ShouldBeNil) - // repo2 - image1.Reference = r2tag1 - err = test.UploadImage(image1, baseURL, repo2) + err = test.UploadImage(image1, baseURL, repo3, r3tag1) So(err, ShouldBeNil) - - image2.Reference = r2tag2 - err = test.UploadImage(image2, baseURL, repo2) - So(err, ShouldBeNil) - - // repo3 - image1.Reference = r3tag1 - err = test.UploadImage(image1, baseURL, repo3) - So(err, ShouldBeNil) - - image2.Reference = r3tag2 - err = test.UploadImage(image2, baseURL, repo3) + err = test.UploadImage(image2, baseURL, repo3, r3tag2) So(err, ShouldBeNil) cmd := NewSearchCommand(new(searchService)) diff --git a/pkg/compliance/v1_0_0/check.go b/pkg/compliance/v1_0_0/check.go index 02f30355..bac6079c 100644 --- a/pkg/compliance/v1_0_0/check.go +++ b/pkg/compliance/v1_0_0/check.go @@ -484,17 +484,16 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - cfg, layers, manifest, err := test.GetImageComponents(1) + cfg, layers, manifest, err := test.GetImageComponents(1) //nolint:staticcheck So(err, ShouldBeNil) repoName := "repo7" err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:1.0", - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, "test:1.0") So(err, ShouldBeNil) content, err = json.Marshal(manifest) @@ -504,11 +503,10 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:1.0.1", - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, "test:1.0.1") So(err, ShouldBeNil) content = []byte("this is a blob5") @@ -522,11 +520,10 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:2.0", - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, "test:2.0") So(err, ShouldBeNil) // check/get by tag @@ -595,17 +592,16 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { _, _ = Print("\nPagination") for index := 0; index <= 4; index++ { - cfg, layers, manifest, err := test.GetImageComponents(1) + cfg, layers, manifest, err := test.GetImageComponents(1) //nolint:staticcheck So(err, ShouldBeNil) repoName := "page0" err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: fmt.Sprintf("test:%d.0", index), - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, fmt.Sprintf("test:%d.0", index)) So(err, ShouldBeNil) content, err := json.Marshal(manifest) @@ -736,17 +732,16 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(err, ShouldBeNil) So(resp.StatusCode(), ShouldEqual, http.StatusNotFound) - cfg, layers, manifest, err := test.GetImageComponents(1) + cfg, layers, manifest, err := test.GetImageComponents(1) //nolint:staticcheck So(err, ShouldBeNil) // subpath firsttest err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:1.0", - }, baseURL, "firsttest/first") + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, "firsttest/first", "test:1.0") So(err, ShouldBeNil) content, err = json.Marshal(manifest) @@ -757,11 +752,10 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { // subpath secondtest err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:1.0", - }, baseURL, "secondtest/second") + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, "secondtest/second", "test:1.0") So(err, ShouldBeNil) content, err = json.Marshal(manifest) @@ -776,11 +770,10 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { // subpath firsttest err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:2.0", - }, baseURL, "firsttest/first") + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, "firsttest/first", "test:2.0") So(err, ShouldBeNil) content, err = json.Marshal(manifest) @@ -791,11 +784,10 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { // subpath secondtest err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "test:2.0", - }, baseURL, "secondtest/second") + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, "secondtest/second", "test:2.0") So(err, ShouldBeNil) // check/get by tag diff --git a/pkg/extensions/extension_ui_test.go b/pkg/extensions/extension_ui_test.go index fd77030c..2cc5886e 100644 --- a/pkg/extensions/extension_ui_test.go +++ b/pkg/extensions/extension_ui_test.go @@ -57,7 +57,7 @@ func TestUIExtension(t *testing.T) { So(found, ShouldBeTrue) So(err, ShouldBeNil) - cfg, layers, manifest, err := test.GetImageComponents(1) + cfg, layers, manifest, err := test.GetImageComponents(1) //nolint:staticcheck So(err, ShouldBeNil) repoName := "test-repo" @@ -66,11 +66,10 @@ func TestUIExtension(t *testing.T) { // Upload a test image err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: tagName, - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, tagName) So(err, ShouldBeNil) resp, err := resty.R().Get(baseURL + "/home") diff --git a/pkg/extensions/extensions_test.go b/pkg/extensions/extensions_test.go index 13059fc6..57075f94 100644 --- a/pkg/extensions/extensions_test.go +++ b/pkg/extensions/extensions_test.go @@ -659,30 +659,28 @@ func TestMgmtExtension(t *testing.T) { DefaultStore: imageStore, } - config, layers, manifest, err := test.GetRandomImageComponents(10) + config, layers, manifest, err := test.GetRandomImageComponents(10) //nolint:staticcheck So(err, ShouldBeNil) err = test.WriteImageToFileSystem( test.Image{ - Manifest: manifest, - Layers: layers, - Config: config, - Reference: "0.0.1", - }, "repo", storeController, + Manifest: manifest, + Layers: layers, + Config: config, + }, "repo", "0.0.1", storeController, ) So(err, ShouldBeNil) - sigConfig, sigLayers, sigManifest, err := test.GetRandomImageComponents(10) + sigConfig, sigLayers, sigManifest, err := test.GetRandomImageComponents(10) //nolint:staticcheck So(err, ShouldBeNil) ref, _ := test.GetCosignSignatureTagForManifest(manifest) err = test.WriteImageToFileSystem( test.Image{ - Manifest: sigManifest, - Layers: sigLayers, - Config: sigConfig, - Reference: ref, - }, "repo", storeController, + Manifest: sigManifest, + Layers: sigLayers, + Config: sigConfig, + }, "repo", ref, storeController, ) So(err, ShouldBeNil) diff --git a/pkg/extensions/search/cve/cve_test.go b/pkg/extensions/search/cve/cve_test.go index b31a07b7..e3a71997 100644 --- a/pkg/extensions/search/cve/cve_test.go +++ b/pkg/extensions/search/cve/cve_test.go @@ -1563,7 +1563,7 @@ func TestFixedTagsWithIndex(t *testing.T) { defer cm.StopServer() // push index with 2 manifests: one with vulns and one without vulnManifestCreated := time.Date(2010, 1, 1, 1, 1, 1, 1, time.UTC) - vulnManifest, err := GetVulnImageWithConfig("", ispec.Image{ + vulnManifest, err := GetVulnImageWithConfig(ispec.Image{ Created: &vulnManifestCreated, Platform: ispec.Platform{OS: "linux", Architecture: "amd64"}, }) @@ -1581,18 +1581,18 @@ func TestFixedTagsWithIndex(t *testing.T) { multiArch := GetMultiarchImageForImages([]Image{fixedManifest, vulnManifest}) multiArchDigest := multiArch.Digest() - err = UploadMultiarchImageWithRef(multiArch, baseURL, "repo", "multi-arch-tag") + err = UploadMultiarchImage(multiArch, baseURL, "repo", "multi-arch-tag") So(err, ShouldBeNil) // oldest vulnerability simpleVulnCreated := time.Date(2005, 1, 1, 1, 1, 1, 1, time.UTC) - simpleVulnImg, err := GetVulnImageWithConfig("vuln-img", ispec.Image{ + simpleVulnImg, err := GetVulnImageWithConfig(ispec.Image{ Created: &simpleVulnCreated, Platform: ispec.Platform{OS: "windows", Architecture: "amd64"}, }) So(err, ShouldBeNil) - err = UploadImage(simpleVulnImg, baseURL, "repo") + err = UploadImage(simpleVulnImg, baseURL, "repo", "vuln-img") So(err, ShouldBeNil) scanner := trivy.NewScanner(ctlr.StoreController, ctlr.MetaDB, "ghcr.io/project-zot/trivy-db", "", ctlr.Log) diff --git a/pkg/extensions/search/cve/trivy/scanner_internal_test.go b/pkg/extensions/search/cve/trivy/scanner_internal_test.go index 71152011..67fd6f80 100644 --- a/pkg/extensions/search/cve/trivy/scanner_internal_test.go +++ b/pkg/extensions/search/cve/trivy/scanner_internal_test.go @@ -34,7 +34,7 @@ import ( func generateTestImage(storeController storage.StoreController, image string) { repoName, tag := common.GetImageDirAndTag(image) - config, layers, manifest, err := test.GetImageComponents(10) + config, layers, manifest, err := test.GetImageComponents(10) //nolint:staticcheck So(err, ShouldBeNil) store := storeController.GetImageStore(repoName) diff --git a/pkg/extensions/search/cve/trivy/scanner_test.go b/pkg/extensions/search/cve/trivy/scanner_test.go index 435fa452..f7b40b63 100644 --- a/pkg/extensions/search/cve/trivy/scanner_test.go +++ b/pkg/extensions/search/cve/trivy/scanner_test.go @@ -50,9 +50,9 @@ func TestScanningByDigest(t *testing.T) { simpleImage := test.CreateRandomImage() - multiArch := test.GetMultiarchImageForImages([]test.Image{simpleImage, vulnImage}) + multiArch := test.GetMultiarchImageForImages([]test.Image{simpleImage, vulnImage}) //nolint:staticcheck - err := test.UploadMultiarchImageWithRef(multiArch, baseURL, "multi-arch", "multi-arch-tag") + err := test.UploadMultiarchImage(multiArch, baseURL, "multi-arch", "multi-arch-tag") So(err, ShouldBeNil) // scan @@ -149,7 +149,7 @@ func TestVulnerableLayer(t *testing.T) { DefaultStore: imageStore, } - err = test.WriteImageToFileSystem(img, "repo", storeController) + err = test.WriteImageToFileSystem(img, "repo", img.DigestStr(), storeController) So(err, ShouldBeNil) params := boltdb.DBParameters{ diff --git a/pkg/extensions/search/digest_test.go b/pkg/extensions/search/digest_test.go index efc0537a..b8fd5a33 100644 --- a/pkg/extensions/search/digest_test.go +++ b/pkg/extensions/search/digest_test.go @@ -87,12 +87,8 @@ func TestDigestSearchHTTP(t *testing.T) { So(err, ShouldBeNil) const ver001 = "0.0.1" - image1.Reference = ver001 - err = UploadImage( - image1, - baseURL, - "zot-cve-test", - ) + + err = UploadImage(image1, baseURL, "zot-cve-test", ver001) So(err, ShouldBeNil) createdTime2 := time.Date(2010, 1, 1, 12, 0, 0, 0, time.UTC) @@ -110,10 +106,9 @@ func TestDigestSearchHTTP(t *testing.T) { ) So(err, ShouldBeNil) - image2.Reference = ver001 manifestDigest := image2.Digest() - err = UploadImage(image2, baseURL, "zot-test") + err = UploadImage(image2, baseURL, "zot-test", ver001) So(err, ShouldBeNil) configBlob, err := json.Marshal(image2.Config) diff --git a/pkg/extensions/search/search_test.go b/pkg/extensions/search/search_test.go index 788fd211..6588121a 100644 --- a/pkg/extensions/search/search_test.go +++ b/pkg/extensions/search/search_test.go @@ -210,13 +210,10 @@ func uploadNewRepoTag(tag string, repoName string, baseURL string, layers [][]by err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: tag, - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, tag, ) return err @@ -851,13 +848,10 @@ func TestGetReferrersGQL(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "1.0", - }, - baseURL, - repo) + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repo, "1.0") So(err, ShouldBeNil) @@ -908,9 +902,8 @@ func TestGetReferrersGQL(t *testing.T) { artifactManifestBlob, err := json.Marshal(artifactImg.Manifest) So(err, ShouldBeNil) artifactManifestDigest := godigest.FromBytes(artifactManifestBlob) - artifactImg.Reference = artifactManifestDigest.String() - err = UploadImage(artifactImg, baseURL, repo) + err = UploadImage(artifactImg, baseURL, repo, artifactManifestDigest.String()) So(err, ShouldBeNil) gqlQuery := ` @@ -985,7 +978,7 @@ func TestGetReferrersGQL(t *testing.T) { So(err, ShouldBeNil) repo := "artifact-ref" - err = UploadMultiarchImage(multiarch, baseURL, repo) + err = UploadMultiarchImage(multiarch, baseURL, repo, "multiarch") So(err, ShouldBeNil) indexBlob, err := json.Marshal(multiarch.Index) @@ -1037,11 +1030,8 @@ func TestGetReferrersGQL(t *testing.T) { Image{ Manifest: artifactManifest, Config: ispec.Image{}, - Layers: [][]byte{ - artifactContentBlob, - }, - Reference: artifactManifestDigest.String(), - }, baseURL, repo) + Layers: [][]byte{artifactContentBlob}, + }, baseURL, repo, artifactManifestDigest.String()) So(err, ShouldBeNil) gqlQuery := ` @@ -1110,11 +1100,11 @@ func TestGetReferrersGQL(t *testing.T) { // Upload the index referrer - targetImg, err := GetRandomImage("") + targetImg, err := GetRandomImage() So(err, ShouldBeNil) targetDigest := targetImg.Digest() - err = UploadImage(targetImg, baseURL, "repo") + err = UploadImage(targetImg, baseURL, "repo", targetDigest.String()) So(err, ShouldBeNil) indexReferrer, err := GetRandomMultiarchImage("ref") @@ -1129,7 +1119,7 @@ func TestGetReferrersGQL(t *testing.T) { indexReferrerDigest := indexReferrer.Digest() - err = UploadMultiarchImage(indexReferrer, baseURL, "repo") + err = UploadMultiarchImage(indexReferrer, baseURL, "repo", "ref") So(err, ShouldBeNil) // Call Referrers GQL @@ -1217,13 +1207,10 @@ func TestExpandedRepoInfo(t *testing.T) { err = WriteImageToFileSystem( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: fmt.Sprintf("%d.0", i), - }, - repo1, - storeController) + Manifest: manifest, + Config: config, + Layers: layers, + }, repo1, fmt.Sprintf("%d.0", i), storeController) So(err, ShouldBeNil) } @@ -1541,19 +1528,18 @@ func TestExpandedRepoInfo(t *testing.T) { ctlrManager.StartAndWait(port) defer ctlrManager.StopServer() - image, err := GetRandomImage(test) + image, err := GetRandomImage() So(err, ShouldBeNil) manifestDigest := image.Digest() - err = UploadImage(image, baseURL, "repo") + err = UploadImage(image, baseURL, "repo", test) So(err, ShouldBeNil) referrer, err := GetImageWithSubject(manifestDigest, ispec.MediaTypeImageManifest) So(err, ShouldBeNil) tag := "test-ref-tag" - referrer.Reference = tag - err = UploadImage(referrer, baseURL, "repo") + err = UploadImage(referrer, baseURL, "repo", tag) So(err, ShouldBeNil) // ------- Make the call to GQL and see that it doesn't crash @@ -1876,13 +1862,10 @@ func TestDerivedImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -1919,13 +1902,10 @@ func TestDerivedImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -1962,13 +1942,10 @@ func TestDerivedImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -2024,13 +2001,10 @@ func TestDerivedImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -2081,13 +2055,10 @@ func TestDerivedImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -2369,13 +2340,10 @@ func TestBaseImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -2417,13 +2385,10 @@ func TestBaseImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -2460,13 +2425,10 @@ func TestBaseImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -2495,13 +2457,10 @@ func TestBaseImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - "one-layer", + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, "one-layer", "latest", ) So(err, ShouldBeNil) @@ -2530,13 +2489,10 @@ func TestBaseImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - "one-layer", + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, "one-layer", "latest", ) So(err, ShouldBeNil) @@ -2567,13 +2523,10 @@ func TestBaseImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -2604,13 +2557,10 @@ func TestBaseImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -2647,13 +2597,10 @@ func TestBaseImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -2708,13 +2655,10 @@ func TestBaseImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -2751,13 +2695,10 @@ func TestBaseImageList(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -2987,11 +2928,10 @@ func TestGlobalSearchImageAuthor(t *testing.T) { manifest.Annotations["org.opencontainers.image.authors"] = "author name" err = UploadImage( Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "latest", - }, baseURL, "repowithauthor") + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, "repowithauthor", "latest") So(err, ShouldBeNil) @@ -3050,11 +2990,10 @@ func TestGlobalSearchImageAuthor(t *testing.T) { err = UploadImage( Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: "latest", - }, baseURL, "repowithauthorconfig") + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, "repowithauthorconfig", "latest") So(err, ShouldBeNil) @@ -3183,13 +3122,10 @@ func TestGlobalSearch(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest1, - Config: config1, - Layers: layers1, - Reference: "1.0.1", - }, - baseURL, - "repo1", + Manifest: manifest1, + Config: config1, + Layers: layers1, + }, baseURL, "repo1", "1.0.1", ) So(err, ShouldBeNil) @@ -3225,13 +3161,10 @@ func TestGlobalSearch(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest2, - Config: config2, - Layers: layers2, - Reference: "1.0.2", - }, - baseURL, - "repo1", + Manifest: manifest2, + Config: config2, + Layers: layers2, + }, baseURL, "repo1", "1.0.2", ) So(err, ShouldBeNil) @@ -3250,13 +3183,10 @@ func TestGlobalSearch(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest3, - Config: config3, - Layers: layers3, - Reference: "1.0.0", - }, - baseURL, - "repo2", + Manifest: manifest3, + Config: config3, + Layers: layers3, + }, baseURL, "repo2", "1.0.0", ) So(err, ShouldBeNil) @@ -3530,13 +3460,10 @@ func TestGlobalSearch(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest1, - Config: config1, - Layers: layers1, - Reference: "1.0.1", - }, - baseURL, - "repo1", + Manifest: manifest1, + Config: config1, + Layers: layers1, + }, baseURL, "repo1", "1.0.1", ) So(err, ShouldBeNil) @@ -3555,13 +3482,10 @@ func TestGlobalSearch(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest2, - Config: config2, - Layers: layers2, - Reference: "1.0.2", - }, - baseURL, - "repo1", + Manifest: manifest2, + Config: config2, + Layers: layers2, + }, baseURL, "repo1", "1.0.2", ) So(err, ShouldBeNil) @@ -3580,13 +3504,10 @@ func TestGlobalSearch(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest3, - Config: config3, - Layers: layers3, - Reference: "1.0.0", - }, - baseURL, - "repo2", + Manifest: manifest3, + Config: config3, + Layers: layers3, + }, baseURL, "repo2", "1.0.0", ) So(err, ShouldBeNil) @@ -3794,11 +3715,7 @@ func TestCleaningFilteringParamsGlobalSearch(t *testing.T) { }) So(err, ShouldBeNil) - err = UploadImage( - image, - baseURL, - "repo1", - ) + err = UploadImage(image, baseURL, "repo1", image.DigestStr()) So(err, ShouldBeNil) image, err = GetImageWithConfig(ispec.Image{ @@ -3809,11 +3726,7 @@ func TestCleaningFilteringParamsGlobalSearch(t *testing.T) { }) So(err, ShouldBeNil) - err = UploadImage( - image, - baseURL, - "repo2", - ) + err = UploadImage(image, baseURL, "repo2", image.DigestStr()) So(err, ShouldBeNil) query := ` @@ -3863,13 +3776,10 @@ func TestGlobalSearchFiltering(t *testing.T) { err = UploadImage( Image{ - Config: config, - Layers: layers, - Manifest: manifest, - Reference: "test", - }, - baseURL, - "unsigned-repo", + Config: config, + Layers: layers, + Manifest: manifest, + }, baseURL, "unsigned-repo", "test", ) So(err, ShouldBeNil) @@ -3878,13 +3788,10 @@ func TestGlobalSearchFiltering(t *testing.T) { err = UploadImage( Image{ - Config: config, - Layers: layers, - Manifest: manifest, - Reference: "test", - }, - baseURL, - "signed-repo", + Config: config, + Layers: layers, + Manifest: manifest, + }, baseURL, "signed-repo", "test", ) So(err, ShouldBeNil) @@ -4189,13 +4096,10 @@ func TestGlobalSearchPagination(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "0.0.1", - }, - baseURL, - fmt.Sprintf("repo%d", i), + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, fmt.Sprintf("repo%d", i), "0.0.1", ) So(err, ShouldBeNil) } @@ -4398,25 +4302,19 @@ func TestMetaDBWhenSigningImages(t *testing.T) { err = UploadImage( Image{ - Manifest: image1.Manifest, - Config: image1.Config, - Layers: image1.Layers, - Reference: "1.0.1", - }, - baseURL, - "repo1", + Manifest: image1.Manifest, + Config: image1.Config, + Layers: image1.Layers, + }, baseURL, "repo1", "1.0.1", ) So(err, ShouldBeNil) err = UploadImage( Image{ - Manifest: image1.Manifest, - Config: image1.Config, - Layers: image1.Layers, - Reference: "2.0.2", - }, - baseURL, - "repo1", + Manifest: image1.Manifest, + Config: image1.Config, + Layers: image1.Layers, + }, baseURL, "repo1", "2.0.2", ) So(err, ShouldBeNil) @@ -4428,11 +4326,7 @@ func TestMetaDBWhenSigningImages(t *testing.T) { multiArch, err := GetRandomMultiarchImage("index") So(err, ShouldBeNil) - err = UploadMultiarchImage( - multiArch, - baseURL, - "repo1", - ) + err = UploadMultiarchImage(multiArch, baseURL, "repo1", "index") So(err, ShouldBeNil) queryImage1 := ` @@ -4653,13 +4547,10 @@ func TestMetaDBWhenPushingImages(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest1, - Config: config1, - Layers: layers1, - Reference: "1.0.1", - }, - baseURL, - "repo1", + Manifest: manifest1, + Config: config1, + Layers: layers1, + }, baseURL, "repo1", "1.0.1", ) So(err, ShouldNotBeNil) }) @@ -4687,13 +4578,10 @@ func TestMetaDBWhenPushingImages(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest1, - Config: config1, - Layers: layers1, - Reference: "1.0.1", - }, - baseURL, - "repo1", + Manifest: manifest1, + Config: config1, + Layers: layers1, + }, baseURL, "repo1", "1.0.1", ) So(err, ShouldBeNil) }) @@ -4737,7 +4625,7 @@ func RunMetaDBIndexTests(baseURL, port string) { indexDigest := godigest.FromBytes(indexBlob) - err = UploadMultiarchImage(multiarchImage, baseURL, repo) + err = UploadMultiarchImage(multiarchImage, baseURL, repo, "tag1") So(err, ShouldBeNil) query := ` @@ -4844,7 +4732,7 @@ func RunMetaDBIndexTests(baseURL, port string) { imageAMD64, imageSomeArch, }) - err = UploadMultiarchImageWithRef(multiImage, baseURL, "test-repo", "latest") + err = UploadMultiarchImage(multiImage, baseURL, "test-repo", "latest") So(err, ShouldBeNil) // ---------------- BASE IMAGE ------------------- @@ -4865,7 +4753,7 @@ func RunMetaDBIndexTests(baseURL, port string) { multiImage = GetMultiarchImageForImages([]Image{image1, image2}) - err = UploadMultiarchImageWithRef(multiImage, baseURL, "index-one-arch-same-layers", "index-one-arch-same-layers") + err = UploadMultiarchImage(multiImage, baseURL, "index-one-arch-same-layers", "index-one-arch-same-layers") So(err, ShouldBeNil) // ---------------- SAME LAYERS ------------------- @@ -4886,7 +4774,7 @@ func RunMetaDBIndexTests(baseURL, port string) { So(err, ShouldBeNil) multiImage = GetMultiarchImageForImages([]Image{image1, image2}) - err = UploadMultiarchImageWithRef(multiImage, baseURL, "index-one-arch-less-layers", "index-one-arch-less-layers") + err = UploadMultiarchImage(multiImage, baseURL, "index-one-arch-less-layers", "index-one-arch-less-layers") So(err, ShouldBeNil) // ---------------- LESS LAYERS ------------------- @@ -4908,7 +4796,7 @@ func RunMetaDBIndexTests(baseURL, port string) { ) So(err, ShouldBeNil) multiImage = GetMultiarchImageForImages([]Image{image1, image2}) - err = UploadMultiarchImageWithRef(multiImage, baseURL, "index-one-arch-less-layers-false", + err = UploadMultiarchImage(multiImage, baseURL, "index-one-arch-less-layers-false", "index-one-arch-less-layers-false") So(err, ShouldBeNil) // ---------------- LESS LAYERS FALSE ------------------- @@ -4930,7 +4818,7 @@ func RunMetaDBIndexTests(baseURL, port string) { So(err, ShouldBeNil) multiImage = GetMultiarchImageForImages([]Image{image1, image2}) - err = UploadMultiarchImageWithRef(multiImage, baseURL, "index-one-arch-more-layers", "index-one-arch-more-layers") + err = UploadMultiarchImage(multiImage, baseURL, "index-one-arch-more-layers", "index-one-arch-more-layers") So(err, ShouldBeNil) // ---------------- MORE LAYERS ------------------- @@ -4994,7 +4882,7 @@ func RunMetaDBIndexTests(baseURL, port string) { baseLinuxSomeArchDigest := imageSomeArch.Digest() multiImage := GetMultiarchImageForImages([]Image{imageAMD64, imageSomeArch}) - err = UploadMultiarchImageWithRef(multiImage, baseURL, "test-repo", "index") + err = UploadMultiarchImage(multiImage, baseURL, "test-repo", "index") So(err, ShouldBeNil) // ---------------- BASE IMAGE FOR LINUX AMD64 ------------------- @@ -5003,9 +4891,8 @@ func RunMetaDBIndexTests(baseURL, port string) { [][]byte{imageAMD64.Layers[0]}, ) So(err, ShouldBeNil) - image.Reference = "less-layers-linux-amd64" - err = UploadImage(image, baseURL, "test-repo") + err = UploadImage(image, baseURL, "test-repo", "less-layers-linux-amd64") So(err, ShouldBeNil) // ---------------- BASE IMAGE FOR LINUX SOMEARCH ------------------- @@ -5015,9 +4902,8 @@ func RunMetaDBIndexTests(baseURL, port string) { [][]byte{imageSomeArch.Layers[0]}, ) So(err, ShouldBeNil) - image.Reference = "less-layers-linux-somearch" - err = UploadImage(image, baseURL, "test-repo") + err = UploadImage(image, baseURL, "test-repo", "less-layers-linux-somearch") So(err, ShouldBeNil) // ------- TEST @@ -5092,7 +4978,7 @@ func RunMetaDBIndexTests(baseURL, port string) { multiImage := GetMultiarchImageForImages([]Image{ imageAMD64, imageSomeArch, }) - err = UploadMultiarchImageWithRef(multiImage, baseURL, "test-repo", "latest") + err = UploadMultiarchImage(multiImage, baseURL, "test-repo", "latest") So(err, ShouldBeNil) // ---------------- BASE IMAGE ------------------- @@ -5114,7 +5000,7 @@ func RunMetaDBIndexTests(baseURL, port string) { multiImage = GetMultiarchImageForImages([]Image{ image1, image2, }) - err = UploadMultiarchImageWithRef(multiImage, baseURL, "index-one-arch-same-layers", "index-one-arch-same-layers") + err = UploadMultiarchImage(multiImage, baseURL, "index-one-arch-same-layers", "index-one-arch-same-layers") So(err, ShouldBeNil) // ---------------- SAME LAYERS ------------------- @@ -5136,7 +5022,7 @@ func RunMetaDBIndexTests(baseURL, port string) { multiImage = GetMultiarchImageForImages([]Image{ image1, image2, }) - err = UploadMultiarchImageWithRef(multiImage, baseURL, "index-one-arch-less-layers", "index-one-arch-less-layers") + err = UploadMultiarchImage(multiImage, baseURL, "index-one-arch-less-layers", "index-one-arch-less-layers") So(err, ShouldBeNil) // ---------------- LESS LAYERS ------------------- @@ -5158,7 +5044,7 @@ func RunMetaDBIndexTests(baseURL, port string) { multiImage = GetMultiarchImageForImages([]Image{ image1, image2, }) - err = UploadMultiarchImageWithRef(multiImage, baseURL, "index-one-arch-less-layers-false", + err = UploadMultiarchImage(multiImage, baseURL, "index-one-arch-less-layers-false", "index-one-arch-less-layers-false") So(err, ShouldBeNil) // ---------------- LESS LAYERS FALSE ------------------- @@ -5186,7 +5072,7 @@ func RunMetaDBIndexTests(baseURL, port string) { multiImage = GetMultiarchImageForImages([]Image{ image1, image2, }) - err = UploadMultiarchImageWithRef(multiImage, baseURL, "index-one-arch-more-layers", "index-one-arch-more-layers") + err = UploadMultiarchImage(multiImage, baseURL, "index-one-arch-more-layers", "index-one-arch-more-layers") So(err, ShouldBeNil) // ---------------- MORE LAYERS ------------------- @@ -5252,7 +5138,7 @@ func RunMetaDBIndexTests(baseURL, port string) { multiImage := GetMultiarchImageForImages([]Image{ imageAMD64, imageSomeArch, }) - err = UploadMultiarchImageWithRef(multiImage, baseURL, "test-repo", "index") + err = UploadMultiarchImage(multiImage, baseURL, "test-repo", "index") So(err, ShouldBeNil) // ---------------- BASE IMAGE FOR LINUX AMD64 ------------------- @@ -5266,9 +5152,8 @@ func RunMetaDBIndexTests(baseURL, port string) { }, ) So(err, ShouldBeNil) - image.Reference = "more-layers-linux-amd64" - err = UploadImage(image, baseURL, "test-repo") + err = UploadImage(image, baseURL, "test-repo", "more-layers-linux-amd64") So(err, ShouldBeNil) // ---------------- BASE IMAGE FOR LINUX SOMEARCH ------------------- @@ -5283,9 +5168,8 @@ func RunMetaDBIndexTests(baseURL, port string) { }, ) So(err, ShouldBeNil) - image.Reference = "more-layers-linux-somearch" - err = UploadImage(image, baseURL, "test-repo") + err = UploadImage(image, baseURL, "test-repo", "more-layers-linux-somearch") So(err, ShouldBeNil) // ------- TEST @@ -5356,13 +5240,10 @@ func TestMetaDBWhenReadingImages(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest1, - Config: config1, - Layers: layers1, - Reference: "1.0.1", - }, - baseURL, - "repo1", + Manifest: manifest1, + Config: config1, + Layers: layers1, + }, baseURL, "repo1", "1.0.1", ) So(err, ShouldBeNil) @@ -5440,14 +5321,10 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { defer ctlrManager.StopServer() // push test images to repo 1 image 1 - image1, err := GetRandomImage("1.0.1") + image1, err := GetRandomImage() So(err, ShouldBeNil) - err = UploadImage( - image1, - baseURL, - "repo1", - ) + err = UploadImage(image1, baseURL, "repo1", "1.0.1") So(err, ShouldBeNil) // push test images to repo 1 image 2 @@ -5462,13 +5339,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { }) So(err, ShouldBeNil) - image2.Reference = "1.0.2" - - err = UploadImage( - image2, - baseURL, - "repo1", - ) + err = UploadImage(image2, baseURL, "repo1", "1.0.2") So(err, ShouldBeNil) query := ` @@ -5692,11 +5563,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { referrerImage, err := GetImageWithSubject(referredImageDigest, ispec.MediaTypeImageManifest) So(err, ShouldBeNil) - err = UploadImage( - referrerImage, - baseURL, - "repo1", - ) + err = UploadImage(referrerImage, baseURL, "repo1", referrerImage.DigestStr()) So(err, ShouldBeNil) // ------- check referrers for this image @@ -5720,14 +5587,14 @@ func TestMetaDBWhenDeletingImages(t *testing.T) { So(err, ShouldBeNil) So(len(responseStruct.Referrers), ShouldEqual, 1) - So(responseStruct.Referrers[0].Digest, ShouldResemble, referrerImage.Reference) + So(responseStruct.Referrers[0].Digest, ShouldResemble, referrerImage.DigestStr()) - statusCode, err := DeleteImage("repo1", referrerImage.Reference, "badURL") + statusCode, err := DeleteImage("repo1", referrerImage.DigestStr(), "badURL") So(err, ShouldNotBeNil) So(statusCode, ShouldEqual, -1) // ------- Delete the referrer and see if it disappears from metaDB also - statusCode, err = DeleteImage("repo1", referrerImage.Reference, baseURL) + statusCode, err = DeleteImage("repo1", referrerImage.DigestStr(), baseURL) So(err, ShouldBeNil) So(statusCode, ShouldEqual, http.StatusAccepted) @@ -5909,13 +5776,10 @@ func TestSearchSize(t *testing.T) { err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "latest", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "latest", ) So(err, ShouldBeNil) @@ -5994,13 +5858,10 @@ func TestSearchSize(t *testing.T) { // add the same image with different tag err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: "10.2.14", - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, "10.2.14", ) So(err, ShouldBeNil) @@ -6169,11 +6030,9 @@ func TestImageSummary(t *testing.T) { }, ) So(err, ShouldBeNil) - image.Reference = tagTarget - manifestDigest := image.Digest() - err = UploadImage(image, baseURL, repoName) + err = UploadImage(image, baseURL, repoName, tagTarget) So(err, ShouldBeNil) // ------ Add a referrer @@ -6187,9 +6046,8 @@ func TestImageSummary(t *testing.T) { referrerImage.Manifest.Config.MediaType = "application/test.artifact.type" referrerImage.Manifest.Annotations = map[string]string{"testAnnotationKey": "testAnnotationValue"} referrerManifestDigest := referrerImage.Digest() - referrerImage.Reference = referrerManifestDigest.String() - err = UploadImage(referrerImage, baseURL, repoName) + err = UploadImage(referrerImage, baseURL, repoName, referrerManifestDigest.String()) So(err, ShouldBeNil) var ( @@ -6393,13 +6251,10 @@ func TestImageSummary(t *testing.T) { tagTarget := "latest" err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: tagTarget, - }, - baseURL, - repoName, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repoName, tagTarget, ) So(err, ShouldBeNil) var ( @@ -6488,21 +6343,21 @@ func TestImageSummary(t *testing.T) { artType1 := "application/test.signature.v1" artType2 := "application/test.signature.v2" - img1, err := GetRandomImage("art1") + img1, err := GetRandomImage() So(err, ShouldBeNil) img1.Manifest.Config = ispec.DescriptorEmptyJSON img1.Manifest.ArtifactType = artType1 digest1 := img1.Digest() - err = UploadImage(img1, baseURL, "repo") + err = UploadImage(img1, baseURL, "repo", "art1") So(err, ShouldBeNil) - img2, err := GetRandomImage("art2") + img2, err := GetRandomImage() So(err, ShouldBeNil) img2.Manifest.Config.MediaType = artType2 digest2 := img2.Digest() - err = UploadImage(img2, baseURL, "repo") + err = UploadImage(img2, baseURL, "repo", "art2") So(err, ShouldBeNil) // GET image 1 diff --git a/pkg/extensions/search/userprefs_test.go b/pkg/extensions/search/userprefs_test.go index 1e134039..b0d6701b 100644 --- a/pkg/extensions/search/userprefs_test.go +++ b/pkg/extensions/search/userprefs_test.go @@ -98,22 +98,20 @@ func TestUserData(t *testing.T) { err = UploadImageWithBasicAuth( Image{ - Config: config, - Layers: layers, - Manifest: manifest, - Reference: tag, - }, baseURL, accessibleRepo, + Config: config, + Layers: layers, + Manifest: manifest, + }, baseURL, accessibleRepo, tag, adminUser, adminPassword, ) So(err, ShouldBeNil) err = UploadImageWithBasicAuth( Image{ - Config: config, - Layers: layers, - Manifest: manifest, - Reference: tag, - }, baseURL, forbiddenRepo, + Config: config, + Layers: layers, + Manifest: manifest, + }, baseURL, forbiddenRepo, tag, adminUser, adminPassword, ) So(err, ShouldBeNil) @@ -533,7 +531,7 @@ func TestChangingRepoState(t *testing.T) { ctlr := api.NewController(conf) - img, err := GetRandomImage("tag") + img, err := GetRandomImage() if err != nil { t.FailNow() } @@ -542,14 +540,14 @@ func TestChangingRepoState(t *testing.T) { defaultStore := local.NewImageStore(conf.Storage.RootDirectory, false, 0, false, false, log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), nil, nil) - err = WriteImageToFileSystem(img, accesibleRepo, storage.StoreController{ + err = WriteImageToFileSystem(img, accesibleRepo, "tag", storage.StoreController{ DefaultStore: defaultStore, }) if err != nil { t.FailNow() } - err = WriteImageToFileSystem(img, forbiddenRepo, storage.StoreController{ + err = WriteImageToFileSystem(img, forbiddenRepo, "tag", storage.StoreController{ DefaultStore: defaultStore, }) if err != nil { @@ -664,16 +662,16 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) { // ------ Add simple repo repo := "repo" - img, err := GetRandomImage("tag") + img, err := GetRandomImage() So(err, ShouldBeNil) - err = UploadImageWithBasicAuth(img, baseURL, repo, simpleUser, simpleUserPassword) + err = UploadImageWithBasicAuth(img, baseURL, repo, "tag", simpleUser, simpleUserPassword) So(err, ShouldBeNil) // ------ Add repo and star it sRepo := "starred-repo" - img, err = GetRandomImage("tag") + img, err = GetRandomImage() So(err, ShouldBeNil) - err = UploadImageWithBasicAuth(img, baseURL, sRepo, simpleUser, simpleUserPassword) + err = UploadImageWithBasicAuth(img, baseURL, sRepo, "tag", simpleUser, simpleUserPassword) So(err, ShouldBeNil) resp, err := simpleUserClient.Put(preferencesBaseURL + PutRepoStarURL(sRepo)) @@ -682,9 +680,9 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) { // ------ Add repo and bookmark it bRepo := "bookmarked-repo" - img, err = GetRandomImage("tag") + img, err = GetRandomImage() So(err, ShouldBeNil) - err = UploadImageWithBasicAuth(img, baseURL, bRepo, simpleUser, simpleUserPassword) + err = UploadImageWithBasicAuth(img, baseURL, bRepo, "tag", simpleUser, simpleUserPassword) So(err, ShouldBeNil) resp, err = simpleUserClient.Put(preferencesBaseURL + PutRepoBookmarkURL(bRepo)) @@ -693,9 +691,9 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) { // ------ Add repo, star and bookmark it sbRepo := "starred-bookmarked-repo" - img, err = GetRandomImage("tag") + img, err = GetRandomImage() So(err, ShouldBeNil) - err = UploadImageWithBasicAuth(img, baseURL, sbRepo, simpleUser, simpleUserPassword) + err = UploadImageWithBasicAuth(img, baseURL, sbRepo, "tag", simpleUser, simpleUserPassword) So(err, ShouldBeNil) resp, err = simpleUserClient.Put(preferencesBaseURL + PutRepoStarURL(sbRepo)) @@ -857,9 +855,9 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) { // ------ Add sbrepo and star/bookmark it sbrepo := "sbrepo" - img, err := GetRandomImage("tag") + img, err := GetRandomImage() So(err, ShouldBeNil) - err = UploadImageWithBasicAuth(img, baseURL, sbrepo, simpleUser, simpleUserPassword) + err = UploadImageWithBasicAuth(img, baseURL, sbrepo, "tag", simpleUser, simpleUserPassword) So(err, ShouldBeNil) resp, err := simpleUserClient.Put(preferencesBaseURL + PutRepoStarURL(sbrepo)) @@ -897,9 +895,9 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) { // ------ Add srepo and star it srepo := "srepo" - img, err = GetRandomImage("tag") + img, err = GetRandomImage() So(err, ShouldBeNil) - err = UploadImageWithBasicAuth(img, baseURL, srepo, simpleUser, simpleUserPassword) + err = UploadImageWithBasicAuth(img, baseURL, srepo, "tag", simpleUser, simpleUserPassword) So(err, ShouldBeNil) resp, err = simpleUserClient.Put(preferencesBaseURL + PutRepoStarURL(srepo)) @@ -932,9 +930,9 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) { // ------ Add brepo and bookmark it brepo := "brepo" - img, err = GetRandomImage("tag") + img, err = GetRandomImage() So(err, ShouldBeNil) - err = UploadImageWithBasicAuth(img, baseURL, brepo, simpleUser, simpleUserPassword) + err = UploadImageWithBasicAuth(img, baseURL, brepo, "tag", simpleUser, simpleUserPassword) So(err, ShouldBeNil) resp, err = simpleUserClient.Put(preferencesBaseURL + PutRepoBookmarkURL(brepo)) @@ -967,9 +965,9 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) { // ------ Add repo without star/bookmark repo := "repo" - img, err = GetRandomImage("tag") + img, err = GetRandomImage() So(err, ShouldBeNil) - err = UploadImageWithBasicAuth(img, baseURL, repo, simpleUser, simpleUserPassword) + err = UploadImageWithBasicAuth(img, baseURL, repo, "tag", simpleUser, simpleUserPassword) So(err, ShouldBeNil) // ExpandedRepoinfo diff --git a/pkg/extensions/sync/sync_test.go b/pkg/extensions/sync/sync_test.go index 085f6346..cfcb6020 100644 --- a/pkg/extensions/sync/sync_test.go +++ b/pkg/extensions/sync/sync_test.go @@ -721,7 +721,7 @@ func TestOnDemand(t *testing.T) { cm.StartAndWait(conf.HTTP.Port) defer cm.StopServer() - imageConfig, layers, manifest, err := test.GetRandomImageComponents(10) + imageConfig, layers, manifest, err := test.GetRandomImageComponents(10) //nolint:staticcheck So(err, ShouldBeNil) manifestBlob, err := json.Marshal(manifest) @@ -730,9 +730,8 @@ func TestOnDemand(t *testing.T) { manifestDigest := godigest.FromBytes(manifestBlob) err = test.UploadImage( - test.Image{Config: imageConfig, Layers: layers, Manifest: manifest, Reference: "test"}, - srcBaseURL, - "remote-repo", + test.Image{Config: imageConfig, Layers: layers, Manifest: manifest}, + srcBaseURL, "remote-repo", "test", ) So(err, ShouldBeNil) @@ -1076,7 +1075,7 @@ func TestSyncWithNonDistributableBlob(t *testing.T) { dcm := test.NewControllerManager(dctlr) - imageConfig, layers, manifest, err := test.GetRandomImageComponents(10) + imageConfig, layers, manifest, err := test.GetRandomImageComponents(10) //nolint:staticcheck So(err, ShouldBeNil) nonDistributableLayer := make([]byte, 10) @@ -1093,9 +1092,8 @@ func TestSyncWithNonDistributableBlob(t *testing.T) { manifest.Layers = append(manifest.Layers, nonDistributableLayerDesc) err = test.UploadImage( - test.Image{Config: imageConfig, Layers: layers, Manifest: manifest, Reference: tag}, - srcBaseURL, - repoName, + test.Image{Config: imageConfig, Layers: layers, Manifest: manifest}, + srcBaseURL, repoName, tag, ) So(err, ShouldBeNil) @@ -1266,7 +1264,7 @@ func TestDockerImagesAreSkipped(t *testing.T) { // upload multiple manifests for i := 0; i < 4; i++ { - config, layers, manifest, err := test.GetImageComponents(1000 + i) + config, layers, manifest, err := test.GetImageComponents(1000 + i) //nolint:staticcheck So(err, ShouldBeNil) manifestContent, err := json.Marshal(manifest) @@ -1276,13 +1274,10 @@ func TestDockerImagesAreSkipped(t *testing.T) { err = test.UploadImage( test.Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: manifestDigest.String(), - }, - srcBaseURL, - "index") + Manifest: manifest, + Config: config, + Layers: layers, + }, srcBaseURL, "index", manifestDigest.String()) So(err, ShouldBeNil) index.Manifests = append(index.Manifests, ispec.Descriptor{ @@ -4439,10 +4434,10 @@ func TestSyncedSignaturesMetaDB(t *testing.T) { defer scm.StopServer() // Push an image - signedImage, err := test.GetRandomImage(tag) + signedImage, err := test.GetRandomImage() //nolint:staticcheck So(err, ShouldBeNil) - err = test.UploadImage(signedImage, srcBaseURL, repoName) + err = test.UploadImage(signedImage, srcBaseURL, repoName, tag) So(err, ShouldBeNil) err = test.SignImageUsingNotary(repoName+":"+tag, srcPort) @@ -6104,7 +6099,7 @@ func TestSyncImageIndex(t *testing.T) { // upload multiple manifests for i := 0; i < 4; i++ { - config, layers, manifest, err := test.GetImageComponents(1000 + i) + config, layers, manifest, err := test.GetImageComponents(1000 + i) //nolint:staticcheck So(err, ShouldBeNil) manifestContent, err := json.Marshal(manifest) @@ -6114,13 +6109,10 @@ func TestSyncImageIndex(t *testing.T) { err = test.UploadImage( test.Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: manifestDigest.String(), - }, - srcBaseURL, - "index") + Manifest: manifest, + Config: config, + Layers: layers, + }, srcBaseURL, "index", manifestDigest.String()) So(err, ShouldBeNil) index.Manifests = append(index.Manifests, ispec.Descriptor{ diff --git a/pkg/meta/meta_test.go b/pkg/meta/meta_test.go index c06f19fb..6a2725d3 100644 --- a/pkg/meta/meta_test.go +++ b/pkg/meta/meta_test.go @@ -1152,7 +1152,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("trusted signature", func() { - _, _, manifest, _ := test.GetRandomImageComponents(10) + _, _, manifest, _ := test.GetRandomImageComponents(10) //nolint:staticcheck manifestContent, _ := json.Marshal(manifest) manifestDigest := godigest.FromBytes(manifestContent) repo := "repo" @@ -2685,7 +2685,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("Test index logic", func() { - multiArch, err := test.GetRandomMultiarchImage("tag1") + multiArch, err := test.GetRandomMultiarchImage("tag1") //nolint:staticcheck So(err, ShouldBeNil) indexDigest := multiArch.Digest() @@ -2704,7 +2704,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("Test Referrers", func() { - image, err := test.GetRandomImage("tag") + image, err := test.GetRandomImage() //nolint:staticcheck So(err, ShouldBeNil) referredDigest := image.Digest() @@ -2728,7 +2728,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func // ------- Add Artifact 1 - artifact1, err := test.GetImageWithSubject( + artifact1, err := test.GetImageWithSubject( //nolint:staticcheck referredDigest, ispec.MediaTypeImageManifest, ) @@ -2744,7 +2744,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func // ------- Add Artifact 2 - artifact2, err := test.GetImageWithSubject( + artifact2, err := test.GetImageWithSubject( //nolint:staticcheck referredDigest, ispec.MediaTypeImageManifest, ) @@ -2867,7 +2867,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func }) Convey("FilterRepos", func() { - img, err := test.GetRandomImage("img1") + img, err := test.GetRandomImage() //nolint:staticcheck So(err, ShouldBeNil) imgDigest := img.Digest() @@ -2877,7 +2877,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func err = metaDB.SetManifestData(imgDigest, manifestData) So(err, ShouldBeNil) - multiarch, err := test.GetRandomMultiarchImage("multi") + multiarch, err := test.GetRandomMultiarchImage("multi") //nolint:staticcheck So(err, ShouldBeNil) multiarchDigest := multiarch.Digest() @@ -2897,10 +2897,10 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func So(err, ShouldBeNil) } - err = metaDB.SetRepoReference("repo", img.Reference, imgDigest, img.Manifest.MediaType) + err = metaDB.SetRepoReference("repo", img.DigestStr(), imgDigest, img.Manifest.MediaType) So(err, ShouldBeNil) - err = metaDB.SetRepoReference("repo", multiarch.Reference, multiarchDigest, ispec.MediaTypeImageIndex) + err = metaDB.SetRepoReference("repo", multiarch.DigestStr(), multiarchDigest, ispec.MediaTypeImageIndex) So(err, ShouldBeNil) repoMetas, _, _, _, err := metaDB.FilterRepos(context.Background(), diff --git a/pkg/meta/signatures/signatures_test.go b/pkg/meta/signatures/signatures_test.go index bc24976c..6a711774 100644 --- a/pkg/meta/signatures/signatures_test.go +++ b/pkg/meta/signatures/signatures_test.go @@ -129,7 +129,7 @@ func TestVerifySignatures(t *testing.T) { }) Convey("empty manifest digest", t, func() { - image, err := test.GetRandomImage("image") + image, err := test.GetRandomImage() //nolint:staticcheck So(err, ShouldBeNil) manifestContent, err := json.Marshal(image.Manifest) @@ -141,7 +141,7 @@ func TestVerifySignatures(t *testing.T) { }) Convey("wrong signature type", t, func() { - image, err := test.GetRandomImage("image") + image, err := test.GetRandomImage() //nolint:staticcheck So(err, ShouldBeNil) manifestContent, err := json.Marshal(image.Manifest) @@ -157,7 +157,7 @@ func TestVerifySignatures(t *testing.T) { Convey("verify cosign signature", t, func() { repo := "repo" tag := "test" - image, err := test.GetRandomImage(tag) + image, err := test.GetRandomImage() //nolint:staticcheck So(err, ShouldBeNil) manifestContent, err := json.Marshal(image.Manifest) @@ -218,7 +218,7 @@ func TestVerifySignatures(t *testing.T) { cm.StartAndWait(conf.HTTP.Port) defer cm.StopServer() - err := test.UploadImage(image, baseURL, repo) + err := test.UploadImage(image, baseURL, repo, tag) So(err, ShouldBeNil) err = signatures.InitCosignDir(rootDir) @@ -292,7 +292,7 @@ func TestVerifySignatures(t *testing.T) { Convey("verify notation signature", t, func() { repo := "repo" tag := "test" - image, err := test.GetRandomImage(tag) + image, err := test.GetRandomImage() //nolint:staticcheck So(err, ShouldBeNil) manifestContent, err := json.Marshal(image.Manifest) @@ -365,7 +365,7 @@ func TestVerifySignatures(t *testing.T) { cm.StartAndWait(conf.HTTP.Port) defer cm.StopServer() - err := test.UploadImage(image, baseURL, repo) + err := test.UploadImage(image, baseURL, repo, tag) So(err, ShouldBeNil) err = signatures.InitNotationDir(rootDir) diff --git a/pkg/meta/storage_parsing_test.go b/pkg/meta/storage_parsing_test.go index faed8088..ce84ad07 100644 --- a/pkg/meta/storage_parsing_test.go +++ b/pkg/meta/storage_parsing_test.go @@ -317,8 +317,8 @@ func TestParseStorageErrors(t *testing.T) { err = meta.ParseRepo("repo", metaDB, storeController, log) So(err, ShouldNotBeNil) - _, _, cosignManifestContent, _ := test.GetRandomImageComponents(10) - _, _, signedManifest, _ := test.GetRandomImageComponents(10) + _, _, cosignManifestContent, _ := test.GetRandomImageComponents(10) //nolint:staticcheck + _, _, signedManifest, _ := test.GetRandomImageComponents(10) //nolint:staticcheck signatureTag, err := test.GetCosignSignatureTagForManifest(signedManifest) So(err, ShouldBeNil) @@ -414,20 +414,17 @@ func RunParseStorageTests(rootDir string, metaDB mTypes.MetaDB) { storeController := storage.StoreController{DefaultStore: imageStore} manifests := []ispec.Manifest{} for i := 0; i < 3; i++ { - config, layers, manifest, err := test.GetRandomImageComponents(100) + config, layers, manifest, err := test.GetRandomImageComponents(100) //nolint:staticcheck So(err, ShouldBeNil) manifests = append(manifests, manifest) err = test.WriteImageToFileSystem( test.Image{ - Config: config, - Layers: layers, - Manifest: manifest, - Reference: fmt.Sprintf("tag%d", i), - }, - repo, - storeController) + Config: config, + Layers: layers, + Manifest: manifest, + }, repo, fmt.Sprintf("tag%d", i), storeController) So(err, ShouldBeNil) } @@ -440,18 +437,15 @@ func RunParseStorageTests(rootDir string, metaDB mTypes.MetaDB) { signedManifestDigest := godigest.FromBytes(manifestBlob) - config, layers, manifest, err := test.GetRandomImageComponents(100) + config, layers, manifest, err := test.GetRandomImageComponents(100) //nolint:staticcheck So(err, ShouldBeNil) err = test.WriteImageToFileSystem( test.Image{ - Config: config, - Layers: layers, - Manifest: manifest, - Reference: signatureTag, - }, - repo, - storeController) + Config: config, + Layers: layers, + Manifest: manifest, + }, repo, signatureTag, storeController) So(err, ShouldBeNil) // remove tag2 from index.json @@ -508,22 +502,19 @@ func RunParseStorageTests(rootDir string, metaDB mTypes.MetaDB) { storeController := storage.StoreController{DefaultStore: imageStore} // add an image - config, layers, manifest, err := test.GetRandomImageComponents(100) + config, layers, manifest, err := test.GetRandomImageComponents(100) //nolint:staticcheck So(err, ShouldBeNil) err = test.WriteImageToFileSystem( test.Image{ - Config: config, - Layers: layers, - Manifest: manifest, - Reference: "tag1", - }, - repo, - storeController) + Config: config, + Layers: layers, + Manifest: manifest, + }, repo, "tag1", storeController) So(err, ShouldBeNil) // add mock cosign signature without pushing the signed image - image, err := test.GetRandomImage("") + image, err := test.GetRandomImage() //nolint:staticcheck So(err, ShouldBeNil) signatureTag, err := test.GetCosignSignatureTagForManifest(image.Manifest) @@ -532,18 +523,15 @@ func RunParseStorageTests(rootDir string, metaDB mTypes.MetaDB) { missingImageDigest := image.Digest() // get the body of the signature - config, layers, manifest, err = test.GetRandomImageComponents(100) + config, layers, manifest, err = test.GetRandomImageComponents(100) //nolint:staticcheck So(err, ShouldBeNil) err = test.WriteImageToFileSystem( test.Image{ - Config: config, - Layers: layers, - Manifest: manifest, - Reference: signatureTag, - }, - repo, - storeController) + Config: config, + Layers: layers, + Manifest: manifest, + }, repo, signatureTag, storeController) So(err, ShouldBeNil) err = meta.ParseStorage(metaDB, storeController, log.NewLogger("debug", "")) @@ -572,15 +560,12 @@ func RunParseStorageTests(rootDir string, metaDB mTypes.MetaDB) { storeController := storage.StoreController{DefaultStore: imageStore} // add an image - image, err := test.GetRandomImage("tag") + image, err := test.GetRandomImage() //nolint:staticcheck So(err, ShouldBeNil) manifestDigest := image.Digest() - err = test.WriteImageToFileSystem( - image, - repo, - storeController) + err = test.WriteImageToFileSystem(image, repo, "tag", storeController) So(err, ShouldBeNil) err = metaDB.SetRepoReference(repo, "tag", manifestDigest, ispec.MediaTypeImageManifest) diff --git a/pkg/meta/update_test.go b/pkg/meta/update_test.go index 253aed0a..733966bd 100644 --- a/pkg/meta/update_test.go +++ b/pkg/meta/update_test.go @@ -44,15 +44,13 @@ func TestOnUpdateManifest(t *testing.T) { metaDB, err := boltdb.New(boltDriver, log) So(err, ShouldBeNil) - config, layers, manifest, err := test.GetRandomImageComponents(100) + config, layers, manifest, err := test.GetRandomImageComponents(100) //nolint:staticcheck So(err, ShouldBeNil) err = test.WriteImageToFileSystem( test.Image{ - Config: config, Manifest: manifest, Layers: layers, Reference: "tag1", - }, - "repo", - storeController) + Config: config, Manifest: manifest, Layers: layers, + }, "repo", "tag1", storeController) So(err, ShouldBeNil) manifestBlob, err := json.Marshal(manifest) diff --git a/pkg/storage/s3/s3_test.go b/pkg/storage/s3/s3_test.go index bd01938e..9430b2cc 100644 --- a/pkg/storage/s3/s3_test.go +++ b/pkg/storage/s3/s3_test.go @@ -480,7 +480,7 @@ func TestGetOrasAndOCIReferrers(t *testing.T) { _, imgStore, _ := createObjectsStore(testDir, tdir, true) Convey("Upload test image", t, func(c C) { - cfg, layers, manifest, err := test.GetImageComponents(100) + cfg, layers, manifest, err := test.GetImageComponents(100) //nolint:staticcheck So(err, ShouldBeNil) for _, content := range layers { diff --git a/pkg/storage/scrub_test.go b/pkg/storage/scrub_test.go index bea4c239..460695ec 100644 --- a/pkg/storage/scrub_test.go +++ b/pkg/storage/scrub_test.go @@ -55,7 +55,7 @@ func TestCheckAllBlobsIntegrity(t *testing.T) { storeCtlr := storage.StoreController{} storeCtlr.DefaultStore = imgStore - config, layers, manifest, err := test.GetImageComponents(1000) + config, layers, manifest, err := test.GetImageComponents(1000) //nolint:staticcheck So(err, ShouldBeNil) layerReader := bytes.NewReader(layers[0]) @@ -223,7 +223,7 @@ func TestCheckAllBlobsIntegrity(t *testing.T) { }) Convey("Scrub index", func() { - newConfig, newLayers, newManifest, err := test.GetImageComponents(10) + newConfig, newLayers, newManifest, err := test.GetImageComponents(10) //nolint:staticcheck So(err, ShouldBeNil) newLayerReader := bytes.NewReader(newLayers[0]) diff --git a/pkg/test/common.go b/pkg/test/common.go index f3457a2f..8bd56a05 100644 --- a/pkg/test/common.go +++ b/pkg/test/common.go @@ -278,7 +278,7 @@ func NewControllerManager(controller Controller) ControllerManager { return cm } -func WriteImageToFileSystem(image Image, repoName string, storeController storage.StoreController) error { +func WriteImageToFileSystem(image Image, repoName, ref string, storeController storage.StoreController) error { store := storeController.GetImageStore(repoName) err := store.InitRepo(repoName) @@ -314,7 +314,7 @@ func WriteImageToFileSystem(image Image, repoName string, storeController storag return err } - _, _, err = store.PutImageManifest(repoName, image.Reference, ispec.MediaTypeImageManifest, manifestBlob) + _, _, err = store.PutImageManifest(repoName, ref, ispec.MediaTypeImageManifest, manifestBlob) if err != nil { return err } @@ -333,7 +333,7 @@ func WriteMultiArchImageToFileSystem(multiarchImage MultiarchImage, repoName, re } for _, image := range multiarchImage.Images { - err := WriteImageToFileSystem(image, repoName, storeController) + err := WriteImageToFileSystem(image, repoName, image.DigestStr(), storeController) if err != nil { return err } @@ -503,6 +503,7 @@ func GetOciLayoutDigests(imagePath string) (godigest.Digest, godigest.Digest, go return manifestDigest, configDigest, layerDigest } +// Deprecated: Should use the new functions starting with "Create". func GetImageComponents(layerSize int) (ispec.Image, [][]byte, ispec.Manifest, error) { config := ispec.Image{ Platform: ispec.Platform{ @@ -551,6 +552,7 @@ func GetImageComponents(layerSize int) (ispec.Image, [][]byte, ispec.Manifest, e return config, layers, manifest, nil } +// Deprecated: Should use the new functions starting with "Create". func GetRandomImageComponents(layerSize int) (ispec.Image, [][]byte, ispec.Manifest, error) { config := ispec.Image{ Platform: ispec.Platform{ @@ -606,7 +608,8 @@ const ( Vulnerability3ID = "CVE-2023-2975" ) -func GetVulnImageWithConfig(ref string, config ispec.Image) (Image, error) { +// Deprecated: Should use the new functions starting with "Create". +func GetVulnImageWithConfig(config ispec.Image) (Image, error) { vulnerableLayer, err := GetLayerWithVulnerability() if err != nil { return Image{}, err @@ -632,8 +635,6 @@ func GetVulnImageWithConfig(ref string, config ispec.Image) (Image, error) { return Image{}, err } - img.Reference = ref - return img, err } @@ -693,7 +694,8 @@ func GetRandomLayer(size int) []byte { return layer } -func GetRandomImage(reference string) (Image, error) { +// Deprecated: Should use the new functions starting with "Create". +func GetRandomImage() (Image, error) { const layerSize = 20 config, layers, manifest, err := GetRandomImageComponents(layerSize) @@ -701,23 +703,14 @@ func GetRandomImage(reference string) (Image, error) { return Image{}, err } - if reference == "" { - blob, err := json.Marshal(manifest) - if err != nil { - return Image{}, err - } - - reference = godigest.FromBytes(blob).String() - } - return Image{ - Manifest: manifest, - Layers: layers, - Config: config, - Reference: reference, + Manifest: manifest, + Layers: layers, + Config: config, }, nil } +// Deprecated: Should use the new functions starting with "Create". func GetImageComponentsWithConfig(conf ispec.Image) (ispec.Image, [][]byte, ispec.Manifest, error) { configBlob, err := json.Marshal(conf) if err = inject.Error(err); err != nil { @@ -762,25 +755,21 @@ func GetImageComponentsWithConfig(conf ispec.Image) (ispec.Image, [][]byte, ispe return conf, layers, manifest, nil } +// Deprecated: Should use the new functions starting with "Create". func GetImageWithConfig(conf ispec.Image) (Image, error) { config, layers, manifest, err := GetImageComponentsWithConfig(conf) if err != nil { return Image{}, err } - blob, err := json.Marshal(manifest) - if err != nil { - return Image{}, err - } - return Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: godigest.FromBytes(blob).String(), + Manifest: manifest, + Config: config, + Layers: layers, }, nil } +// Deprecated: Should use the new functions starting with "Create". func GetImageWithComponents(config ispec.Image, layers [][]byte) (Image, error) { configBlob, err := json.Marshal(config) if err != nil { @@ -812,16 +801,10 @@ func GetImageWithComponents(config ispec.Image, layers [][]byte) (Image, error) Layers: manifestLayers, } - manifestBlob, err := json.Marshal(manifest) - if err != nil { - return Image{}, err - } - return Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: godigest.FromBytes(manifestBlob).String(), + Manifest: manifest, + Config: config, + Layers: layers, }, nil } @@ -840,6 +823,7 @@ func GetCosignSignatureTagForDigest(manifestDigest godigest.Digest) string { return manifestDigest.Algorithm().String() + "-" + manifestDigest.Encoded() + ".sig" } +// Deprecated: Should use the new functions starting with "Create". func GetImageWithSubject(subjectDigest godigest.Digest, mediaType string) (Image, error) { num := 100 @@ -853,133 +837,14 @@ func GetImageWithSubject(subjectDigest godigest.Digest, mediaType string) (Image MediaType: mediaType, } - blob, err := json.Marshal(manifest) - if err != nil { - return Image{}, err - } - return Image{ - Manifest: manifest, - Config: conf, - Layers: layers, - Reference: godigest.FromBytes(blob).String(), + Manifest: manifest, + Config: conf, + Layers: layers, }, nil } -func UploadImage(img Image, baseURL, repo string) error { - for _, blob := range img.Layers { - resp, err := resty.R().Post(baseURL + "/v2/" + repo + "/blobs/uploads/") - if err != nil { - return err - } - - if resp.StatusCode() != http.StatusAccepted { - return ErrPostBlob - } - - loc := resp.Header().Get("Location") - - digest := godigest.FromBytes(blob).String() - - resp, err = resty.R(). - SetHeader("Content-Length", fmt.Sprintf("%d", len(blob))). - SetHeader("Content-Type", "application/octet-stream"). - SetQueryParam("digest", digest). - SetBody(blob). - Put(baseURL + loc) - - if err != nil { - return err - } - - if resp.StatusCode() != http.StatusCreated { - return ErrPutBlob - } - } - - var err error - - cblob := img.ConfigDescriptor.Data - - // we'll remove this check once we make the full transition to the new way of generating test images - if len(cblob) == 0 { - cblob, err = json.Marshal(img.Config) - if err = inject.Error(err); err != nil { - return err - } - } - - cdigest := godigest.FromBytes(cblob) - - if img.Manifest.Config.MediaType == ispec.MediaTypeEmptyJSON || - img.Manifest.Config.Digest == ispec.DescriptorEmptyJSON.Digest { - cblob = ispec.DescriptorEmptyJSON.Data - cdigest = ispec.DescriptorEmptyJSON.Digest - } - - resp, err := resty.R(). - Post(baseURL + "/v2/" + repo + "/blobs/uploads/") - if err = inject.Error(err); err != nil { - return err - } - - if inject.ErrStatusCode(resp.StatusCode()) != http.StatusAccepted || inject.ErrStatusCode(resp.StatusCode()) == -1 { - return ErrPostBlob - } - - loc := Location(baseURL, resp) - - // uploading blob should get 201 - resp, err = resty.R(). - SetHeader("Content-Length", fmt.Sprintf("%d", len(cblob))). - SetHeader("Content-Type", "application/octet-stream"). - SetQueryParam("digest", cdigest.String()). - SetBody(cblob). - Put(loc) - if err = inject.Error(err); err != nil { - return err - } - - if inject.ErrStatusCode(resp.StatusCode()) != http.StatusCreated || inject.ErrStatusCode(resp.StatusCode()) == -1 { - return ErrPostBlob - } - - manifestBlob := img.ManifestDescriptor.Data - - // we'll remove this check once we make the full transition to the new way of generating test images - if len(manifestBlob) == 0 { - manifestBlob, err = json.Marshal(img.Manifest) - if err = inject.Error(err); err != nil { - return err - } - } - - // validate manifest - if err := storageCommon.ValidateManifestSchema(manifestBlob); err != nil { - return err - } - - if img.Reference == "" { - img.Reference = godigest.FromBytes(manifestBlob).String() - } - - resp, err = resty.R(). - SetHeader("Content-type", ispec.MediaTypeImageManifest). - SetBody(manifestBlob). - Put(baseURL + "/v2/" + repo + "/manifests/" + img.Reference) - - if inject.ErrStatusCode(resp.StatusCode()) != http.StatusCreated { - return ErrPutBlob - } - - if inject.ErrStatusCode(resp.StatusCode()) != http.StatusCreated { - return ErrPutBlob - } - - return err -} - -func UploadImageWithRef(img Image, baseURL, repo, ref string) error { +func UploadImage(img Image, baseURL, repo, ref string) error { for _, blob := range img.Layers { resp, err := resty.R().Post(baseURL + "/v2/" + repo + "/blobs/uploads/") if err != nil { @@ -1137,13 +1002,13 @@ func PushTestImage(repoName string, tag string, //nolint:unparam ) error { err := UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: tag, + Manifest: manifest, + Config: config, + Layers: layers, }, baseURL, repoName, + tag, ) return err @@ -1662,101 +1527,7 @@ func Contains[E isser](s []E, name string) bool { return Index(s, name) >= 0 } -func UploadImageWithBasicAuth(img Image, baseURL, repo, user, password string) error { - for _, blob := range img.Layers { - resp, err := resty.R(). - SetBasicAuth(user, password). - Post(baseURL + "/v2/" + repo + "/blobs/uploads/") - if err != nil { - return err - } - - if resp.StatusCode() != http.StatusAccepted { - return ErrPostBlob - } - - loc := resp.Header().Get("Location") - - digest := godigest.FromBytes(blob).String() - - resp, err = resty.R(). - SetBasicAuth(user, password). - SetHeader("Content-Length", fmt.Sprintf("%d", len(blob))). - SetHeader("Content-Type", "application/octet-stream"). - SetQueryParam("digest", digest). - SetBody(blob). - Put(baseURL + loc) - - if err != nil { - return err - } - - if resp.StatusCode() != http.StatusCreated { - return ErrPutBlob - } - } - // upload config - cblob, err := json.Marshal(img.Config) - if err = inject.Error(err); err != nil { - return err - } - - cdigest := godigest.FromBytes(cblob) - - if img.Manifest.Config.MediaType == ispec.MediaTypeEmptyJSON { - cblob = ispec.DescriptorEmptyJSON.Data - cdigest = ispec.DescriptorEmptyJSON.Digest - } - - resp, err := resty.R(). - SetBasicAuth(user, password). - Post(baseURL + "/v2/" + repo + "/blobs/uploads/") - if err = inject.Error(err); err != nil { - return err - } - - if inject.ErrStatusCode(resp.StatusCode()) != http.StatusAccepted || inject.ErrStatusCode(resp.StatusCode()) == -1 { - return ErrPostBlob - } - - loc := Location(baseURL, resp) - - // uploading blob should get 201 - resp, err = resty.R(). - SetBasicAuth(user, password). - SetHeader("Content-Length", fmt.Sprintf("%d", len(cblob))). - SetHeader("Content-Type", "application/octet-stream"). - SetQueryParam("digest", cdigest.String()). - SetBody(cblob). - Put(loc) - if err = inject.Error(err); err != nil { - return err - } - - if inject.ErrStatusCode(resp.StatusCode()) != http.StatusCreated || inject.ErrStatusCode(resp.StatusCode()) == -1 { - return ErrPostBlob - } - - // put manifest - manifestBlob, err := json.Marshal(img.Manifest) - if err = inject.Error(err); err != nil { - return err - } - - if img.Reference == "" { - img.Reference = godigest.FromBytes(manifestBlob).String() - } - - _, err = resty.R(). - SetBasicAuth(user, password). - SetHeader("Content-type", "application/vnd.oci.image.manifest.v1+json"). - SetBody(manifestBlob). - Put(baseURL + "/v2/" + repo + "/manifests/" + img.Reference) - - return err -} - -func UploadImageWithBasicAuthRef(img Image, baseURL, repo, ref, user, password string) error { +func UploadImageWithBasicAuth(img Image, baseURL, repo, ref, user, password string) error { for _, blob := range img.Layers { resp, err := resty.R(). SetBasicAuth(user, password). @@ -1922,6 +1693,7 @@ func SignImageUsingNotary(repoTag, port string) error { return err } +// Deprecated: Should use the new functions starting with "Create". func GetRandomMultiarchImageComponents() (ispec.Index, []Image, error) { const layerSize = 100 @@ -1946,8 +1718,6 @@ func GetRandomMultiarchImageComponents() (ispec.Index, []Image, error) { return ispec.Index{}, []Image{}, err } - image1.Reference = getManifestDigest(image1.Manifest).String() - randomLayer2 := make([]byte, layerSize) _, err = rand.Read(randomLayer2) @@ -1969,8 +1739,6 @@ func GetRandomMultiarchImageComponents() (ispec.Index, []Image, error) { return ispec.Index{}, []Image{}, err } - image2.Reference = getManifestDigest(image2.Manifest).String() - randomLayer3 := make([]byte, layerSize) _, err = rand.Read(randomLayer3) @@ -1992,8 +1760,6 @@ func GetRandomMultiarchImageComponents() (ispec.Index, []Image, error) { return ispec.Index{}, []Image{}, err } - image3.Reference = getManifestDigest(image3.Manifest).String() - index := ispec.Index{ MediaType: ispec.MediaTypeImageIndex, Manifests: []ispec.Descriptor{ @@ -2018,6 +1784,7 @@ func GetRandomMultiarchImageComponents() (ispec.Index, []Image, error) { return index, []Image{image1, image2, image3}, nil } +// Deprecated: Should use the new functions starting with "Create". func GetRandomMultiarchImage(reference string) (MultiarchImage, error) { index, images, err := GetRandomMultiarchImageComponents() if err != nil { @@ -2031,18 +1798,16 @@ func GetRandomMultiarchImage(reference string) (MultiarchImage, error) { }, err } +// Deprecated: Should use the new functions starting with "Create". func GetMultiarchImageForImages(images []Image) MultiarchImage { var index ispec.Index - for i, image := range images { + for _, image := range images { index.Manifests = append(index.Manifests, ispec.Descriptor{ MediaType: ispec.MediaTypeImageManifest, Digest: getManifestDigest(image.Manifest), Size: getManifestSize(image.Manifest), }) - - // update the reference with the digest of the manifest - images[i].Reference = getManifestDigest(image.Manifest).String() } index.SchemaVersion = 2 @@ -2068,40 +1833,9 @@ func getManifestDigest(manifest ispec.Manifest) godigest.Digest { return godigest.FromBytes(manifestBlob) } -func UploadMultiarchImage(multiImage MultiarchImage, baseURL string, repo string) error { +func UploadMultiarchImage(multiImage MultiarchImage, baseURL string, repo, ref string) error { for _, image := range multiImage.Images { - err := UploadImage(image, baseURL, repo) - if err != nil { - return err - } - } - - // put manifest - indexBlob, err := json.Marshal(multiImage.Index) - if err = inject.Error(err); err != nil { - return err - } - - // validate manifest - if err := storageCommon.ValidateImageIndexSchema(indexBlob); err != nil { - return err - } - - resp, err := resty.R(). - SetHeader("Content-type", ispec.MediaTypeImageIndex). - SetBody(indexBlob). - Put(baseURL + "/v2/" + repo + "/manifests/" + multiImage.Reference) - - if resp.StatusCode() != http.StatusCreated { - return ErrPutIndex - } - - return err -} - -func UploadMultiarchImageWithRef(multiImage MultiarchImage, baseURL string, repo, ref string) error { - for _, image := range multiImage.Images { - err := UploadImageWithRef(image, baseURL, repo, image.DigestStr()) + err := UploadImage(image, baseURL, repo, image.DigestStr()) if err != nil { return err } diff --git a/pkg/test/common_test.go b/pkg/test/common_test.go index c1e75e76..fbbe2962 100644 --- a/pkg/test/common_test.go +++ b/pkg/test/common_test.go @@ -433,9 +433,8 @@ func TestUploadMultiarchImage(t *testing.T) { }, }, }, - Images: []test.Image{img}, - Reference: "index", - }, baseURL, "test") + Images: []test.Image{img}, + }, baseURL, "test", "index") So(err, ShouldBeNil) }) @@ -451,9 +450,8 @@ func TestUploadMultiarchImage(t *testing.T) { }, }, }, - Images: []test.Image{img}, - Reference: "index", - }, baseURL, "test") + Images: []test.Image{img}, + }, baseURL, "test", "index") So(err, ShouldNotBeNil) }) }) @@ -493,7 +491,7 @@ func TestUploadImage(t *testing.T) { Config: ispec.Image{}, } - err := test.UploadImage(img, baseURL, "test") + err := test.UploadImage(img, baseURL, "test", img.DigestStr()) So(err, ShouldNotBeNil) }) @@ -509,7 +507,7 @@ func TestUploadImage(t *testing.T) { Layers: make([][]byte, 10), } - err := test.UploadImage(img, baseURL, "test") + err := test.UploadImage(img, baseURL, "test", "") So(err, ShouldNotBeNil) }) @@ -537,7 +535,7 @@ func TestUploadImage(t *testing.T) { Layers: make([][]byte, 10), } - err = test.UploadImage(img, baseURL, "test") + err = test.UploadImage(img, baseURL, "test", "") So(err, ShouldNotBeNil) }) @@ -560,7 +558,7 @@ func TestUploadImage(t *testing.T) { Config: ispec.Image{}, } - err := test.UploadImage(img, baseURL, "test") + err := test.UploadImage(img, baseURL, "test", "") So(err, ShouldNotBeNil) }) @@ -600,7 +598,7 @@ func TestUploadImage(t *testing.T) { Config: ispec.Image{}, } - err := test.UploadImage(img, baseURL, "test") + err := test.UploadImage(img, baseURL, "test", img.DigestStr()) So(err, ShouldBeNil) }) @@ -659,31 +657,19 @@ func TestUploadImage(t *testing.T) { defer ctlrManager.StopServer() Convey("Request fail while pushing layer", func() { - err := test.UploadImageWithBasicAuth(test.Image{Layers: [][]byte{{1, 2, 3}}}, "badURL", "", "", "") - So(err, ShouldNotBeNil) - - err = test.UploadImageWithBasicAuthRef(test.Image{Layers: [][]byte{{1, 2, 3}}}, "badURL", "", "", "", "") + err := test.UploadImageWithBasicAuth(test.Image{Layers: [][]byte{{1, 2, 3}}}, "badURL", "", "", "", "") So(err, ShouldNotBeNil) }) Convey("Request status is not StatusOk while pushing layer", func() { - err := test.UploadImageWithBasicAuth(test.Image{Layers: [][]byte{{1, 2, 3}}}, baseURL, "", "repo", "") - So(err, ShouldNotBeNil) - - err = test.UploadImageWithBasicAuthRef(test.Image{Layers: [][]byte{{1, 2, 3}}}, baseURL, "", "repo", "", "") + err := test.UploadImageWithBasicAuth(test.Image{Layers: [][]byte{{1, 2, 3}}}, baseURL, "", "repo", "", "") So(err, ShouldNotBeNil) }) Convey("Request fail while pushing config", func() { - err := test.UploadImageWithBasicAuth(test.Image{}, "badURL", "", "", "") - So(err, ShouldNotBeNil) - - err = test.UploadImageWithBasicAuthRef(test.Image{}, "badURL", "", "", "", "") + err := test.UploadImageWithBasicAuth(test.Image{}, "badURL", "", "", "", "") So(err, ShouldNotBeNil) }) Convey("Request status is not StatusOk while pushing config", func() { - err := test.UploadImageWithBasicAuth(test.Image{}, baseURL, "", "repo", "") - So(err, ShouldNotBeNil) - - err = test.UploadImageWithBasicAuthRef(test.Image{}, baseURL, "", "repo", "", "") + err := test.UploadImageWithBasicAuth(test.Image{}, baseURL, "", "repo", "", "") So(err, ShouldNotBeNil) }) }) @@ -737,7 +723,7 @@ func TestUploadImage(t *testing.T) { Config: ispec.Image{}, } - err := test.UploadImage(img, baseURL, "test") + err := test.UploadImage(img, baseURL, "test", "") So(err, ShouldNotBeNil) }) @@ -768,14 +754,14 @@ func TestUploadImage(t *testing.T) { Convey("CreateBlobUpload", func() { injected := inject.InjectFailure(2) if injected { - err := test.UploadImage(img, baseURL, "test") + err := test.UploadImage(img, baseURL, "test", img.DigestStr()) So(err, ShouldNotBeNil) } }) Convey("UpdateBlobUpload", func() { injected := inject.InjectFailure(4) if injected { - err := test.UploadImage(img, baseURL, "test") + err := test.UploadImage(img, baseURL, "test", img.DigestStr()) So(err, ShouldNotBeNil) } }) @@ -829,40 +815,28 @@ func TestInjectUploadImage(t *testing.T) { Convey("first marshal", func() { injected := inject.InjectFailure(0) if injected { - err := test.UploadImage(img, baseURL, "test") - So(err, ShouldNotBeNil) - - err = test.UploadImageWithRef(img, baseURL, "test", img.DigestStr()) + err := test.UploadImage(img, baseURL, "test", img.DigestStr()) So(err, ShouldNotBeNil) } }) Convey("CreateBlobUpload POST call", func() { injected := inject.InjectFailure(1) if injected { - err := test.UploadImage(img, baseURL, "test") - So(err, ShouldNotBeNil) - - err = test.UploadImageWithRef(img, baseURL, "test", img.DigestStr()) + err := test.UploadImage(img, baseURL, "test", img.DigestStr()) So(err, ShouldNotBeNil) } }) Convey("UpdateBlobUpload PUT call", func() { injected := inject.InjectFailure(3) if injected { - err := test.UploadImage(img, baseURL, "test") - So(err, ShouldNotBeNil) - - err = test.UploadImageWithRef(img, baseURL, "test", img.DigestStr()) + err := test.UploadImage(img, baseURL, "test", img.DigestStr()) So(err, ShouldNotBeNil) } }) Convey("second marshal", func() { injected := inject.InjectFailure(5) if injected { - err := test.UploadImage(img, baseURL, "test") - So(err, ShouldNotBeNil) - - err = test.UploadImageWithRef(img, baseURL, "test", img.DigestStr()) + err := test.UploadImage(img, baseURL, "test", img.DigestStr()) So(err, ShouldNotBeNil) } }) @@ -970,28 +944,28 @@ func TestInjectUploadImageWithBasicAuth(t *testing.T) { Convey("first marshal", func() { injected := inject.InjectFailure(0) if injected { - err := test.UploadImageWithBasicAuth(img, baseURL, "test", "user", "password") + err := test.UploadImageWithBasicAuth(img, baseURL, "test", img.DigestStr(), "user", "password") So(err, ShouldNotBeNil) } }) Convey("CreateBlobUpload POST call", func() { injected := inject.InjectFailure(1) if injected { - err := test.UploadImageWithBasicAuth(img, baseURL, "test", "user", "password") + err := test.UploadImageWithBasicAuth(img, baseURL, "test", img.DigestStr(), "user", "password") So(err, ShouldNotBeNil) } }) Convey("UpdateBlobUpload PUT call", func() { injected := inject.InjectFailure(3) if injected { - err := test.UploadImageWithBasicAuth(img, baseURL, "test", "user", "password") + err := test.UploadImageWithBasicAuth(img, baseURL, "test", img.DigestStr(), "user", "password") So(err, ShouldNotBeNil) } }) Convey("second marshal", func() { injected := inject.InjectFailure(5) if injected { - err := test.UploadImageWithBasicAuth(img, baseURL, "test", "user", "password") + err := test.UploadImageWithBasicAuth(img, baseURL, "test", img.DigestStr(), "user", "password") So(err, ShouldNotBeNil) } }) @@ -1265,11 +1239,10 @@ func TestVerifyWithNotation(t *testing.T) { err = test.UploadImage( test.Image{ - Config: cfg, - Layers: layers, - Manifest: manifest, - Reference: tag, - }, baseURL, repoName) + Config: cfg, + Layers: layers, + Manifest: manifest, + }, baseURL, repoName, tag) So(err, ShouldBeNil) content, err := json.Marshal(manifest) @@ -1478,7 +1451,7 @@ func TestGenerateNotationCerts(t *testing.T) { func TestWriteImageToFileSystem(t *testing.T) { Convey("WriteImageToFileSystem errors", t, func() { - err := test.WriteImageToFileSystem(test.Image{}, "repo", storage.StoreController{ + err := test.WriteImageToFileSystem(test.Image{}, "repo", "dig", storage.StoreController{ DefaultStore: mocks.MockedImageStore{ InitRepoFn: func(name string) error { return ErrTestError @@ -1490,6 +1463,7 @@ func TestWriteImageToFileSystem(t *testing.T) { err = test.WriteImageToFileSystem( test.Image{Layers: [][]byte{[]byte("testLayer")}}, "repo", + "tag", storage.StoreController{ DefaultStore: mocks.MockedImageStore{ FullBlobUploadFn: func(repo string, body io.Reader, digest godigest.Digest, @@ -1504,6 +1478,7 @@ func TestWriteImageToFileSystem(t *testing.T) { err = test.WriteImageToFileSystem( test.Image{Layers: [][]byte{[]byte("testLayer")}}, "repo", + "tag", storage.StoreController{ DefaultStore: mocks.MockedImageStore{ FullBlobUploadFn: func(repo string, body io.Reader, digest godigest.Digest, @@ -1523,6 +1498,7 @@ func TestWriteImageToFileSystem(t *testing.T) { err = test.WriteImageToFileSystem( test.Image{Layers: [][]byte{[]byte("testLayer")}}, "repo", + "tag", storage.StoreController{ DefaultStore: mocks.MockedImageStore{ PutImageManifestFn: func(repo, reference, mediaType string, body []byte, diff --git a/pkg/test/images.go b/pkg/test/images.go index 61af54b2..871adc03 100644 --- a/pkg/test/images.go +++ b/pkg/test/images.go @@ -77,10 +77,9 @@ type ManifestBuilder interface { } type Image struct { - Manifest ispec.Manifest - Config ispec.Image - Layers [][]byte - Reference string + Manifest ispec.Manifest + Config ispec.Image + Layers [][]byte ConfigDescriptor ispec.Descriptor ManifestDescriptor ispec.Descriptor @@ -151,6 +150,7 @@ func CreateRandomImageWith() ManifestBuilder { return CreateImageWith().RandomLayers(layerCount, layerSize).RandomConfig() } +// CreateVulnerableImage creates a vulnerable image with the default config. func CreateVulnerableImage() Image { return CreateImageWith().VulnerableLayers().DefaultVulnConfig().Build() } @@ -433,8 +433,6 @@ func (ib *BaseImageBuilder) Build() Image { Data: manifestBlob, } - img.Reference = img.ManifestDescriptor.Digest.String() - return img } diff --git a/pkg/test/images_test.go b/pkg/test/images_test.go index c14aed44..15d22330 100644 --- a/pkg/test/images_test.go +++ b/pkg/test/images_test.go @@ -83,7 +83,6 @@ func TestImageBuilder(t *testing.T) { img := configBuilder.EmptyConfig().Build() So(img.Manifest.Config.Size, ShouldEqual, ispec.DescriptorEmptyJSON.Size) So(img.Manifest.Config.Digest, ShouldResemble, ispec.DescriptorEmptyJSON.Digest) - So(img.Reference, ShouldResemble, img.Digest().String()) }) }) diff --git a/pkg/test/oci-layout/oci_layout_test.go b/pkg/test/oci-layout/oci_layout_test.go index 472a2a19..227be7b2 100644 --- a/pkg/test/oci-layout/oci_layout_test.go +++ b/pkg/test/oci-layout/oci_layout_test.go @@ -307,7 +307,7 @@ func TestBaseOciLayoutUtils(t *testing.T) { defer ctlrManager.StopServer() // push test image to repo - config, layers, manifest, err := GetImageComponents(100) + config, layers, manifest, err := GetImageComponents(100) //nolint:staticcheck So(err, ShouldBeNil) layersSize1 := 0 @@ -319,13 +319,10 @@ func TestBaseOciLayoutUtils(t *testing.T) { tag := "1.0.1" err = UploadImage( Image{ - Manifest: manifest, - Config: config, - Layers: layers, - Reference: tag, - }, - baseURL, - repo, + Manifest: manifest, + Config: config, + Layers: layers, + }, baseURL, repo, tag, ) So(err, ShouldBeNil) @@ -357,16 +354,15 @@ func TestExtractImageDetails(t *testing.T) { } num := 10 - config, layers, manifest, err := GetImageComponents(num) + config, layers, manifest, err := GetImageComponents(num) //nolint:staticcheck So(err, ShouldBeNil) err = WriteImageToFileSystem( Image{ - Manifest: manifest, - Layers: layers, - Config: config, - Reference: "latest", - }, "zot-test", storeController, + Manifest: manifest, + Layers: layers, + Config: config, + }, "zot-test", "latest", storeController, ) So(err, ShouldBeNil) @@ -414,16 +410,15 @@ func TestExtractImageDetails(t *testing.T) { } num := 10 - config, layers, manifest, err := GetImageComponents(num) + config, layers, manifest, err := GetImageComponents(num) //nolint:staticcheck So(err, ShouldBeNil) err = WriteImageToFileSystem( Image{ - Manifest: manifest, - Layers: layers, - Config: config, - Reference: "latest", - }, "zot-test", storeController, + Manifest: manifest, + Layers: layers, + Config: config, + }, "zot-test", "latest", storeController, ) So(err, ShouldBeNil)