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): OCI layout specs for oras attach #882

Merged
merged 2 commits into from
Mar 14, 2023
Merged
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
76 changes: 75 additions & 1 deletion test/e2e/suite/command/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ var _ = Describe("ORAS beginners:", func() {
ORAS("attach", "--artifact-type", "oras.test").ExpectFailure().MatchErrKeyWords("Error:").Exec()
})

It("should fail if no file reference or manifest annotation provided", func() {
It("should fail if no file reference or manifest annotation provided for registry", func() {
ORAS("attach", "--artifact-type", "oras.test", RegistryRef(Host, ImageRepo, foobar.Tag)).
ExpectFailure().MatchErrKeyWords("Error: no blob or manifest annotation are provided").Exec()
})

It("should fail if no file reference or manifest annotation provided for OCI layout", func() {
root := GinkgoT().TempDir()
ORAS("attach", "--artifact-type", "oras.test", LayoutRef(root, foobar.Tag)).
ExpectFailure().MatchErrKeyWords("Error: no blob or manifest annotation are provided").Exec()
})
})
})

Expand Down Expand Up @@ -182,3 +188,71 @@ var _ = Describe("Fallback registry users:", func() {
})
})
})

var _ = Describe("OCI image layout users:", func() {
When("running attach command", func() {
prepare := func(root string) {
ORAS("cp", RegistryRef(Host, ImageRepo, foobar.Tag), Flags.ToLayout, LayoutRef(root, foobar.Tag)).Exec()
}
It("should attach a file to a subject", func() {
root := PrepareTempFiles()
subjectRef := LayoutRef(root, foobar.Tag)
prepare(root)
ORAS("attach", "--artifact-type", "test.attach", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)).
WithWorkDir(root).
MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec()
})

It("should attach a file to a subject and export the built manifest", func() {
// prepare
root := PrepareTempFiles()
exportName := "manifest.json"
subjectRef := LayoutRef(root, foobar.Tag)
prepare(root)
// test
ORAS("attach", "--artifact-type", "test.attach", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--export-manifest", exportName).
WithWorkDir(root).
MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec()
// validate
var index ocispec.Index
bytes := ORAS("discover", Flags.Layout, subjectRef, "-o", "json").Exec().Out.Contents()
Expect(json.Unmarshal(bytes, &index)).ShouldNot(HaveOccurred())
Expect(len(index.Manifests)).To(Equal(1))
Expect(index.Manifests[0].MediaType).To(Equal(ocispec.MediaTypeImageManifest))
fetched := ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, index.Manifests[0].Digest.String())).Exec().Out.Contents()
MatchFile(filepath.Join(root, exportName), string(fetched), DefaultTimeout)
})
It("should attach a file via a OCI Image", func() {
root := PrepareTempFiles()
subjectRef := LayoutRef(root, foobar.Tag)
prepare(root)
// test
ORAS("attach", "--artifact-type", "test.attach", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--image-spec", "v1.1-image").
WithWorkDir(root).
MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec()

// validate
var index ocispec.Index
bytes := ORAS("discover", subjectRef, Flags.Layout, "-o", "json").Exec().Out.Contents()
Expect(json.Unmarshal(bytes, &index)).ShouldNot(HaveOccurred())
Expect(len(index.Manifests)).To(Equal(1))
Expect(index.Manifests[0].MediaType).To(Equal(ocispec.MediaTypeImageManifest))
})
It("should attach a file via a OCI Artifact", func() {
root := PrepareTempFiles()
subjectRef := LayoutRef(root, foobar.Tag)
prepare(root)
// test
ORAS("attach", "--artifact-type", "test.attach", subjectRef, Flags.Layout, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--image-spec", "v1.1-artifact").
WithWorkDir(root).
MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec()

// validate
var index ocispec.Index
bytes := ORAS("discover", subjectRef, Flags.Layout, "-o", "json").Exec().Out.Contents()
Expect(json.Unmarshal(bytes, &index)).ShouldNot(HaveOccurred())
Expect(len(index.Manifests)).To(Equal(1))
Expect(index.Manifests[0].MediaType).To(Equal(ocispec.MediaTypeArtifactManifest))
})
})
})