Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): add test for resolve command #1188

Merged
merged 5 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
39 changes: 38 additions & 1 deletion 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,14 +49,20 @@ 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())
outString = strings.TrimSpace(outString)
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
qweeah marked this conversation as resolved.
Show resolved Hide resolved
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() {
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
qweeah marked this conversation as resolved.
Show resolved Hide resolved
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("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 := 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)))
})
})
})
Loading