From 0bb8f668c1b63c789c5aa7df8fd2bbdee048b332 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Fri, 1 Sep 2023 06:38:47 +0000 Subject: [PATCH] add cp test Signed-off-by: Billy Zha --- .../internal/testdata/artifact/index/const.go | 26 +++++++++++++++++++ .../e2e/internal/testdata/multi_arch/const.go | 1 + test/e2e/suite/command/cp.go | 18 +++++++++---- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 test/e2e/internal/testdata/artifact/index/const.go diff --git a/test/e2e/internal/testdata/artifact/index/const.go b/test/e2e/internal/testdata/artifact/index/const.go new file mode 100644 index 000000000..5fdb41ed0 --- /dev/null +++ b/test/e2e/internal/testdata/artifact/index/const.go @@ -0,0 +1,26 @@ +/* +Copyright The ORAS Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package index + +import "oras.land/oras/test/e2e/internal/utils/match" + +var ( + ManifestDigest = "sha256:7679bc22c33b87aa345c6950a993db98a6df7a6cc77a35c388908a3a50be6bad" + ManifestStatusKey = match.StateKey{ + Digest: "7679bc22c33b", + Name: "application/vnd.oci.image.index.v1+json", + } +) diff --git a/test/e2e/internal/testdata/multi_arch/const.go b/test/e2e/internal/testdata/multi_arch/const.go index 94cd9ef59..119764386 100644 --- a/test/e2e/internal/testdata/multi_arch/const.go +++ b/test/e2e/internal/testdata/multi_arch/const.go @@ -34,6 +34,7 @@ var ( {Digest: "2ef548696ac7", Name: "hello.tar"}, {Digest: "fe9dbc99451d", Name: "application/vnd.oci.image.config.v1+json"}, {Digest: "9d84a5716c66", Name: "application/vnd.oci.image.manifest.v1+json"}, + {Digest: "e2bfc9cc6a84", Name: "application/vnd.oci.image.index.v1+json"}, } // below are newly baked artifacts for ZOT IndexZOTReferrerStateKey = match.StateKey{Digest: "d37baf66300b", Name: "application/vnd.oci.image.manifest.v1+json"} diff --git a/test/e2e/suite/command/cp.go b/test/e2e/suite/command/cp.go index 28e9a9891..317d0f989 100644 --- a/test/e2e/suite/command/cp.go +++ b/test/e2e/suite/command/cp.go @@ -29,6 +29,7 @@ import ( "oras.land/oras-go/v2" "oras.land/oras/test/e2e/internal/testdata/artifact/blob" "oras.land/oras/test/e2e/internal/testdata/artifact/config" + "oras.land/oras/test/e2e/internal/testdata/artifact/index" "oras.land/oras/test/e2e/internal/testdata/feature" "oras.land/oras/test/e2e/internal/testdata/foobar" ma "oras.land/oras/test/e2e/internal/testdata/multi_arch" @@ -85,6 +86,13 @@ var _ = Describe("1.1 registry users:", func() { ORAS("cp", src, dst, "-v").MatchStatus(config.StateKeys, true, len(config.StateKeys)).Exec() }) + It("should copy index and its subject", func() { + stateKeys := append(ma.IndexStateKeys, index.ManifestStatusKey) + src := RegistryRef(ZOTHost, ArtifactRepo, index.ManifestDigest) + dst := RegistryRef(ZOTHost, cpTestRepo("index-with-subject"), "") + ORAS("cp", src, dst, "-v").MatchStatus(stateKeys, true, len(stateKeys)).Exec() + }) + It("should copy an image to a new repository via tag", func() { src := RegistryRef(ZOTHost, ImageRepo, foobar.Tag) dst := RegistryRef(ZOTHost, cpTestRepo("tag"), "copied") @@ -126,7 +134,7 @@ var _ = Describe("1.1 registry users:", func() { // validate CompareRef(RegistryRef(ZOTHost, ImageRepo, ma.Digest), dst) var index ocispec.Index - bytes := ORAS("discover", dst, "-o", "json"). + bytes := ORAS("discover", dst, "-o", "json", "--artifact-type", ma.IndexReferrerConfigStateKey.Name). MatchKeyWords(ma.IndexReferrerDigest). WithDescription("copy image referrer"). Exec().Out.Contents() @@ -151,7 +159,7 @@ var _ = Describe("1.1 registry users:", func() { // validate CompareRef(RegistryRef(ZOTHost, ImageRepo, ma.Digest), dst) var index ocispec.Index - bytes := ORAS("discover", dst, "-o", "json"). + bytes := ORAS("discover", dst, "-o", "json", "--artifact-type", ma.IndexReferrerConfigStateKey.Name). MatchKeyWords(ma.IndexReferrerDigest). WithDescription("copy image referrer"). Exec().Out.Contents() @@ -469,8 +477,8 @@ var _ = Describe("OCI layout users:", func() { dstManifest := ORAS("manifest", "fetch", dst, Flags.Layout).WithDescription("fetch from destination to validate").Exec().Out.Contents() Expect(srcManifest).To(Equal(dstManifest)) var index ocispec.Index - bytes := ORAS("discover", dst, "-o", "json", Flags.Layout). - MatchKeyWords(ma.IndexReferrerDigest). + bytes := ORAS("discover", dst, "-o", "json", Flags.Layout, "--artifact-type", ma.IndexReferrerConfigStateKey.Name). + // MatchKeyWords(ma.IndexReferrerDigest). WithDescription("copy image referrer"). Exec().Out.Contents() Expect(json.Unmarshal(bytes, &index)).ShouldNot(HaveOccurred()) @@ -499,7 +507,7 @@ var _ = Describe("OCI layout users:", func() { dstManifest := ORAS("manifest", "fetch", dst).WithDescription("fetch from destination to validate").Exec().Out.Contents() Expect(srcManifest).To(Equal(dstManifest)) var index ocispec.Index - bytes := ORAS("discover", dst, "-o", "json"). + bytes := ORAS("discover", dst, "-o", "json", "--artifact-type", ma.IndexReferrerConfigStateKey.Name). MatchKeyWords(ma.IndexReferrerDigest). WithDescription("copy image referrer"). Exec().Out.Contents()