From 4f200763f02c5635ce93052b3f4d6abaa19af0b7 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Thu, 16 Nov 2023 08:29:22 +0000 Subject: [PATCH 1/5] test(e2e): add test for `resolve` command Signed-off-by: Billy Zha --- cmd/oras/root/resolve.go | 6 ++--- test/e2e/suite/auth/auth.go | 1 + test/e2e/suite/command/resolve.go | 39 ++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/cmd/oras/root/resolve.go b/cmd/oras/root/resolve.go index 022fa8b20..b98e67144 100644 --- a/cmd/oras/root/resolve.go +++ b/cmd/oras/root/resolve.go @@ -29,7 +29,7 @@ type resolveOptions struct { option.Platform option.Target - FullRef bool + fullRef bool } func resolveCmd() *cobra.Command { @@ -54,7 +54,7 @@ Example - Resolve digest of the target artifact: }, } - cmd.Flags().BoolVarP(&opts.FullRef, "full-reference", "l", false, "print the full artifact reference with digest") + cmd.Flags().BoolVarP(&opts.fullRef, "full-reference", "l", false, "print the full artifact reference with digest") option.ApplyFlags(&opts, cmd.Flags()) return cmd } @@ -76,7 +76,7 @@ func runResolve(ctx context.Context, opts resolveOptions) error { return fmt.Errorf("failed to resolve digest: %w", err) } - if opts.FullRef { + if opts.fullRef { fmt.Printf("%s@%s\n", opts.Path, desc.Digest) } else { fmt.Println(desc.Digest.String()) diff --git a/test/e2e/suite/auth/auth.go b/test/e2e/suite/auth/auth.go index e664e6cbc..63685124b 100644 --- a/test/e2e/suite/auth/auth.go +++ b/test/e2e/suite/auth/auth.go @@ -43,6 +43,7 @@ var _ = Describe("Common registry user", Ordered, func() { RunWithoutLogin("blob", "delete", ZOTHost+"/repo@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") RunWithoutLogin("blob", "push", ZOTHost+"/repo", WriteTempFile("blob", "test")) RunWithoutLogin("tag", ZOTHost+"/repo:tag", "tag1") + RunWithoutLogin("resolve", ZOTHost+"/repo:tag", "tag1") RunWithoutLogin("repo", "ls", ZOTHost) RunWithoutLogin("repo", "tags", RegistryRef(ZOTHost, "repo", "")) RunWithoutLogin("manifest", "fetch-config", ZOTHost+"/repo:tag") diff --git a/test/e2e/suite/command/resolve.go b/test/e2e/suite/command/resolve.go index fb46d798c..04ee75e11 100644 --- a/test/e2e/suite/command/resolve.go +++ b/test/e2e/suite/command/resolve.go @@ -22,12 +22,21 @@ import ( . "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" + "oras.land/oras/test/e2e/internal/testdata/feature" "oras.land/oras/test/e2e/internal/testdata/multi_arch" . "oras.land/oras/test/e2e/internal/utils" ) var _ = Describe("ORAS beginners:", func() { When("running resolve command", func() { + It("should show help description with feature mark", func() { + out := ORAS("resolve", "--help").MatchKeyWords(ExampleDesc).Exec().Out + gomega.Expect(out.Contents()).Should(gomega.HavePrefix(feature.Experimental.Mark)) + }) + It("should show help description via alias", func() { + out := ORAS("digest", "--help").MatchKeyWords(ExampleDesc).Exec().Out + gomega.Expect(out.Contents()).Should(gomega.HavePrefix(feature.Experimental.Mark)) + }) It("should fail when no manifest reference provided", func() { ORAS("resolve").ExpectFailure().MatchErrKeyWords("Error:").Exec() }) @@ -40,6 +49,12 @@ var _ = Describe("ORAS beginners:", func() { It("should fail when provided manifest reference is not found", func() { ORAS("resolve", RegistryRef(ZOTHost, ImageRepo, "i-dont-think-this-tag-exists")).ExpectFailure().MatchErrKeyWords("Error: failed to resolve digest:", "not found").Exec() }) + + }) +}) + +var _ = Describe("Common registry user", func() { + When("running resolve command", func() { It("should resolve with just digest", func() { out := ORAS("resolve", RegistryRef(ZOTHost, ImageRepo, multi_arch.Digest)).Exec().Out outString := string(out.Contents()) @@ -47,7 +62,7 @@ var _ = Describe("ORAS beginners:", func() { gomega.Expect(outString).To(gomega.Equal(multi_arch.Digest)) }) It("should resolve with a fully qualified reference", func() { - out := ORAS("digest", "-l", RegistryRef(ZOTHost, ImageRepo, multi_arch.Tag)).Exec().Out + out := ORAS("resolve", "-l", RegistryRef(ZOTHost, ImageRepo, multi_arch.Tag)).Exec().Out gomega.Expect(out).To(gbytes.Say(fmt.Sprintf("%s/%s@%s", ZOTHost, ImageRepo, multi_arch.Digest))) }) It("should resolve with a fully qualified reference for a platform", func() { @@ -56,3 +71,25 @@ var _ = Describe("ORAS beginners:", func() { }) }) }) + +var _ = Describe("OCI image layout users", func() { + When("running resolve command", func() { + It("should resolve with just digest", func() { + tmpRoot := GinkgoT().TempDir() + out := ORAS("resolve", LayoutRef(tmpRoot, multi_arch.Digest)).Exec().Out + outString := string(out.Contents()) + outString = strings.TrimSpace(outString) + gomega.Expect(outString).To(gomega.Equal(multi_arch.Digest)) + }) + It("should resolve with a fully qualified reference", func() { + tmpRoot := GinkgoT().TempDir() + out := ORAS("resolve", "-l", LayoutRef(tmpRoot, multi_arch.Tag)).Exec().Out + gomega.Expect(out).To(gbytes.Say(fmt.Sprintf("%s@%s", tmpRoot, multi_arch.Digest))) + }) + It("should resolve with a fully qualified reference for a platform", func() { + tmpRoot := GinkgoT().TempDir() + out := ORAS("resolve", "--full-reference", "--platform", "linux/amd64", LayoutRef(tmpRoot, multi_arch.Tag)).Exec().Out + gomega.Expect(out).To(gbytes.Say(fmt.Sprintf("%s/%s@%s", ZOTHost, ImageRepo, multi_arch.LinuxAMD64.Digest))) + }) + }) +}) From a96eb638274f213e9dd334cf05123cc6bb0e7a59 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Thu, 16 Nov 2023 08:57:49 +0000 Subject: [PATCH 2/5] fix: e2e Signed-off-by: Billy Zha --- test/e2e/suite/auth/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/suite/auth/auth.go b/test/e2e/suite/auth/auth.go index 63685124b..7852c7873 100644 --- a/test/e2e/suite/auth/auth.go +++ b/test/e2e/suite/auth/auth.go @@ -43,7 +43,7 @@ var _ = Describe("Common registry user", Ordered, func() { RunWithoutLogin("blob", "delete", ZOTHost+"/repo@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") RunWithoutLogin("blob", "push", ZOTHost+"/repo", WriteTempFile("blob", "test")) RunWithoutLogin("tag", ZOTHost+"/repo:tag", "tag1") - RunWithoutLogin("resolve", ZOTHost+"/repo:tag", "tag1") + RunWithoutLogin("resolve", ZOTHost+"/repo:tag") RunWithoutLogin("repo", "ls", ZOTHost) RunWithoutLogin("repo", "tags", RegistryRef(ZOTHost, "repo", "")) RunWithoutLogin("manifest", "fetch-config", ZOTHost+"/repo:tag") From dd164e17225f0ed9fad7db2b274171618db41b04 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Thu, 16 Nov 2023 09:20:42 +0000 Subject: [PATCH 3/5] add layout flag Signed-off-by: Billy Zha --- test/e2e/suite/command/resolve.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/suite/command/resolve.go b/test/e2e/suite/command/resolve.go index 04ee75e11..b1701a736 100644 --- a/test/e2e/suite/command/resolve.go +++ b/test/e2e/suite/command/resolve.go @@ -76,19 +76,19 @@ var _ = Describe("OCI image layout users", func() { When("running resolve command", func() { It("should resolve with just digest", func() { tmpRoot := GinkgoT().TempDir() - out := ORAS("resolve", LayoutRef(tmpRoot, multi_arch.Digest)).Exec().Out + out := ORAS("resolve", Flags.Layout, LayoutRef(tmpRoot, multi_arch.Digest)).Exec().Out outString := string(out.Contents()) outString = strings.TrimSpace(outString) gomega.Expect(outString).To(gomega.Equal(multi_arch.Digest)) }) It("should resolve with a fully qualified reference", func() { tmpRoot := GinkgoT().TempDir() - out := ORAS("resolve", "-l", LayoutRef(tmpRoot, multi_arch.Tag)).Exec().Out + out := ORAS("resolve", Flags.Layout, "-l", LayoutRef(tmpRoot, multi_arch.Tag)).Exec().Out gomega.Expect(out).To(gbytes.Say(fmt.Sprintf("%s@%s", tmpRoot, multi_arch.Digest))) }) It("should resolve with a fully qualified reference for a platform", func() { tmpRoot := GinkgoT().TempDir() - out := ORAS("resolve", "--full-reference", "--platform", "linux/amd64", LayoutRef(tmpRoot, multi_arch.Tag)).Exec().Out + out := ORAS("resolve", Flags.Layout, "--full-reference", "--platform", "linux/amd64", LayoutRef(tmpRoot, multi_arch.Tag)).Exec().Out gomega.Expect(out).To(gbytes.Say(fmt.Sprintf("%s/%s@%s", ZOTHost, ImageRepo, multi_arch.LinuxAMD64.Digest))) }) }) From 47e827d6a4a91f40b9c0a83cf2db6e9bd46b1666 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Thu, 16 Nov 2023 10:24:20 +0000 Subject: [PATCH 4/5] fix e2e Signed-off-by: Billy Zha --- test/e2e/suite/command/resolve.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/suite/command/resolve.go b/test/e2e/suite/command/resolve.go index b1701a736..ae76e7f9d 100644 --- a/test/e2e/suite/command/resolve.go +++ b/test/e2e/suite/command/resolve.go @@ -75,21 +75,21 @@ var _ = Describe("Common registry user", func() { var _ = Describe("OCI image layout users", func() { When("running resolve command", func() { It("should resolve with just digest", func() { - tmpRoot := GinkgoT().TempDir() + tmpRoot := PrepareTempOCI(ImageRepo) out := ORAS("resolve", Flags.Layout, LayoutRef(tmpRoot, multi_arch.Digest)).Exec().Out outString := string(out.Contents()) outString = strings.TrimSpace(outString) gomega.Expect(outString).To(gomega.Equal(multi_arch.Digest)) }) It("should resolve with a fully qualified reference", func() { - tmpRoot := GinkgoT().TempDir() + tmpRoot := PrepareTempOCI(ImageRepo) out := ORAS("resolve", Flags.Layout, "-l", LayoutRef(tmpRoot, multi_arch.Tag)).Exec().Out gomega.Expect(out).To(gbytes.Say(fmt.Sprintf("%s@%s", tmpRoot, multi_arch.Digest))) }) It("should resolve with a fully qualified reference for a platform", func() { - tmpRoot := GinkgoT().TempDir() + tmpRoot := PrepareTempOCI(ImageRepo) out := ORAS("resolve", Flags.Layout, "--full-reference", "--platform", "linux/amd64", LayoutRef(tmpRoot, multi_arch.Tag)).Exec().Out - gomega.Expect(out).To(gbytes.Say(fmt.Sprintf("%s/%s@%s", ZOTHost, ImageRepo, multi_arch.LinuxAMD64.Digest))) + gomega.Expect(out).To(gbytes.Say(fmt.Sprintf("%s@%s", tmpRoot, multi_arch.LinuxAMD64.Digest))) }) }) }) From e362ead9126ffcffc223535df0aa83f007f2c55d Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Wed, 22 Nov 2023 07:12:28 +0000 Subject: [PATCH 5/5] test alias Signed-off-by: Billy Zha --- test/e2e/suite/command/resolve.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/suite/command/resolve.go b/test/e2e/suite/command/resolve.go index ae76e7f9d..f3ae46c2b 100644 --- a/test/e2e/suite/command/resolve.go +++ b/test/e2e/suite/command/resolve.go @@ -62,7 +62,7 @@ var _ = Describe("Common registry user", func() { gomega.Expect(outString).To(gomega.Equal(multi_arch.Digest)) }) It("should resolve with a fully qualified reference", func() { - out := ORAS("resolve", "-l", RegistryRef(ZOTHost, ImageRepo, multi_arch.Tag)).Exec().Out + out := ORAS("digest", "-l", RegistryRef(ZOTHost, ImageRepo, multi_arch.Tag)).Exec().Out gomega.Expect(out).To(gbytes.Say(fmt.Sprintf("%s/%s@%s", ZOTHost, ImageRepo, multi_arch.Digest))) }) It("should resolve with a fully qualified reference for a platform", func() { @@ -83,7 +83,7 @@ var _ = Describe("OCI image layout users", func() { }) It("should resolve with a fully qualified reference", func() { tmpRoot := PrepareTempOCI(ImageRepo) - out := ORAS("resolve", Flags.Layout, "-l", LayoutRef(tmpRoot, multi_arch.Tag)).Exec().Out + out := ORAS("digest", Flags.Layout, "-l", LayoutRef(tmpRoot, multi_arch.Tag)).Exec().Out gomega.Expect(out).To(gbytes.Say(fmt.Sprintf("%s@%s", tmpRoot, multi_arch.Digest))) }) It("should resolve with a fully qualified reference for a platform", func() {