From adb16ec42ff9741f8cf4cd01f47920b03691b8fa Mon Sep 17 00:00:00 2001 From: "Lixia (Sylvia) Lei" Date: Thu, 5 Dec 2024 17:18:15 +0800 Subject: [PATCH] fix tests Signed-off-by: Lixia (Sylvia) Lei --- test/e2e/internal/testdata/feature/feature.go | 2 ++ test/e2e/internal/utils/deprecation.go | 18 ------------------ test/e2e/internal/utils/match/status.go | 1 + test/e2e/suite/command/attach.go | 14 +++++++++----- test/e2e/suite/command/blob.go | 8 ++++---- test/e2e/suite/command/cp.go | 13 ++++++++----- test/e2e/suite/command/discover.go | 2 +- test/e2e/suite/command/manifest.go | 17 ++++++++++------- test/e2e/suite/command/pull.go | 11 +++++++---- test/e2e/suite/command/push.go | 11 +++++++---- 10 files changed, 49 insertions(+), 48 deletions(-) delete mode 100644 test/e2e/internal/utils/deprecation.go diff --git a/test/e2e/internal/testdata/feature/feature.go b/test/e2e/internal/testdata/feature/feature.go index 3bb065346..90d7426d1 100644 --- a/test/e2e/internal/testdata/feature/feature.go +++ b/test/e2e/internal/testdata/feature/feature.go @@ -15,6 +15,8 @@ limitations under the License. package feature +const DeprecationMessageVerboseFlag = "Flag --verbose has been deprecated, and will be removed in a future release." + var ( Preview = struct { Mark string diff --git a/test/e2e/internal/utils/deprecation.go b/test/e2e/internal/utils/deprecation.go deleted file mode 100644 index 7ef667ba0..000000000 --- a/test/e2e/internal/utils/deprecation.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -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 DeprecationMessageVerboseFlag = "Flag --verbose has been deprecated, and will be removed in a future release." diff --git a/test/e2e/internal/utils/match/status.go b/test/e2e/internal/utils/match/status.go index 662a5ba6a..f95d37661 100644 --- a/test/e2e/internal/utils/match/status.go +++ b/test/e2e/internal/utils/match/status.go @@ -78,6 +78,7 @@ func newStateMachine(cmd string) *stateMachine { sm.addPath("Exists") sm.addPath("Mounted") case "manifest", "blob": // for `manifest push` and `blob push` + // TODO: refactor the matcher to match the complete arguments like `manifest push`, `manifest delete`, ... sm.addPath("Uploading", "Uploaded") sm.addPath("Exists") default: diff --git a/test/e2e/suite/command/attach.go b/test/e2e/suite/command/attach.go index 5b8797410..509615919 100644 --- a/test/e2e/suite/command/attach.go +++ b/test/e2e/suite/command/attach.go @@ -41,11 +41,15 @@ var _ = Describe("ORAS beginners:", func() { RunAndShowPreviewInHelp([]string{"attach"}) It("should show preview and help doc", func() { - out := ORAS("attach", "--help").MatchKeyWords(feature.Preview.Mark+" Attach", feature.Preview.Description, ExampleDesc).Exec() - // verbose flag should be hidden in help doc + out := ORAS("attach", "--help").MatchKeyWords(feature.Preview.Mark+" Attach", feature.Preview.Description, ExampleDesc).Exec().Out gomega.Expect(out).Should(gbytes.Say("--distribution-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) }) + It("should not show --verbose in help doc", func() { + out := ORAS("push", "--help").MatchKeyWords(ExampleDesc).Exec().Out + gomega.Expect(out).ShouldNot(gbytes.Say("--verbose")) + }) + It("should show deprecation message and print unnamed status output for --verbose", func() { testRepo := attachTestRepo("test-verbose") CopyZOTRepo(ImageRepo, testRepo) @@ -56,7 +60,7 @@ var _ = Describe("ORAS beginners:", func() { } ORAS("attach", "--artifact-type", "test/attach", "--verbose", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)). WithWorkDir(PrepareTempFiles()). - MatchErrKeyWords(DeprecationMessageVerboseFlag). + MatchErrKeyWords(feature.DeprecationMessageVerboseFlag). MatchStatus(stateKeys, true, len(stateKeys)).Exec() }) @@ -67,8 +71,8 @@ var _ = Describe("ORAS beginners:", func() { stateKeys := []match.StateKey{foobar.AttachFileStateKey} out := ORAS("attach", "--artifact-type", "test/attach", "--verbose=false", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)). WithWorkDir(PrepareTempFiles()). - MatchErrKeyWords(DeprecationMessageVerboseFlag). - MatchStatus(stateKeys, false, len(stateKeys)).Exec() + MatchErrKeyWords(feature.DeprecationMessageVerboseFlag). + MatchStatus(stateKeys, false, len(stateKeys)).Exec().Out gomega.Expect(out).ShouldNot(gbytes.Say("application/vnd.oci.empty.v1+json")) }) diff --git a/test/e2e/suite/command/blob.go b/test/e2e/suite/command/blob.go index a0ebffabc..8d6ddf21d 100644 --- a/test/e2e/suite/command/blob.go +++ b/test/e2e/suite/command/blob.go @@ -24,6 +24,7 @@ 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/foobar" . "oras.land/oras/test/e2e/internal/utils" "oras.land/oras/test/e2e/internal/utils/match" @@ -42,7 +43,6 @@ var _ = Describe("ORAS beginners:", func() { When("running `blob push`", func() { It("should not show --verbose in help doc", func() { out := ORAS("push", "--help").MatchKeyWords(ExampleDesc).Exec().Out - // verbose flag should be hidden in help doc gomega.Expect(out).ShouldNot(gbytes.Say("--verbose")) }) @@ -50,7 +50,7 @@ var _ = Describe("ORAS beginners:", func() { repo := fmt.Sprintf(repoFmt, "push", "test-verbose") ORAS("blob", "push", RegistryRef(ZOTHost, repo, pushDigest), "-", "--size", strconv.Itoa(len(pushContent)), "--verbose"). WithInput(strings.NewReader(pushContent)). - MatchErrKeyWords(DeprecationMessageVerboseFlag). + MatchErrKeyWords(feature.DeprecationMessageVerboseFlag). MatchStatus([]match.StateKey{{Digest: "e1ca41574914", Name: "application/vnd.oci.image.layer.v1.tar"}}, true, 1). Exec() }) @@ -59,8 +59,8 @@ var _ = Describe("ORAS beginners:", func() { repo := fmt.Sprintf(repoFmt, "push", "test-verbose-false") out := ORAS("blob", "push", RegistryRef(ZOTHost, repo, pushDigest), "-", "--size", strconv.Itoa(len(pushContent)), "--verbose=false"). WithInput(strings.NewReader(pushContent)). - MatchErrKeyWords(DeprecationMessageVerboseFlag). - Exec() + MatchErrKeyWords(feature.DeprecationMessageVerboseFlag). + Exec().Out // should not print status output for unnamed blobs gomega.Expect(out).ShouldNot(gbytes.Say("application/vnd.oci.image.layer.v1.tar")) }) diff --git a/test/e2e/suite/command/cp.go b/test/e2e/suite/command/cp.go index 5fd24fb96..169629c2a 100644 --- a/test/e2e/suite/command/cp.go +++ b/test/e2e/suite/command/cp.go @@ -48,15 +48,18 @@ var _ = Describe("ORAS beginners:", func() { Expect(out).Should(gbytes.Say("--from-distribution-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) Expect(out).Should(gbytes.Say("-r, --recursive\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) Expect(out).Should(gbytes.Say("--to-distribution-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) - // verbose flag should be hidden in help doc - Expect(out).ShouldNot(gbytes.Say("--verbose")) + }) + + It("should not show --verbose in help doc", func() { + out := ORAS("push", "--help").MatchKeyWords(ExampleDesc).Exec().Out + gomega.Expect(out).ShouldNot(gbytes.Say("--verbose")) }) It("should show deprecation message and print unnamed status output for --verbose", func() { src := RegistryRef(ZOTHost, ArtifactRepo, blob.Tag) dst := RegistryRef(ZOTHost, cpTestRepo("test-verbose"), "copied") ORAS("cp", src, dst, "--verbose"). - MatchErrKeyWords(DeprecationMessageVerboseFlag). + MatchErrKeyWords(feature.DeprecationMessageVerboseFlag). MatchStatus(blob.StateKeys, true, len(blob.StateKeys)). Exec() CompareRef(src, dst) @@ -69,9 +72,9 @@ var _ = Describe("ORAS beginners:", func() { {Digest: "2ef548696ac7", Name: "hello.tar"}, } out := ORAS("cp", src, dst, "--verbose=false"). - MatchErrKeyWords(DeprecationMessageVerboseFlag). + MatchErrKeyWords(feature.DeprecationMessageVerboseFlag). MatchStatus(stateKeys, false, len(stateKeys)). - Exec() + Exec().Out CompareRef(src, dst) // should not print status output for unnamed blobs gomega.Expect(out).ShouldNot(gbytes.Say("application/vnd.oci.empty.v1+json")) diff --git a/test/e2e/suite/command/discover.go b/test/e2e/suite/command/discover.go index 977c1b03c..5d2723dc7 100644 --- a/test/e2e/suite/command/discover.go +++ b/test/e2e/suite/command/discover.go @@ -52,7 +52,7 @@ var _ = Describe("ORAS beginners:", func() { RunAndShowPreviewInHelp([]string{"discover"}) It("should show preview and help doc", func() { - out := ORAS("discover", "--help").MatchKeyWords(feature.Preview.Mark+" Discover", feature.Preview.Description, ExampleDesc).Exec() + out := ORAS("discover", "--help").MatchKeyWords(feature.Preview.Mark+" Discover", feature.Preview.Description, ExampleDesc).Exec().Out gomega.Expect(out).Should(gbytes.Say("--distribution-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) }) diff --git a/test/e2e/suite/command/manifest.go b/test/e2e/suite/command/manifest.go index 467de92b7..4b55dc145 100644 --- a/test/e2e/suite/command/manifest.go +++ b/test/e2e/suite/command/manifest.go @@ -54,10 +54,8 @@ var _ = Describe("ORAS beginners:", func() { When("running manifest command", func() { When("running `manifest push`", func() { It("should show help doc with feature flags", func() { - out := ORAS("manifest", "push", "--help").MatchKeyWords(ExampleDesc).Exec() + out := ORAS("manifest", "push", "--help").MatchKeyWords(ExampleDesc).Exec().Out gomega.Expect(out).Should(gbytes.Say("--distribution-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) - // verbose flag should be hidden in help doc - gomega.Expect(out).ShouldNot(gbytes.Say("--verbose")) }) It("should have flag for prettifying JSON output", func() { @@ -66,6 +64,11 @@ var _ = Describe("ORAS beginners:", func() { Exec() }) + It("should not show --verbose in help doc", func() { + out := ORAS("push", "--help").MatchKeyWords(ExampleDesc).Exec().Out + gomega.Expect(out).ShouldNot(gbytes.Say("--verbose")) + }) + It("should show deprecation message and print unnamed status output for --verbose", func() { manifest := `{"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":[]}` manifestDigest := "sha256:bc1a59d49fc7c7b0a31f22ca0c743ecdabdb736777e3d9672fa9d97b4fe323f4" @@ -73,7 +76,7 @@ var _ = Describe("ORAS beginners:", func() { tag := "test-verbose" ORAS("manifest", "push", RegistryRef(ZOTHost, ImageRepo, tag), "-", "--verbose"). WithInput(strings.NewReader(manifest)). - MatchErrKeyWords(DeprecationMessageVerboseFlag). + MatchErrKeyWords(feature.DeprecationMessageVerboseFlag). MatchKeyWords("Pushed", RegistryRef(ZOTHost, ImageRepo, tag), "Digest:", manifestDigest). MatchStatus([]match.StateKey{{Digest: "bc1a59d49fc7", Name: "application/vnd.oci.image.manifest.v1+json"}}, true, 1). Exec() @@ -86,9 +89,9 @@ var _ = Describe("ORAS beginners:", func() { tag := "test-verbose-false" out := ORAS("manifest", "push", RegistryRef(ZOTHost, ImageRepo, tag), "-", "--verbose=false"). WithInput(strings.NewReader(manifest)). - MatchErrKeyWords(DeprecationMessageVerboseFlag). + MatchErrKeyWords(feature.DeprecationMessageVerboseFlag). MatchKeyWords("Pushed", RegistryRef(ZOTHost, ImageRepo, tag), "Digest:", manifestDigest). - Exec() + Exec().Out // should not print status output for unnamed blobs gomega.Expect(out).ShouldNot(gbytes.Say("application/vnd.oci.image.manifest.v1+json")) }) @@ -153,7 +156,7 @@ var _ = Describe("ORAS beginners:", func() { When("running `manifest delete`", func() { It("should show help doc with feature flags", func() { - out := ORAS("manifest", "delete", "--help").MatchKeyWords(ExampleDesc).Exec() + out := ORAS("manifest", "delete", "--help").MatchKeyWords(ExampleDesc).Exec().Out gomega.Expect(out).Should(gbytes.Say("--distribution-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) }) diff --git a/test/e2e/suite/command/pull.go b/test/e2e/suite/command/pull.go index 9a6c600d8..f31436e7a 100644 --- a/test/e2e/suite/command/pull.go +++ b/test/e2e/suite/command/pull.go @@ -41,7 +41,10 @@ var _ = Describe("ORAS beginners:", func() { It("should show help description with feature flags", func() { out := ORAS("pull", "--help").MatchKeyWords(ExampleDesc).Exec().Out gomega.Expect(out).Should(gbytes.Say("--include-subject\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) - // verbose flag should be hidden in help doc + }) + + It("should not show --verbose in help doc", func() { + out := ORAS("push", "--help").MatchKeyWords(ExampleDesc).Exec().Out gomega.Expect(out).ShouldNot(gbytes.Say("--verbose")) }) @@ -55,7 +58,7 @@ var _ = Describe("ORAS beginners:", func() { stateKeys := append(foobar.ImageLayerStateKeys, foobar.ManifestStateKey) ORAS("pull", ref, "--verbose"). WithWorkDir(tempDir). - MatchErrKeyWords(DeprecationMessageVerboseFlag). + MatchErrKeyWords(feature.DeprecationMessageVerboseFlag). MatchStatus(stateKeys, true, len(stateKeys)). Exec() }) @@ -66,9 +69,9 @@ var _ = Describe("ORAS beginners:", func() { stateKeys := foobar.ImageLayerStateKeys out := ORAS("pull", ref, "--verbose=false"). WithWorkDir(tempDir). - MatchErrKeyWords(DeprecationMessageVerboseFlag). + MatchErrKeyWords(feature.DeprecationMessageVerboseFlag). MatchStatus(stateKeys, false, len(stateKeys)). - Exec() + Exec().Out // should not print status output for unnamed blobs gomega.Expect(out).ShouldNot(gbytes.Say("application/vnd.oci.image.manifest.v1+json")) }) diff --git a/test/e2e/suite/command/push.go b/test/e2e/suite/command/push.go index c5a25fc04..e489283f9 100644 --- a/test/e2e/suite/command/push.go +++ b/test/e2e/suite/command/push.go @@ -39,7 +39,10 @@ var _ = Describe("ORAS beginners:", func() { It("should show help description with feature flags", func() { out := ORAS("push", "--help").MatchKeyWords(ExampleDesc).Exec().Out gomega.Expect(out).Should(gbytes.Say("--image-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) - // verbose flag should be hidden in help doc + }) + + It("should not show --verbose in help doc", func() { + out := ORAS("push", "--help").MatchKeyWords(ExampleDesc).Exec().Out gomega.Expect(out).ShouldNot(gbytes.Say("--verbose")) }) @@ -57,7 +60,7 @@ var _ = Describe("ORAS beginners:", func() { ORAS("push", RegistryRef(ZOTHost, repo, tag), "--verbose"). WithWorkDir(tempDir). - MatchErrKeyWords(DeprecationMessageVerboseFlag). + MatchErrKeyWords(feature.DeprecationMessageVerboseFlag). MatchStatus(stateKeys, true, len(stateKeys)). Exec() }) @@ -69,8 +72,8 @@ var _ = Describe("ORAS beginners:", func() { out := ORAS("push", RegistryRef(ZOTHost, repo, tag), "--verbose=false"). WithWorkDir(tempDir). - MatchErrKeyWords(DeprecationMessageVerboseFlag). - Exec() + MatchErrKeyWords(feature.DeprecationMessageVerboseFlag). + Exec().Out // should not print status output for unnamed blobs gomega.Expect(out).ShouldNot(gbytes.Say("application/vnd.oci.empty.v1+json")) gomega.Expect(out).ShouldNot(gbytes.Say("application/vnd.oci.image.manifest.v1+json"))