Skip to content

Commit

Permalink
cp e2e
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 2, 2024
1 parent 042f77b commit bbf8b63
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
4 changes: 2 additions & 2 deletions test/e2e/suite/command/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ var _ = Describe("1.1 registry users:", func() {
MatchContent(fmt.Sprintf(pushDescFmt, mediaType)).Exec()
ORAS("blob", "fetch", RegistryRef(ZOTHost, repo, pushDigest), "--output", "-").MatchContent(pushContent).Exec()

ORAS("blob", "push", RegistryRef(ZOTHost, repo, ""), blobPath, "-v").
ORAS("blob", "push", RegistryRef(ZOTHost, repo, ""), blobPath).
WithDescription("skip the pushing if the blob already exists in the target repo").
MatchKeyWords("Exists").Exec()
})
Expand Down Expand Up @@ -347,7 +347,7 @@ var _ = Describe("OCI image layout users:", func() {
// test
ORAS("blob", "push", Flags.Layout, LayoutRef(tmpRoot, pushDigest), blobPath, "--media-type", mediaType, "--descriptor").
MatchContent(fmt.Sprintf(pushDescFmt, mediaType)).Exec()
ORAS("blob", "push", Flags.Layout, LayoutRef(tmpRoot, pushDigest), blobPath, "-v").
ORAS("blob", "push", Flags.Layout, LayoutRef(tmpRoot, pushDigest), blobPath).
WithDescription("skip pushing if the blob already exists in the target repo").
MatchKeyWords("Exists").Exec()
// validate
Expand Down
64 changes: 44 additions & 20 deletions test/e2e/suite/command/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"oras.land/oras/test/e2e/internal/testdata/foobar"
ma "oras.land/oras/test/e2e/internal/testdata/multi_arch"
. "oras.land/oras/test/e2e/internal/utils"
"oras.land/oras/test/e2e/internal/utils/match"
)

func cpTestRepo(text string) string {
Expand All @@ -54,6 +55,29 @@ var _ = Describe("ORAS beginners:", func() {
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).
MatchStatus(blob.StateKeys, true, len(blob.StateKeys)).
Exec()
CompareRef(src, dst)
})

It("should show deprecation message and print unnamed status output for --verbose=false", func() {
src := RegistryRef(ZOTHost, ArtifactRepo, blob.Tag)
dst := RegistryRef(ZOTHost, cpTestRepo("test-verbose-false"), "copied")
stateKeys := []match.StateKey{
{Digest: "2ef548696ac7", Name: "hello.tar"},
}
ORAS("cp", src, dst, "--verbose=false").
MatchErrKeyWords(DeprecationMessageVerboseFlag).
MatchStatus(stateKeys, true, len(stateKeys)).
Exec()
CompareRef(src, dst)
})

It("should fail when no reference provided", func() {
ORAS("cp").ExpectFailure().MatchErrKeyWords("Error:").Exec()
})
Expand Down Expand Up @@ -127,7 +151,7 @@ var _ = Describe("1.1 registry users:", func() {
It("should copy an artifact with blob", func() {
src := RegistryRef(ZOTHost, ArtifactRepo, blob.Tag)
dst := RegistryRef(ZOTHost, cpTestRepo("artifact-with-blob"), "copied")
ORAS("cp", src, dst, "-v").MatchStatus(blob.StateKeys, true, len(blob.StateKeys)).Exec()
ORAS("cp", src, dst).MatchStatus(blob.StateKeys, true, len(blob.StateKeys)).Exec()
CompareRef(src, dst)
})

Expand All @@ -143,42 +167,42 @@ var _ = Describe("1.1 registry users:", func() {
It("should copy an artifact with config", func() {
src := RegistryRef(ZOTHost, ArtifactRepo, config.Tag)
dst := RegistryRef(ZOTHost, cpTestRepo("artifact-with-config"), "copied")
ORAS("cp", src, dst, "-v").MatchStatus(config.StateKeys, true, len(config.StateKeys)).Exec()
ORAS("cp", src, dst).MatchStatus(config.StateKeys, true, len(config.StateKeys)).Exec()
})

It("should copy index and its subject", func() {
stateKeys := append(ma.IndexStateKeys, index.ManifestStatusKey)
src := RegistryRef(ZOTHost, ArtifactRepo, index.ManifestDigest)
dst := RegistryRef(ZOTHost, cpTestRepo("index-with-subject"), "")
ORAS("cp", src, dst, "-v").MatchStatus(stateKeys, true, len(stateKeys)).Exec()
ORAS("cp", src, dst).MatchStatus(stateKeys, true, len(stateKeys)).Exec()
})

It("should copy an image to a new repository via tag", func() {
src := RegistryRef(ZOTHost, ImageRepo, foobar.Tag)
dst := RegistryRef(ZOTHost, cpTestRepo("tag"), "copied")
ORAS("cp", src, dst, "-v").MatchStatus(foobarStates, true, len(foobarStates)).Exec()
ORAS("cp", src, dst).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
CompareRef(src, dst)
})

It("should copy an image to a new repository via digest", func() {
src := RegistryRef(ZOTHost, ImageRepo, foobar.Digest)
dst := RegistryRef(ZOTHost, cpTestRepo("digest"), "copiedTag")
ORAS("cp", src, dst, "-v").MatchStatus(foobarStates, true, len(foobarStates)).Exec()
ORAS("cp", src, dst).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
CompareRef(src, dst)
})

It("should copy an image to a new repository via tag without tagging", func() {
src := RegistryRef(ZOTHost, ImageRepo, foobar.Tag)
dst := RegistryRef(ZOTHost, cpTestRepo("no-tagging"), foobar.Digest)
ORAS("cp", src, dst, "-v").MatchStatus(foobarStates, true, len(foobarStates)).Exec()
ORAS("cp", src, dst).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
CompareRef(src, dst)
})

It("should copy an image and its referrers to a new repository", func() {
stateKeys := append(append(foobar.ImageLayerStateKeys, foobar.ManifestStateKey, foobar.ImageReferrerConfigStateKeys[0]), foobar.ImageReferrersStateKeys...)
src := RegistryRef(ZOTHost, ArtifactRepo, foobar.Tag)
dst := RegistryRef(ZOTHost, cpTestRepo("referrers"), foobar.Digest)
ORAS("cp", "-r", src, dst, "-v").MatchStatus(stateKeys, true, len(stateKeys)).Exec()
ORAS("cp", "-r", src, dst).MatchStatus(stateKeys, true, len(stateKeys)).Exec()
CompareRef(src, dst)
})

Expand All @@ -187,7 +211,7 @@ var _ = Describe("1.1 registry users:", func() {
src := RegistryRef(ZOTHost, ArtifactRepo, ma.Tag)
dstRepo := cpTestRepo("index-referrers")
dst := RegistryRef(ZOTHost, dstRepo, "copiedTag")
ORAS("cp", src, dst, "-r", "-v").
ORAS("cp", src, dst, "-r").
MatchStatus(stateKeys, true, len(stateKeys)).
MatchKeyWords("Digest: " + ma.Digest).
Exec()
Expand Down Expand Up @@ -233,7 +257,7 @@ var _ = Describe("1.1 registry users:", func() {
src := RegistryRef(ZOTHost, ArtifactRepo, ma.Tag)
dstRepo := cpTestRepo("index-referrers-digest")
dst := RegistryRef(ZOTHost, dstRepo, ma.Digest)
ORAS("cp", src, dst, "-r", "-v").
ORAS("cp", src, dst, "-r").
MatchStatus(stateKeys, true, len(stateKeys)).
MatchKeyWords("Digest: " + ma.Digest).
Exec()
Expand All @@ -249,7 +273,7 @@ var _ = Describe("1.1 registry users:", func() {
src := RegistryRef(ZOTHost, ImageRepo, ma.Tag)
dst := RegistryRef(ZOTHost, cpTestRepo("platform-tag"), "copiedTag")

ORAS("cp", src, dst, "--platform", "linux/amd64", "-v").
ORAS("cp", src, dst, "--platform", "linux/amd64").
MatchStatus(ma.LinuxAMD64StateKeys, true, len(ma.LinuxAMD64StateKeys)).
MatchKeyWords("Digest: " + ma.LinuxAMD64.Digest.String()).
Exec()
Expand All @@ -260,7 +284,7 @@ var _ = Describe("1.1 registry users:", func() {
src := RegistryRef(ZOTHost, ImageRepo, ma.Digest)
dstRepo := cpTestRepo("platform-digest")
dst := RegistryRef(ZOTHost, dstRepo, "")
ORAS("cp", src, dst, "--platform", "linux/amd64", "-v").
ORAS("cp", src, dst, "--platform", "linux/amd64").
MatchStatus(ma.LinuxAMD64StateKeys, true, len(ma.LinuxAMD64StateKeys)).
MatchKeyWords("Digest: " + ma.LinuxAMD64.Digest.String()).
Exec()
Expand All @@ -273,7 +297,7 @@ var _ = Describe("1.1 registry users:", func() {
dstRepo := cpTestRepo("platform-referrers")
dst := RegistryRef(ZOTHost, dstRepo, "copiedTag")
digest := ma.LinuxAMD64.Digest.String()
ORAS("cp", src, dst, "-r", "--platform", "linux/amd64", "-v").
ORAS("cp", src, dst, "-r", "--platform", "linux/amd64").
MatchStatus(stateKeys, true, len(stateKeys)).
MatchKeyWords("Digest: " + digest).
Exec()
Expand All @@ -291,7 +315,7 @@ var _ = Describe("1.1 registry users:", func() {
dstRepo := cpTestRepo("platform-referrers-no-tag")
dst := RegistryRef(ZOTHost, dstRepo, "")
digest := ma.LinuxAMD64.Digest.String()
ORAS("cp", src, dst, "-r", "--platform", "linux/amd64", "-v").
ORAS("cp", src, dst, "-r", "--platform", "linux/amd64").
MatchStatus(stateKeys, true, len(stateKeys)).
MatchKeyWords("Digest: " + digest).
Exec()
Expand All @@ -308,7 +332,7 @@ var _ = Describe("1.1 registry users:", func() {
tags := []string{"tag1", "tag2", "tag3"}
dstRepo := cpTestRepo("multi-tagging")
dst := RegistryRef(ZOTHost, dstRepo, "")
ORAS("cp", src, dst+":"+strings.Join(tags, ","), "-v").MatchStatus(foobarStates, true, len(foobarStates)).Exec()
ORAS("cp", src, dst+":"+strings.Join(tags, ",")).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
for _, tag := range tags {
dst := RegistryRef(ZOTHost, dstRepo, tag)
CompareRef(src, dst)
Expand All @@ -323,7 +347,7 @@ var _ = Describe("OCI spec 1.0 registry users:", func() {
repo := cpTestRepo("1.0-mount")
src := RegistryRef(FallbackHost, ArtifactRepo, foobar.Tag)
dst := RegistryRef(FallbackHost, repo, "")
out := ORAS("cp", src, dst, "-v").Exec()
out := ORAS("cp", src, dst).Exec()
Expect(out).Should(gbytes.Say("Mounted fcde2b2edba5 bar"))
CompareRef(src, RegistryRef(FallbackHost, repo, foobar.Digest))
})
Expand All @@ -333,7 +357,7 @@ var _ = Describe("OCI spec 1.0 registry users:", func() {
stateKeys := append(append(foobar.ImageLayerStateKeys, foobar.ManifestStateKey, foobar.ImageReferrerConfigStateKeys[0]), foobar.ImageReferrersStateKeys...)
src := RegistryRef(ZOTHost, ArtifactRepo, foobar.SignatureImageReferrer.Digest.String())
dst := RegistryRef(FallbackHost, repo, "")
ORAS("cp", "-r", src, dst, "-v").MatchStatus(stateKeys, true, len(stateKeys)).Exec()
ORAS("cp", "-r", src, dst).MatchStatus(stateKeys, true, len(stateKeys)).Exec()
CompareRef(src, RegistryRef(FallbackHost, repo, foobar.SignatureImageReferrer.Digest.String()))
ORAS("discover", "-o", "tree", RegistryRef(FallbackHost, repo, foobar.Digest)).
WithDescription("discover referrer via subject").MatchKeyWords(foobar.SignatureImageReferrer.Digest.String(), foobar.SBOMImageReferrer.Digest.String()).Exec()
Expand All @@ -343,7 +367,7 @@ var _ = Describe("OCI spec 1.0 registry users:", func() {
stateKeys := append(append(foobar.ImageLayerStateKeys, foobar.ManifestStateKey, foobar.ImageReferrerConfigStateKeys[0]), foobar.ImageReferrersStateKeys...)
src := RegistryRef(FallbackHost, ArtifactRepo, foobar.SBOMImageReferrer.Digest.String())
dst := RegistryRef(ZOTHost, repo, "")
ORAS("cp", "-r", src, dst, "-v").MatchStatus(stateKeys, true, len(stateKeys)).Exec()
ORAS("cp", "-r", src, dst).MatchStatus(stateKeys, true, len(stateKeys)).Exec()
CompareRef(src, RegistryRef(ZOTHost, repo, foobar.SBOMImageReferrer.Digest.String()))
ORAS("discover", "-o", "tree", RegistryRef(ZOTHost, repo, foobar.Digest)).
WithDescription("discover referrer via subject").MatchKeyWords(foobar.SignatureImageReferrer.Digest.String(), foobar.SBOMImageReferrer.Digest.String()).Exec()
Expand Down Expand Up @@ -528,7 +552,7 @@ var _ = Describe("OCI layout users:", func() {
toDir := GinkgoT().TempDir()
dst := LayoutRef(toDir, "copied")
// test
ORAS("cp", src, Flags.ToLayout, dst, "-r", "-v").
ORAS("cp", src, Flags.ToLayout, dst, "-r").
MatchStatus(stateKeys, true, len(stateKeys)).
MatchKeyWords("Digest: " + ma.Digest).
Exec()
Expand Down Expand Up @@ -557,7 +581,7 @@ var _ = Describe("OCI layout users:", func() {
// prepare
ORAS("cp", RegistryRef(ZOTHost, ArtifactRepo, ma.Tag), src, Flags.ToLayout, "-r").Exec()
// test
ORAS("cp", src, Flags.FromLayout, dst, "-r", "-v").
ORAS("cp", src, Flags.FromLayout, dst, "-r").
MatchStatus(stateKeys, true, len(stateKeys)).
MatchKeyWords("Digest: " + ma.Digest).
Exec()
Expand Down Expand Up @@ -725,7 +749,7 @@ var _ = Describe("OCI image spec v1.1.0-rc2 artifact users:", func() {
digest := foobar.SBOMArtifactReferrer.Digest.String()
src := RegistryRef(Host, ArtifactRepo, digest)
dst := RegistryRef(Host, cpTestRepo("referrers"), digest)
ORAS("cp", "-r", src, dst, "-v").MatchStatus(stateKeys, true, len(stateKeys)).Exec()
ORAS("cp", "-r", src, dst).MatchStatus(stateKeys, true, len(stateKeys)).Exec()
CompareRef(src, dst)
})
})
2 changes: 1 addition & 1 deletion test/e2e/suite/command/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var _ = Describe("ORAS beginners:", func() {
Exec()
})

It("should show deprecation message and print unnamed status output for --verbose", func() {
It("should show deprecation message and print unnamed status output for --verbose=false", func() {
repo := pushTestRepo("test-verbose-false")
tag := "e2e"
tempDir := PrepareTempFiles()
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/suite/command/resolve_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ var _ = Describe("1.1 registry users:", func() {
It("should copy an image with source resolve DNS rules", func() {
repo := testRepo("cp/from")
dst := RegistryRef(Host, repo, "copied")
ORAS(append([]string{"cp", RegistryRef(mockedHost, ImageRepo, foobar.Tag), dst, "-v"}, from...)...).
ORAS(append([]string{"cp", RegistryRef(mockedHost, ImageRepo, foobar.Tag), dst}, from...)...).
MatchStatus(foobarStates, true, len(foobarStates)).
Exec()
CompareRef(RegistryRef(Host, ImageRepo, foobar.Tag), dst)
Expand All @@ -136,7 +136,7 @@ var _ = Describe("1.1 registry users:", func() {
src := RegistryRef(Host, ImageRepo, foobar.Tag)
repo := testRepo("cp/to")
tag := "copied"
ORAS(append([]string{"cp", src, RegistryRef(mockedHost, repo, tag), "-v"}, to...)...).
ORAS(append([]string{"cp", src, RegistryRef(mockedHost, repo, tag)}, to...)...).
MatchStatus(foobarStates, true, len(foobarStates)).
Exec()
CompareRef(src, RegistryRef(Host, repo, tag))
Expand All @@ -147,7 +147,7 @@ var _ = Describe("1.1 registry users:", func() {
repo := testRepo("cp/base")
tag := "copied"
flags := append(to[2:], "--resolve", unary[1]) //hack to chop the destination flags off
ORAS(append([]string{"cp", src, RegistryRef(mockedHost, repo, tag), "-v"}, flags...)...).
ORAS(append([]string{"cp", src, RegistryRef(mockedHost, repo, tag)}, flags...)...).
MatchStatus(foobarStates, true, len(foobarStates)).
Exec()
CompareRef(src, RegistryRef(Host, repo, tag))
Expand All @@ -157,7 +157,7 @@ var _ = Describe("1.1 registry users:", func() {
repo := testRepo("cp/override")
tag := "copied"
flags := append(append(to, from...), "--resolve", mockedHost+":80:1.1.1.1:5000")
ORAS(append([]string{"cp", RegistryRef(mockedHost, ImageRepo, foobar.Tag), RegistryRef(mockedHost, repo, tag), "-v"}, flags...)...).
ORAS(append([]string{"cp", RegistryRef(mockedHost, ImageRepo, foobar.Tag), RegistryRef(mockedHost, repo, tag)}, flags...)...).
MatchStatus(foobarStates, true, len(foobarStates)).
Exec()
CompareRef(RegistryRef(Host, ImageRepo, foobar.Tag), RegistryRef(Host, repo, tag))
Expand Down Expand Up @@ -235,7 +235,7 @@ var _ = Describe("1.1 registry users:", func() {
It("should push files without customized media types", func() {
repo := testRepo("push")
tempDir := PrepareTempFiles()
ORAS(append([]string{"push", RegistryRef(mockedHost, repo, foobar.Tag), "-v"}, append(foobar.FileLayerNames, unary...)...)...).
ORAS(append([]string{"push", RegistryRef(mockedHost, repo, foobar.Tag)}, append(foobar.FileLayerNames, unary...)...)...).
MatchStatus(foobar.FileStateKeys, true, len(foobar.FileStateKeys)).
WithWorkDir(tempDir).Exec()
})
Expand Down

0 comments on commit bbf8b63

Please sign in to comment.