From b2ecfab91d093f9dfacf735f169ad2e75845ce48 Mon Sep 17 00:00:00 2001 From: wangxiaoxuan273 Date: Wed, 15 Mar 2023 08:53:39 +0000 Subject: [PATCH 1/3] test: add e2e tests for manifest fetch-config under oci-layout Signed-off-by: wangxiaoxuan273 --- test/e2e/suite/command/manifest.go | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/e2e/suite/command/manifest.go b/test/e2e/suite/command/manifest.go index ffd134d93..cdc9b959b 100644 --- a/test/e2e/suite/command/manifest.go +++ b/test/e2e/suite/command/manifest.go @@ -488,3 +488,47 @@ var _ = Describe("OCI image layout users:", func() { }) }) }) + +var _ = Describe("OCI image layout users:", func() { + prepare := func(from string, tag string) string { + tmpRoot := GinkgoT().TempDir() + cpPath := tmpRoot + if tag != "" { + cpPath = fmt.Sprintf("%s:%s", tmpRoot, tag) + } + ORAS("cp", from, Flags.ToLayout, cpPath).WithDescription("prepare image from registry to OCI layout").Exec() + return tmpRoot + } + When("running `manifest fetch-config`", func() { + It("should fetch a config via a tag", func() { + root := prepare(RegistryRef(Host, ImageRepo, foobar.Digest), foobar.Tag) + ORAS("manifest", "fetch-config", Flags.Layout, LayoutRef(root, foobar.Tag)). + MatchContent("{}").Exec() + }) + It("should fetch a config descriptor via a tag", func() { + root := prepare(RegistryRef(Host, ImageRepo, foobar.Digest), foobar.Tag) + ORAS("manifest", "fetch-config", "--descriptor", Flags.Layout, LayoutRef(root, foobar.Tag)). + MatchContent(foobar.ImageConfigDesc).Exec() + }) + It("should fetch a config via digest", func() { + root := prepare(RegistryRef(Host, ImageRepo, foobar.Digest), foobar.Tag) + ORAS("manifest", "fetch-config", Flags.Layout, LayoutRef(root, foobar.Digest)). + MatchContent("{}").Exec() + }) + It("should fetch a config descriptor via a digest", func() { + root := prepare(RegistryRef(Host, ImageRepo, foobar.Digest), foobar.Tag) + ORAS("manifest", "fetch-config", "--descriptor", Flags.Layout, LayoutRef(root, foobar.Digest)). + MatchContent(foobar.ImageConfigDesc).Exec() + }) + It("should fetch a config of a specific platform", func() { + root := prepare(RegistryRef(Host, ImageRepo, multi_arch.Digest), multi_arch.Tag) + ORAS("manifest", "fetch-config", "--platform", "linux/amd64", Flags.Layout, LayoutRef(root, multi_arch.Tag)). + MatchContent(multi_arch.LinuxAMD64Config).Exec() + }) + It("should fetch a config descriptor of a specific platform", func() { + root := prepare(RegistryRef(Host, ImageRepo, multi_arch.Digest), multi_arch.Tag) + ORAS("manifest", "fetch-config", "--descriptor", "--platform", "linux/amd64", Flags.Layout, LayoutRef(root, multi_arch.Tag)). + MatchContent(multi_arch.LinuxAMD64ConfigDesc).Exec() + }) + }) +}) From 43d2f74f1f6788dfd4dd100190fec345216982d9 Mon Sep 17 00:00:00 2001 From: wangxiaoxuan273 Date: Wed, 15 Mar 2023 09:38:47 +0000 Subject: [PATCH 2/3] rebase Signed-off-by: wangxiaoxuan273 --- test/e2e/suite/command/manifest.go | 34 ++++++++++++------------------ 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/test/e2e/suite/command/manifest.go b/test/e2e/suite/command/manifest.go index cdc9b959b..7a62f5754 100644 --- a/test/e2e/suite/command/manifest.go +++ b/test/e2e/suite/command/manifest.go @@ -369,13 +369,12 @@ var _ = Describe("Common registry users:", func() { }) var _ = Describe("OCI image layout users:", func() { - prepare := func() string { - tmp := GinkgoT().TempDir() - ORAS("cp", RegistryRef(Host, ImageRepo, multi_arch.Digest), Flags.ToLayout, LayoutRef(tmp, multi_arch.Tag)).WithDescription("prepare image from registry to OCI layout").Exec() - return tmp - } - When("running `manifest fetch`", func() { + prepare := func() string { + tmp := GinkgoT().TempDir() + ORAS("cp", RegistryRef(Host, ImageRepo, multi_arch.Digest), Flags.ToLayout, LayoutRef(tmp, multi_arch.Tag)).WithDescription("prepare image from registry to OCI layout").Exec() + return tmp + } It("should fetch manifest list with digest", func() { root := prepare() ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.Digest)). @@ -462,7 +461,6 @@ var _ = Describe("OCI image layout users:", func() { "--platform", "linux/amd64", "--media-type", "application/vnd.oci.image.index.v1+json,application/vnd.oci.image.manifest.v1+json", "--descriptor"). MatchContent(multi_arch.LinuxAMD64IndexDesc).Exec() }) - It("should fetch image descriptor with media type assertion and platform selection", func() { root := prepare() ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.Tag), @@ -472,14 +470,12 @@ var _ = Describe("OCI image layout users:", func() { "--platform", "linux/amd64", "--media-type", "application/vnd.oci.image.index.v1+json,application/vnd.oci.image.manifest.v1+json", "--descriptor"). MatchContent(multi_arch.LinuxAMD64IndexDesc).Exec() }) - It("should fetch image content with media type assertion and platform validation", func() { root := prepare() ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.LinuxAMD64.Digest.String()), "--platform", "linux/amd64", "--media-type", "application/vnd.oci.image.manifest.v1+json"). MatchContent(multi_arch.LinuxAMD64Manifest).Exec() }) - It("should fetch image descriptor with media type assertion and platform validation", func() { root := prepare() ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.LinuxAMD64.Digest.String()), @@ -487,19 +483,17 @@ var _ = Describe("OCI image layout users:", func() { MatchContent(multi_arch.LinuxAMD64DescStr).Exec() }) }) -}) -var _ = Describe("OCI image layout users:", func() { - prepare := func(from string, tag string) string { - tmpRoot := GinkgoT().TempDir() - cpPath := tmpRoot - if tag != "" { - cpPath = fmt.Sprintf("%s:%s", tmpRoot, tag) - } - ORAS("cp", from, Flags.ToLayout, cpPath).WithDescription("prepare image from registry to OCI layout").Exec() - return tmpRoot - } When("running `manifest fetch-config`", func() { + prepare := func(from string, tag string) string { + tmpRoot := GinkgoT().TempDir() + cpPath := tmpRoot + if tag != "" { + cpPath = fmt.Sprintf("%s:%s", tmpRoot, tag) + } + ORAS("cp", from, Flags.ToLayout, cpPath).WithDescription("prepare image from registry to OCI layout").Exec() + return tmpRoot + } It("should fetch a config via a tag", func() { root := prepare(RegistryRef(Host, ImageRepo, foobar.Digest), foobar.Tag) ORAS("manifest", "fetch-config", Flags.Layout, LayoutRef(root, foobar.Tag)). From 402ea6bc3f36f85b0f8d31d19a3b0080286b2170 Mon Sep 17 00:00:00 2001 From: wangxiaoxuan273 Date: Thu, 16 Mar 2023 05:19:18 +0000 Subject: [PATCH 3/3] resolved comments Signed-off-by: wangxiaoxuan273 --- test/e2e/suite/command/manifest.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/test/e2e/suite/command/manifest.go b/test/e2e/suite/command/manifest.go index 7a62f5754..3e3f0d2cc 100644 --- a/test/e2e/suite/command/manifest.go +++ b/test/e2e/suite/command/manifest.go @@ -482,47 +482,55 @@ var _ = Describe("OCI image layout users:", func() { "--platform", "linux/amd64", "--media-type", "application/vnd.oci.image.manifest.v1+json", "--descriptor"). MatchContent(multi_arch.LinuxAMD64DescStr).Exec() }) + It("should fail fetching manifest without reference provided", func() { + root := prepare() + ORAS("manifest", "fetch", Flags.Layout, root).ExpectFailure(). + MatchErrKeyWords("Error:").Exec() + }) }) When("running `manifest fetch-config`", func() { - prepare := func(from string, tag string) string { + prepare := func(tag string) string { tmpRoot := GinkgoT().TempDir() cpPath := tmpRoot - if tag != "" { - cpPath = fmt.Sprintf("%s:%s", tmpRoot, tag) - } + from := RegistryRef(Host, ImageRepo, tag) + cpPath = fmt.Sprintf("%s:%s", tmpRoot, tag) ORAS("cp", from, Flags.ToLayout, cpPath).WithDescription("prepare image from registry to OCI layout").Exec() return tmpRoot } It("should fetch a config via a tag", func() { - root := prepare(RegistryRef(Host, ImageRepo, foobar.Digest), foobar.Tag) + root := prepare(foobar.Tag) ORAS("manifest", "fetch-config", Flags.Layout, LayoutRef(root, foobar.Tag)). MatchContent("{}").Exec() }) It("should fetch a config descriptor via a tag", func() { - root := prepare(RegistryRef(Host, ImageRepo, foobar.Digest), foobar.Tag) + root := prepare(foobar.Tag) ORAS("manifest", "fetch-config", "--descriptor", Flags.Layout, LayoutRef(root, foobar.Tag)). MatchContent(foobar.ImageConfigDesc).Exec() }) It("should fetch a config via digest", func() { - root := prepare(RegistryRef(Host, ImageRepo, foobar.Digest), foobar.Tag) + root := prepare(foobar.Tag) ORAS("manifest", "fetch-config", Flags.Layout, LayoutRef(root, foobar.Digest)). MatchContent("{}").Exec() }) It("should fetch a config descriptor via a digest", func() { - root := prepare(RegistryRef(Host, ImageRepo, foobar.Digest), foobar.Tag) + root := prepare(foobar.Tag) ORAS("manifest", "fetch-config", "--descriptor", Flags.Layout, LayoutRef(root, foobar.Digest)). MatchContent(foobar.ImageConfigDesc).Exec() }) It("should fetch a config of a specific platform", func() { - root := prepare(RegistryRef(Host, ImageRepo, multi_arch.Digest), multi_arch.Tag) + root := prepare(multi_arch.Tag) ORAS("manifest", "fetch-config", "--platform", "linux/amd64", Flags.Layout, LayoutRef(root, multi_arch.Tag)). MatchContent(multi_arch.LinuxAMD64Config).Exec() }) It("should fetch a config descriptor of a specific platform", func() { - root := prepare(RegistryRef(Host, ImageRepo, multi_arch.Digest), multi_arch.Tag) + root := prepare(multi_arch.Tag) ORAS("manifest", "fetch-config", "--descriptor", "--platform", "linux/amd64", Flags.Layout, LayoutRef(root, multi_arch.Tag)). MatchContent(multi_arch.LinuxAMD64ConfigDesc).Exec() }) + It("should fail if no manifest reference provided", func() { + root := prepare(foobar.Tag) + ORAS("manifest", "fetch-config", Flags.Layout, root).ExpectFailure().Exec() + }) }) })