Skip to content

Commit

Permalink
test(e2e): add test for resolve command (#1188)
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
  • Loading branch information
qweeah authored Nov 22, 2023
1 parent 01e9cdd commit 9ecf303
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/oras/root/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type resolveOptions struct {
option.Platform
option.Target

FullRef bool
fullRef bool
}

func resolveCmd() *cobra.Command {
Expand All @@ -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
}
Expand All @@ -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())
Expand Down
1 change: 1 addition & 0 deletions test/e2e/suite/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
37 changes: 37 additions & 0 deletions test/e2e/suite/command/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand All @@ -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())
Expand All @@ -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)))
})
})
})

0 comments on commit 9ecf303

Please sign in to comment.