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): layout specs for oras manifest push #880

Merged
merged 7 commits into from
Mar 17, 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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
gopkg.in/yaml.v3 v3.0.1
oras.land/oras-go/v2 v2.0.1
oras.land/oras-go/v2 v2.0.0-20230317034844-336b9fb9c68c
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
oras.land/oras-go/v2 v2.0.1 h1:fdnzCXT6yBQziJNJrCqaUPd6Ww7j6M0qLrtFA80tTeM=
oras.land/oras-go/v2 v2.0.1/go.mod h1:PWnWc/Kyyg7wUTUsDHshrsJkzuxXzreeMd6NrfdnFSo=
oras.land/oras-go/v2 v2.0.0-20230317034844-336b9fb9c68c h1:tIEkN9LOZGLh6MTGwSYkiXEBw9KeAWC9jbfa/Qoniqk=
oras.land/oras-go/v2 v2.0.0-20230317034844-336b9fb9c68c/go.mod h1:PWnWc/Kyyg7wUTUsDHshrsJkzuxXzreeMd6NrfdnFSo=
2 changes: 1 addition & 1 deletion test/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc2
gopkg.in/yaml.v2 v2.4.0
oras.land/oras-go/v2 v2.0.0-20230224055117-216f081e33ba
oras.land/oras-go/v2 v2.0.0-20230317034844-336b9fb9c68c
)

require (
Expand Down
89 changes: 89 additions & 0 deletions test/e2e/suite/command/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ limitations under the License.
package command

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -511,3 +513,90 @@ var _ = Describe("OCI image layout users:", func() {
})
})
})

var _ = Describe("OCI image layout users:", func() {
When("running `manifest push`", func() {
scratchSize := 2
scratchDigest := "sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"
manifest := fmt.Sprintf(`{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","config":{"mediaType":"application/vnd.oci.image.config.v1+json","digest":"%s","size":%d},"layers":[]}`, scratchDigest, scratchSize)
manifestDigest := "sha256:f20c43161d73848408ef247f0ec7111b19fe58ffebc0cbcaa0d2c8bda4967268"
prepare := func(layoutRoot string) {
ORAS("blob", "push", Flags.Layout, LayoutRef(layoutRoot, scratchDigest), "--size", "2", "-").
WithInput(strings.NewReader("{}")).Exec()
}
validate := func(root string, digest string, tag string) {
path := filepath.Join(root, "index.json")
Expect(path).To(BeAnExistingFile())
content, err := os.ReadFile(path)
Expect(err).NotTo(HaveOccurred())
var index ocispec.Index
Expect(json.Unmarshal(content, &index)).ShouldNot(HaveOccurred())
for _, m := range index.Manifests {
if m.Digest.String() == digest &&
(tag == "" || tag == m.Annotations["org.opencontainers.image.ref.name"]) {
return
}
}
Fail(fmt.Sprintf("Failed to find manifest with digest %q and tag %q in index.json: \n%s", digest, tag, string(content)))
}
descriptor := "{\"mediaType\":\"application/vnd.oci.image.manifest.v1+json\",\"digest\":\"sha256:f20c43161d73848408ef247f0ec7111b19fe58ffebc0cbcaa0d2c8bda4967268\",\"size\":246}"

It("should push a manifest from stdin", func() {
root := GinkgoT().TempDir()
prepare(root)
ORAS("manifest", "push", Flags.Layout, root, "-").
MatchKeyWords("Pushed", root, "Digest:", manifestDigest).
WithInput(strings.NewReader(manifest)).Exec()
validate(root, manifestDigest, "")
})
It("should push a manifest from stdin and tag", func() {
tag := "from-stdin"
root := GinkgoT().TempDir()
ref := LayoutRef(root, tag)
ORAS("manifest", "push", Flags.Layout, ref, "-").
MatchKeyWords("Pushed", ref, "Digest:", manifestDigest).
WithInput(strings.NewReader(manifest)).Exec()
validate(root, manifestDigest, tag)
})

It("should push a manifest and output descriptor", func() {
root := GinkgoT().TempDir()
prepare(root)
ORAS("manifest", "push", Flags.Layout, root, "-", "--descriptor").
MatchContent(descriptor).
WithInput(strings.NewReader(manifest)).Exec()
validate(root, manifestDigest, "")
})

It("should push a manifest from file", func() {
manifestPath := WriteTempFile("manifest.json", manifest)
root := filepath.Dir(manifestPath)
prepare(root)
tag := "from-file"
ref := LayoutRef(root, tag)
ORAS("manifest", "push", Flags.Layout, ref, manifestPath).
MatchKeyWords("Pushed", ref, "Digest:", manifestDigest).
WithInput(strings.NewReader(manifest)).Exec()
validate(root, manifestDigest, tag)
})

It("should push a manifest from stdin, only when media type flag is set", func() {
manifest := fmt.Sprintf(`{"schemaVersion":2,"config":{"mediaType":"application/vnd.oci.image.config.v1+json","digest":"%s","size":%d}}`, scratchDigest, scratchSize)
manifestDigest := "sha256:8fc649142bbc0a2aa5015d5ef5a922df9d2d7f2dcf3095dbebfaf7c271eca444"

root := GinkgoT().TempDir()
prepare(root)
tag := "mediatype-flag"
ref := LayoutRef(root, tag)
ORAS("manifest", "push", Flags.Layout, ref, "-", "--media-type", "application/vnd.oci.image.manifest.v1+json").
MatchKeyWords("Pushed", ref, "Digest:", manifestDigest).
WithInput(strings.NewReader(manifest)).Exec()
validate(root, manifestDigest, tag)

ORAS("manifest", "push", Flags.Layout, ref, "-").
WithInput(strings.NewReader(manifest)).
ExpectFailure().
WithDescription("fail if no media type flag provided").Exec()
})
})
})