Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lixia (Sylvia) Lei <[email protected]>
  • Loading branch information
Wwwsylvia committed Dec 5, 2024
1 parent 230f053 commit ddcf411
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 48 deletions.
2 changes: 2 additions & 0 deletions test/e2e/internal/testdata/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions test/e2e/internal/utils/deprecation.go

This file was deleted.

1 change: 1 addition & 0 deletions test/e2e/internal/utils/match/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 9 additions & 5 deletions test/e2e/suite/command/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
})

Expand All @@ -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"))
})

Expand Down
8 changes: 4 additions & 4 deletions test/e2e/suite/command/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -42,15 +43,14 @@ 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"))
})

It("should show deprecation message and print unnamed status output for --verbose", 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()
})
Expand All @@ -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"))
})
Expand Down
13 changes: 8 additions & 5 deletions test/e2e/suite/command/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suite/command/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
})

Expand Down
17 changes: 10 additions & 7 deletions test/e2e/suite/command/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -66,14 +64,19 @@ 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"

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()
Expand All @@ -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"))
})
Expand Down Expand Up @@ -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)))
})

Expand Down
11 changes: 7 additions & 4 deletions test/e2e/suite/command/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})

Expand All @@ -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()
})
Expand All @@ -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"))
})
Expand Down
11 changes: 7 additions & 4 deletions test/e2e/suite/command/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})

Expand All @@ -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()
})
Expand All @@ -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"))
Expand Down

0 comments on commit ddcf411

Please sign in to comment.