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: add E2E specs for manifest push #702

Merged
merged 30 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f03e1b1
test: add utility for file matching
qweeah Nov 22, 2022
b78daa5
code clean & add timeout
qweeah Nov 22, 2022
d6c36f4
use file utility
qweeah Nov 22, 2022
c73b59d
bug fix
qweeah Nov 23, 2022
64a7be5
fix bug
qweeah Nov 23, 2022
b59435c
code clean
qweeah Nov 23, 2022
d9b88c3
code clean
qweeah Nov 23, 2022
ddd67aa
test: add E2E specs for `oras manifest push`
qweeah Nov 23, 2022
a6451b6
code clean
qweeah Nov 23, 2022
def4262
remove focusing
qweeah Nov 23, 2022
b256c87
test: add spec to cover `blob push`
qweeah Nov 28, 2022
de13159
fixing unauthed
qweeah Nov 28, 2022
e286146
add temp file
qweeah Nov 28, 2022
4350da5
align style
qweeah Dec 1, 2022
344deca
Merge remote-tracking branch 'origin_src/main' into e2e-manifest-push
qweeah Dec 14, 2022
bd14b06
Merge remote-tracking branch 'origin_src/main' into e2e-manifest-push
qweeah Dec 14, 2022
2588293
Merge remote-tracking branch 'origin_src/main' into e2e-blob-push
qweeah Dec 14, 2022
c5db403
Merge remote-tracking branch 'origin_src/main' into e2e-manifest-push
qweeah Dec 15, 2022
2dd2193
Merge remote-tracking branch 'origin_src/main' into e2e-blob-push
qweeah Dec 15, 2022
02aed52
fix merge error
qweeah Dec 15, 2022
545244f
update blob fetch with file utils
qweeah Dec 15, 2022
153f873
code clean
qweeah Dec 15, 2022
0744ec5
code clean
qweeah Dec 15, 2022
ccf063c
Merge branch 'e2e-blob-push' into e2e-manifest-push
qweeah Dec 15, 2022
b395862
add test utils
qweeah Dec 15, 2022
6563568
update test
qweeah Dec 15, 2022
4e0c549
Merge remote-tracking branch 'origin_src/main' into e2e-manifest-push
qweeah Dec 15, 2022
2859683
rename file
qweeah Dec 15, 2022
7ed08fa
add test data constants
qweeah Dec 15, 2022
0e421c9
code clean
qweeah Dec 15, 2022
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
30 changes: 30 additions & 0 deletions test/e2e/internal/utils/preview.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
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 utils

import (
"fmt"
"strings"

. "github.com/onsi/ginkgo/v2"
)

func RunAndShowPreviewInHelp(args []string, keywords ...string) {
It(fmt.Sprintf("should run %q command", strings.Join(args, " ")), func() {
ORAS(append(args, "--help")...).
MatchKeyWords(append(keywords, "[Preview] "+args[len(args)-1], "\nUsage:")...).
WithDescription("show preview and help doc").
Exec()
})
}
33 changes: 33 additions & 0 deletions test/e2e/internal/utils/testdata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
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 utils

