From 3a0060b9973dfabf407a8725cdb769545e722810 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Thu, 25 Jan 2024 07:03:35 +0000 Subject: [PATCH] update discover usage in e2e Signed-off-by: Billy Zha --- test/e2e/suite/command/attach.go | 79 +++++++++++--------------------- 1 file changed, 26 insertions(+), 53 deletions(-) diff --git a/test/e2e/suite/command/attach.go b/test/e2e/suite/command/attach.go index 1b4523876..b0701e554 100644 --- a/test/e2e/suite/command/attach.go +++ b/test/e2e/suite/command/attach.go @@ -16,7 +16,6 @@ limitations under the License. package command import ( - "encoding/json" "fmt" "path/filepath" "regexp" @@ -26,7 +25,6 @@ import ( "github.com/onsi/gomega" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" - ocispec "github.com/opencontainers/image-spec/specs-go/v1" "oras.land/oras/test/e2e/internal/testdata/feature" "oras.land/oras/test/e2e/internal/testdata/foobar" . "oras.land/oras/test/e2e/internal/utils" @@ -107,15 +105,11 @@ var _ = Describe("1.1 registry users:", func() { subjectRef := RegistryRef(ZOTHost, testRepo, foobar.Tag) CopyZOTRepo(ImageRepo, testRepo) // test - ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--export-manifest", exportName). + ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--export-manifest", exportName, "--format", "{{.Ref}}"). WithWorkDir(tempDir). - MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec() + MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec().Out.Contents() // validate - var index ocispec.Index - bytes := ORAS("discover", subjectRef, "-o", "json").Exec().Out.Contents() - Expect(json.Unmarshal(bytes, &index)).ShouldNot(HaveOccurred()) - Expect(len(index.Manifests)).To(Equal(1)) - fetched := ORAS("manifest", "fetch", RegistryRef(ZOTHost, testRepo, index.Manifests[0].Digest.String())).Exec().Out.Contents() + fetched := ORAS("manifest", "fetch", string(ref)).Exec().Out.Contents() MatchFile(filepath.Join(tempDir, exportName), string(fetched), DefaultTimeout) }) @@ -157,15 +151,12 @@ var _ = Describe("1.1 registry users:", func() { subjectRef := RegistryRef(ZOTHost, testRepo, foobar.Tag) CopyZOTRepo(ImageRepo, testRepo) // test - ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)). + ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.Ref}}"). WithWorkDir(tempDir). - MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec() + MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec().Out.Contents() // validate - var index ocispec.Index - bytes := ORAS("discover", 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("application/vnd.oci.image.manifest.v1+json")) + out := ORAS("discover", subjectRef, "--format", "{{range .Manifests}}{{println .Ref}}{{end}}").Exec().Out + Expect(out).To(gbytes.Say(string(ref))) }) It("should attach file with path validation disabled", func() { @@ -204,16 +195,12 @@ var _ = Describe("1.0 registry users:", func() { subjectRef := RegistryRef(FallbackHost, testRepo, foobar.Tag) prepare(RegistryRef(FallbackHost, ArtifactRepo, foobar.Tag), subjectRef) // test - ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)). + ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.Ref}}"). WithWorkDir(tempDir). - MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec() - + MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec().Out.Contents() // validate - var index ocispec.Index - bytes := ORAS("discover", 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("application/vnd.oci.image.manifest.v1+json")) + out := ORAS("discover", subjectRef, "--format", "{{range .Manifests}}{{println .Ref}}{{end}}").Exec().Out + Expect(out).To(gbytes.Say(string(ref))) }) It("should attach a file via a OCI Image by default", func() { @@ -222,16 +209,13 @@ var _ = Describe("1.0 registry users:", func() { subjectRef := RegistryRef(FallbackHost, testRepo, foobar.Tag) prepare(RegistryRef(FallbackHost, ArtifactRepo, foobar.Tag), subjectRef) // test - ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)). + ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.Ref}}"). WithWorkDir(tempDir). - MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec() + MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec().Out.Contents() // validate - var index ocispec.Index - bytes := ORAS("discover", 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("application/vnd.oci.image.manifest.v1+json")) + out := ORAS("discover", subjectRef, "--format", "{{range .Manifests}}{{println .Ref}}{{end}}").Exec().Out + Expect(out).To(gbytes.Say(string(ref))) }) It("should attach a file via a OCI Image and generate referrer via tag schema", func() { @@ -240,16 +224,13 @@ var _ = Describe("1.0 registry users:", func() { subjectRef := RegistryRef(FallbackHost, testRepo, foobar.Tag) prepare(RegistryRef(FallbackHost, ArtifactRepo, foobar.Tag), subjectRef) // test - ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--distribution-spec", "v1.1-referrers-tag"). + ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--distribution-spec", "v1.1-referrers-tag", "--format", "{{.Ref}}"). WithWorkDir(tempDir). - MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec() + MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec().Out.Contents() // validate - var index ocispec.Index - bytes := ORAS("discover", subjectRef, "--distribution-spec", "v1.1-referrers-tag", "-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("application/vnd.oci.image.manifest.v1+json")) + out := ORAS("discover", subjectRef, "--format", "{{range .Manifests}}{{println .Ref}}{{end}}").Exec().Out + Expect(out).To(gbytes.Say(string(ref))) }) }) }) @@ -270,32 +251,24 @@ var _ = Describe("OCI image layout users:", func() { root := PrepareTempOCI(ImageRepo) subjectRef := LayoutRef(root, foobar.Tag) // test - ORAS("attach", "--artifact-type", "test/attach", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--export-manifest", exportName). + ref := ORAS("attach", "--artifact-type", "test/attach", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--export-manifest", exportName, "--format", "{{.Ref}}"). WithWorkDir(root). - MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec() + MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec().Out.Contents() // 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("application/vnd.oci.image.manifest.v1+json")) - fetched := ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, index.Manifests[0].Digest.String())).Exec().Out.Contents() + fetched := ORAS("manifest", "fetch", Flags.Layout, string(ref)).Exec().Out.Contents() MatchFile(filepath.Join(root, exportName), string(fetched), DefaultTimeout) }) It("should attach a file via a OCI Image", func() { root := PrepareTempOCI(ImageRepo) subjectRef := LayoutRef(root, foobar.Tag) // test - ORAS("attach", "--artifact-type", "test/attach", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)). + ref := 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() + MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec().Out.Contents() // 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("application/vnd.oci.image.manifest.v1+json")) + out := ORAS("discover", subjectRef, "--format", "{{range .Manifests}}{{println .Ref}}{{end}}").Exec().Out + Expect(out).To(gbytes.Say(string(ref))) }) }) })