Skip to content

Commit

Permalink
test: add E2E specs covering repo subcommand (#716)
Browse files Browse the repository at this point in the history
Resolves #714

Signed-off-by: Billy Zha <jinzha1@microsoft.com>
  • Loading branch information
qweeah committed Dec 15, 2022
1 parent 561c3c2 commit 0a396e5
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/oras/repository/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/suite/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
Expand Down
1 change: 1 addition & 0 deletions test/e2e/suite/command/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}]}`
Expand Down
86 changes: 86 additions & 0 deletions test/e2e/suite/command/repo.go
Original file line number Diff line number Diff line change
@@ -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))
})
})
})

0 comments on commit 0a396e5

Please sign in to comment.