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(e2e): add test specs for oras pull #885

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion test/e2e/internal/utils/match/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,5 @@ func (s *statusMatcher) Match(got *gbytes.Buffer) {
for _, v := range s.endResult {
successCnt += len(v)
}
gomega.Expect(successCnt).To(gomega.Equal(s.successCount))
gomega.Expect(successCnt).To(gomega.Equal(s.successCount), "status output doesn't match")
}
86 changes: 86 additions & 0 deletions test/e2e/suite/command/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,95 @@ var _ = Describe("Remote registry users:", func() {
}
})

It("should pull subject", func() {
tempDir := GinkgoT().TempDir()
stateKeys := append(append(
foobar.ImageLayerStateKeys,
foobar.ManifestStateKey),
foobar.ImageReferrersStateKeys...,
)
ORAS("pull", RegistryRef(Host, ArtifactRepo, foobar.SignatureImageReferrer.Digest.String()), "-v", "--include-subject").
MatchStatus(stateKeys, true, len(stateKeys)).
WithWorkDir(tempDir).Exec()
})

It("should pull specific platform", func() {
ORAS("pull", RegistryRef(Host, ImageRepo, "multi"), "--platform", "linux/amd64", "-v", "-o", GinkgoT().TempDir()).
MatchStatus(multi_arch.LinuxAMD64StateKeys, true, len(multi_arch.LinuxAMD64StateKeys)).Exec()
})
})
})

var _ = Describe("OCI image layout users:", func() {
When("pulling images", func() {
var (
configName = "test.config"
)
prepare := func(root string, repo string, tagOrDigest string) {
ORAS("cp", RegistryRef(Host, repo, tagOrDigest), Flags.ToLayout, LayoutRef(root, tagOrDigest), "-r").WithDescription("prepare oci layout test env").Exec()
}
It("should pull all files in an image to a target folder", func() {
pullRoot := "pulled"
tempDir := PrepareTempFiles()
prepare(tempDir, ArtifactRepo, foobar.Tag)
stateKeys := append(foobar.ImageLayerStateKeys, foobar.ManifestStateKey, foobar.ImageConfigStateKey(configName))
ORAS("pull", Flags.Layout, LayoutRef(tempDir, foobar.Tag), "-v", "--config", configName, "-o", pullRoot).
MatchStatus(stateKeys, true, len(stateKeys)).
WithWorkDir(tempDir).Exec()
// check config
configPath := filepath.Join(tempDir, pullRoot, configName)
Expect(configPath).Should(BeAnExistingFile())
f, err := os.Open(configPath)
Expect(err).ShouldNot(HaveOccurred())
defer f.Close()
Eventually(gbytes.BufferReader(f)).Should(gbytes.Say("{}"))
for _, f := range foobar.ImageLayerNames {
// check layers
Binary("diff", filepath.Join(tempDir, "foobar", f), filepath.Join(pullRoot, f)).
WithWorkDir(tempDir).Exec()
}

ORAS("pull", Flags.Layout, LayoutRef(tempDir, foobar.Tag), "-v", "-o", pullRoot, "--keep-old-files").
ExpectFailure().
WithDescription("fail if overwrite old files are disabled")
})

It("should skip config if media type does not match", func() {
pullRoot := "pulled"
tempDir := PrepareTempFiles()
prepare(tempDir, ArtifactRepo, foobar.Tag)
stateKeys := append(foobar.ImageLayerStateKeys, foobar.ManifestStateKey, foobar.ImageConfigStateKey(oras.MediaTypeUnknownConfig))
ORAS("pull", Flags.Layout, LayoutRef(tempDir, foobar.Tag), "-v", "--config", fmt.Sprintf("%s:%s", configName, "???"), "-o", pullRoot).
MatchStatus(stateKeys, true, len(stateKeys)).
WithWorkDir(tempDir).Exec()
// check config
Expect(filepath.Join(pullRoot, configName)).ShouldNot(BeAnExistingFile())
for _, f := range foobar.ImageLayerNames {
// check layers
Binary("diff", filepath.Join(tempDir, "foobar", f), filepath.Join(pullRoot, f)).
WithWorkDir(tempDir).
WithDescription("should download identical file " + f).Exec()
}
})

It("should pull subject", func() {
tempDir := GinkgoT().TempDir()
prepare(tempDir, ArtifactRepo, foobar.Tag)
stateKeys := append(append(
foobar.ImageLayerStateKeys,
foobar.ManifestStateKey),
foobar.ImageReferrersStateKeys...,
)
ORAS("pull", Flags.Layout, LayoutRef(tempDir, foobar.SignatureImageReferrer.Digest.String()), "-v", "--include-subject").
MatchStatus(stateKeys, true, len(stateKeys)).
WithWorkDir(tempDir).Exec()
})

It("should pull specific platform", func() {
tempDir := GinkgoT().TempDir()
prepare(tempDir, ImageRepo, multi_arch.Tag)
ORAS("pull", Flags.Layout, LayoutRef(tempDir, multi_arch.Tag), "--platform", "linux/amd64", "-v", "-o", tempDir).
MatchStatus(multi_arch.LinuxAMD64StateKeys, true, len(multi_arch.LinuxAMD64StateKeys)).Exec()
})
})
})