const (
PreviewDesc = "** This command is in preview and under development. **"
ExampleDesc = "\nExample - "
Repo = "command/images"
FoobarImageTag = "foobar"
FoobarConfigDesc = "{\"mediaType\":\"application/vnd.unknown.config.v1+json\",\"digest\":\"sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a\",\"size\":2}"
MultiImageTag = "multi"
MultiImageDigest = "sha256:e2bfc9cc6a84ec2d7365b5a28c6bc5806b7fa581c9ad7883be955a64e3cc034f"
FoobarImageDigest = "sha256:fd6ed2f36b5465244d5dc86cb4e7df0ab8a9d24adc57825099f522fe009a22bb"
MultiImageManifest = `{"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"}}]}`
MultiImageDescriptor = `{"mediaType":"application/vnd.oci.image.index.v1+json","digest":"sha256:e2bfc9cc6a84ec2d7365b5a28c6bc5806b7fa581c9ad7883be955a64e3cc034f","size":706}`
LinuxAMD64ImageManifest = `{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","config":{"mediaType":"application/vnd.oci.image.config.v1+json","digest":"sha256:fe9dbc99451d0517d65e048c309f0b5afb2cc513b7a3d456b6cc29fe641386c5","size":53},"layers":[{"mediaType":"application/vnd.oci.image.layer.v1.tar","digest":"sha256:2ef548696ac7dd66ef38aab5cc8fc5cc1fb637dfaedb3a9afc89bf16db9277e1","size":10240,"annotations":{"org.opencontainers.image.title":"hello.tar"}}]}`
LinuxAMD64ImageDescriptor = `{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:9d84a5716c66a1d1b9c13f8ed157ba7d1edfe7f9b8766728b8a1f25c0d9c14c1","size":458}`
LinuxAMD64ImageIndexDescriptor = `{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:9d84a5716c66a1d1b9c13f8ed157ba7d1edfe7f9b8766728b8a1f25c0d9c14c1","size":458,"platform":{"architecture":"amd64","os":"linux"}}`
LinuxAMD64ImageDigest = "sha256:9d84a5716c66a1d1b9c13f8ed157ba7d1edfe7f9b8766728b8a1f25c0d9c14c1"
LinuxAMD64ImageConfig = "{\r\n \"architecture\": \"amd64\",\r\n \"os\": \"linux\"\r\n}"
LinuxAMD64ImageConfigDescriptor = `{"mediaType":"application/vnd.oci.image.config.v1+json","digest":"sha256:fe9dbc99451d0517d65e048c309f0b5afb2cc513b7a3d456b6cc29fe641386c5","size":53}`
)
22 changes: 11 additions & 11 deletions test/e2e/suite/command/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = Describe("ORAS beginners:", func() {
RunAndShowPreviewInHelp([]string{"blob"})

When("running `blob push`", func() {
RunAndShowPreviewInHelp([]string{"blob", "push"}, preview_desc, example_desc)
RunAndShowPreviewInHelp([]string{"blob", "push"}, PreviewDesc, ExampleDesc)
It("should fail to read blob content and password from stdin at the same time", func() {
repo := fmt.Sprintf(repoFmt, "password-stdin")
ORAS("blob", "push", Reference(Host, repo, ""), "--password-stdin", "-").
Expand Down Expand Up @@ -87,11 +87,11 @@ var _ = Describe("ORAS beginners:", func() {
})

When("running `blob fetch`", func() {
RunAndShowPreviewInHelp([]string{"blob", "fetch"}, preview_desc, example_desc)
RunAndShowPreviewInHelp([]string{"blob", "fetch"}, PreviewDesc, ExampleDesc)

It("should call sub-commands with aliases", func() {
ORAS("blob", "get", "--help").
MatchKeyWords("[Preview] Fetch", preview_desc, example_desc).
MatchKeyWords("[Preview] Fetch", PreviewDesc, ExampleDesc).
Exec()
})
It("should have flag for prettifying JSON output", func() {
Expand All @@ -101,22 +101,22 @@ var _ = Describe("ORAS beginners:", func() {
})

It("should fail if neither output path nor descriptor flag are not provided", func() {
ORAS("blob", "fetch", Reference(Host, repo, "sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae")).
ORAS("blob", "fetch", Reference(Host, Repo, "sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae")).
WithFailureCheck().Exec()
})

It("should fail if no digest provided", func() {
ORAS("blob", "fetch", Reference(Host, repo, "")).
ORAS("blob", "fetch", Reference(Host, Repo, "")).
WithFailureCheck().Exec()
})

It("should fail if provided digest doesn't existed", func() {
ORAS("blob", "fetch", Reference(Host, repo, "sha256:2aaa2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a")).
ORAS("blob", "fetch", Reference(Host, Repo, "sha256:2aaa2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a")).
WithFailureCheck().Exec()
})

It("should fail if output path points to stdout and descriptor flag is provided", func() {
ORAS("blob", "fetch", Reference(Host, repo, ""), "--descriptor", "--output", "-").
ORAS("blob", "fetch", Reference(Host, Repo, ""), "--descriptor", "--output", "-").
WithFailureCheck().Exec()
})

Expand Down Expand Up @@ -159,24 +159,24 @@ var _ = Describe("Common registry users:", func() {
var blobDescriptor = `{"mediaType":"application/octet-stream","digest":"sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae","size":3}`
When("running `blob fetch`", func() {
It("should fetch blob descriptor ", func() {
ORAS("blob", "fetch", Reference(Host, repo, blobDigest), "--descriptor").
ORAS("blob", "fetch", Reference(Host, Repo, blobDigest), "--descriptor").
MatchContent(blobDescriptor).Exec()
})
It("should fetch blob content and output to stdout", func() {
ORAS("blob", "fetch", Reference(Host, repo, blobDigest), "--output", "-").
ORAS("blob", "fetch", Reference(Host, Repo, blobDigest), "--output", "-").
MatchContent(blobContent).Exec()
})
It("should fetch blob content and output to a file", func() {
tempDir := GinkgoT().TempDir()
contentPath := filepath.Join(tempDir, "fetched")
ORAS("blob", "fetch", Reference(Host, repo, blobDigest), "--output", contentPath).
ORAS("blob", "fetch", Reference(Host, Repo, blobDigest), "--output", contentPath).
WithWorkDir(tempDir).Exec()
MatchFile(contentPath, blobContent, DefaultTimeout)
})
It("should fetch blob descriptor and output content to a file", func() {
tempDir := GinkgoT().TempDir()
contentPath := filepath.Join(tempDir, "fetched")
ORAS("blob", "fetch", Reference(Host, repo, blobDigest), "--output", contentPath, "--descriptor").
ORAS("blob", "fetch", Reference(Host, Repo, blobDigest), "--output", contentPath, "--descriptor").
MatchContent(blobDescriptor).
WithWorkDir(tempDir).Exec()
MatchFile(contentPath, blobContent, DefaultTimeout)
Expand Down
Loading