diff --git a/cmd/oras/repository/tags.go b/cmd/oras/repository/tags.go index 2f12b1d5e..c297d3897 100644 --- a/cmd/oras/repository/tags.go +++ b/cmd/oras/repository/tags.go @@ -69,6 +69,9 @@ func showTags(opts showTagsOptions) error { if err != nil { return err } + if repo.Reference.Reference != "" { + return fmt.Errorf("unexpected tag or digest %q found in repository reference %q", repo.Reference.Reference, opts.targetRef) + } return repo.Tags(ctx, opts.last, func(tags []string) error { for _, tag := range tags { if opts.excludeDigestTag && isDigestTag(tag) { diff --git a/test/e2e/suite/auth/auth.go b/test/e2e/suite/auth/auth.go index 2546fe02a..7de5f3d85 100644 --- a/test/e2e/suite/auth/auth.go +++ b/test/e2e/suite/auth/auth.go @@ -33,6 +33,8 @@ var _ = Describe("Common registry user", Ordered, func() { RunWithoutLogin("push", "-a", "key=value", Host+"/repo:tag") RunWithoutLogin("pull", Host+"/repo:tag") RunWithoutLogin("manifest", "fetch", Host+"/repo:tag") + RunWithoutLogin("repo", "ls", Host) + RunWithoutLogin("repo", "tags", Reference(Host, "repo", "")) RunWithoutLogin("manifest", "fetch-config", Host+"/repo:tag") }) }) diff --git a/test/e2e/suite/command/manifest.go b/test/e2e/suite/command/manifest.go index f4aba4c60..81e1afbcb 100644 --- a/test/e2e/suite/command/manifest.go +++ b/test/e2e/suite/command/manifest.go @@ -29,6 +29,7 @@ const ( foobarTag = "foobar" foobarConfigDescriptor = "{\"mediaType\":\"application/vnd.unknown.config.v1+json\",\"digest\":\"sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a\",\"size\":2}" multiImage = "multi" + foobarImageTag = "foobar" digest_multi = "sha256:e2bfc9cc6a84ec2d7365b5a28c6bc5806b7fa581c9ad7883be955a64e3cc034f" foobarDigest = "sha256:fd6ed2f36b5465244d5dc86cb4e7df0ab8a9d24adc57825099f522fe009a22bb" manifest_multi = `{"mediaType":"application/vnd.oci.image.index.v1+json","schemaVersion":2,"manifests":[{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:9d84a5716c66a1d1b9c13f8ed157ba7d1edfe7f9b8766728b8a1f25c0d9c14c1","size":458,"platform":{"architecture":"amd64","os":"linux"}},{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:4f93460061882467e6fb3b772dc6ab72130d9ac1906aed2fc7589a5cd145433c","size":458,"platform":{"architecture":"arm64","os":"linux"}},{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:58efe73e78fe043ca31b89007a025c594ce12aa7e6da27d21c7b14b50112e255","size":458,"platform":{"architecture":"arm","os":"linux","variant":"v7"}}]}` diff --git a/test/e2e/suite/command/repo.go b/test/e2e/suite/command/repo.go new file mode 100644 index 000000000..129496240 --- /dev/null +++ b/test/e2e/suite/command/repo.go @@ -0,0 +1,86 @@ +/* +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 command + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/onsi/gomega/gbytes" + . "oras.land/oras/test/e2e/internal/utils" +) + +var _ = Describe("ORAS beginners:", func() { + When("running repo command", func() { + runAndShowPreviewInHelp([]string{"repo"}) + When("running `repo ls`", func() { + It("should show preview in help", func() { + ORAS("repo", "ls", "--help").MatchKeyWords("[Preview] List", preview_desc, example_desc).Exec() + }) + + It("should call sub-commands with aliases", func() { + ORAS("repository", "list", "--help").MatchKeyWords("[Preview] List", preview_desc, example_desc).Exec() + }) + + It("should fail listing repositories if wrong registry provided", func() { + ORAS("repo", "ls").WithFailureCheck().MatchErrKeyWords("Error:").Exec() + ORAS("repo", "ls", Reference(Host, repo, "")).WithFailureCheck().MatchErrKeyWords("Error:").Exec() + ORAS("repo", "ls", Reference(Host, repo, "some-tag")).WithFailureCheck().MatchErrKeyWords("Error:").Exec() + }) + }) + When("running `repo tags`", func() { + It("should show preview in help", func() { + ORAS("repo", "tags", "--help").MatchKeyWords("[Preview] Show tags", preview_desc, example_desc).Exec() + }) + + It("should call sub-commands with aliases", func() { + ORAS("repository", "show-tags", "--help").MatchKeyWords("[Preview] Show tags", preview_desc, example_desc).Exec() + }) + + It("should fail listing repositories if wrong registry provided", func() { + ORAS("repo", "tags").WithFailureCheck().MatchErrKeyWords("Error:").Exec() + ORAS("repo", "tags", Host).WithFailureCheck().MatchErrKeyWords("Error:").Exec() + ORAS("repo", "tags", Reference(Host, repo, "some-tag")).WithFailureCheck().MatchErrKeyWords("Error:").Exec() + }) + }) + }) +}) + +var _ = Describe("Common registry users:", func() { + When("running `repo ls`", func() { + It("should list repositories", func() { + ORAS("repository", "list", Host).MatchKeyWords(repo).Exec() + }) + It("should list repositories via short command", func() { + ORAS("repo", "ls", Host).MatchKeyWords(repo).Exec() + }) + It("should list partial repositories via `last` flag", func() { + session := ORAS("repo", "ls", Host, "--last", repo).Exec() + Expect(session.Out).ShouldNot(gbytes.Say(repo)) + }) + }) + When("running `repo tags`", func() { + repoRef := Reference(Host, repo, "") + It("should list tags", func() { + ORAS("repository", "show-tags", repoRef).MatchKeyWords(multiImage, foobarImageTag).Exec() + }) + It("should list tags via short command", func() { + ORAS("repo", "tags", repoRef).MatchKeyWords(multiImage, foobarImageTag).Exec() + + }) + It("should list partial tags via `last` flag", func() { + session := ORAS("repo", "tags", repoRef, "--last", foobarImageTag).MatchKeyWords(multiImage).Exec() + Expect(session.Out).ShouldNot(gbytes.Say(foobarImageTag)) + }) + }) +})