From 9ecf303eeb2620dfe3ddf15721999d1f7e8fd4bf Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Wed, 22 Nov 2023 08:04:48 +0000 Subject: [PATCH] test(e2e): add test for `resolve` command (#1188) Signed-off-by: Billy Zha --- cmd/oras/root/resolve.go | 6 ++--- test/e2e/suite/auth/auth.go | 1 + test/e2e/suite/command/resolve.go | 37 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 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..7852c7873 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") 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..f3ae46c2b 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()) @@ -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 := 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 := PrepareTempOCI(ImageRepo) + 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() { + 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", tmpRoot, multi_arch.LinuxAMD64.Digest))) + }) + }) +})