Skip to content

Commit

Permalink
Merge branch 'main' into output-output
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoxuan Wang committed Nov 11, 2024
2 parents 97ba0a1 + b8db531 commit b3709ff
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 56 deletions.
9 changes: 9 additions & 0 deletions cmd/oras/internal/option/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (opts *Target) AnnotatedReference() string {
func (opts *Target) applyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description string) {
flagPrefix, notePrefix := applyPrefix(prefix, description)
fs.BoolVarP(&opts.IsOCILayout, flagPrefix+"oci-layout", "", false, "set "+notePrefix+"target as an OCI image layout")
fs.StringVar(&opts.Path, flagPrefix+"oci-layout-path", "", "set the path for the "+notePrefix+"OCI image layout target")
}

// ApplyFlagsWithPrefix applies flags to a command flag set with a prefix string.
Expand All @@ -96,13 +97,21 @@ func (opts *Target) ApplyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description

// Parse gets target options from user input.
func (opts *Target) Parse(cmd *cobra.Command) error {
if err := oerrors.CheckMutuallyExclusiveFlags(cmd.Flags(), opts.flagPrefix+"oci-layout-path", opts.flagPrefix+"oci-layout"); err != nil {
return err
}

switch {
case opts.IsOCILayout:
opts.Type = TargetTypeOCILayout
if len(opts.headerFlags) != 0 {
return errors.New("custom header flags cannot be used on an OCI image layout target")
}
return opts.parseOCILayoutReference()
case opts.Path != "":
opts.Type = TargetTypeOCILayout
opts.Reference = opts.RawReference
return nil
default:
opts.Type = TargetTypeRemote
if ref, err := registry.ParseReference(opts.RawReference); err != nil {
Expand Down
42 changes: 40 additions & 2 deletions cmd/oras/internal/option/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/http"
"net/url"
"reflect"
"strings"
"testing"

"github.com/spf13/cobra"
Expand All @@ -28,9 +29,26 @@ import (
oerrors "oras.land/oras/cmd/oras/internal/errors"
)

func TestTarget_Parse_oci_path(t *testing.T) {
opts := Target{
Path: "foo",
RawReference: "mocked/test",
}
cmd := &cobra.Command{}
ApplyFlags(&opts, cmd.Flags())
if err := opts.Parse(cmd); err != nil {
t.Errorf("Target.Parse() error = %v", err)
}
if opts.Type != TargetTypeOCILayout {
t.Errorf("Target.Parse() failed, got %q, want %q", opts.Type, TargetTypeOCILayout)
}
}

func TestTarget_Parse_oci(t *testing.T) {
opts := Target{IsOCILayout: true}
err := opts.Parse(nil)
cmd := &cobra.Command{}
ApplyFlags(&opts, cmd.Flags())
err := opts.Parse(cmd)
if !errors.Is(err, errdef.ErrInvalidReference) {
t.Errorf("Target.Parse() error = %v, expect %v", err, errdef.ErrInvalidReference)
}
Expand All @@ -39,6 +57,24 @@ func TestTarget_Parse_oci(t *testing.T) {
}
}

func TestTarget_Parse_oci_and_oci_path(t *testing.T) {
opts := Target{}
cmd := &cobra.Command{}
opts.ApplyFlags(cmd.Flags())
cmd.SetArgs([]string{"--oci-layout", "foo", "--oci-layout-path", "foo"})
if err := cmd.Execute(); err != nil {
t.Errorf("cmd.Execute() error = %v", err)
}
err := opts.Parse(cmd)
if err == nil {
t.Errorf("expect Target.Parse() to fail but not")
}
if !strings.Contains(err.Error(), "cannot be used at the same time") {
t.Errorf("expect error message to contain 'cannot be used at the same time' but not")
}

}

func TestTarget_Parse_remote(t *testing.T) {
opts := Target{
RawReference: "mocked/test",
Expand All @@ -59,7 +95,9 @@ func TestTarget_Parse_remote_err(t *testing.T) {
RawReference: "/test",
IsOCILayout: false,
}
if err := opts.Parse(nil); err == nil {
cmd := &cobra.Command{}
ApplyFlags(&opts, cmd.Flags())
if err := opts.Parse(cmd); err == nil {
t.Errorf("expect Target.Parse() to fail but not")
}
}
Expand Down
8 changes: 5 additions & 3 deletions cmd/oras/root/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,13 @@ func runPush(cmd *cobra.Command, opts *pushOptions) error {
if err != nil {
return err
}
mediaType := oras.MediaTypeUnknownConfig
if opts.Flag == option.ImageSpecV1_0 && opts.artifactType != "" {
mediaType = opts.artifactType
return &oerrors.Error{
Err: errors.New(`artifact type cannot be customized for OCI image-spec v1.0 when platform is specified`),
Recommendation: "consider using image spec v1.1 or remove --artifact-type",
}
}
desc := content.NewDescriptorFromBytes(mediaType, blob)
desc := content.NewDescriptorFromBytes(ocispec.MediaTypeImageConfig, blob)
err = store.Push(ctx, desc, bytes.NewReader(blob))
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
golang.org/x/sync v0.8.0
golang.org/x/term v0.25.0
golang.org/x/sync v0.9.0
golang.org/x/term v0.26.0
gopkg.in/yaml.v3 v3.0.1
oras.land/oras-go/v2 v2.5.0
)
Expand All @@ -29,5 +29,5 @@ require (
github.com/shopspring/decimal v1.4.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/sys v0.27.0 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module oras.land/oras/test/e2e
go 1.23.0

require (
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/onsi/ginkgo/v2 v2.21.0
github.com/onsi/gomega v1.35.1
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -15,11 +15,11 @@ require (
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 // indirect
golang.org/x/net v0.28.0 // indirect
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/tools v0.26.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
32 changes: 16 additions & 16 deletions test/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 h1:5iH8iuqE5apketRbSFBy+X1V0o+l+8NF1avt4HWl7cA=
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4=
github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5coaZoE2ag=
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc=
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo=
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM=
github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
Expand All @@ -20,18 +20,18 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/internal/testdata/foobar/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
PlatformConfigSize = 38
PlatformConfigDigest = digest.Digest("sha256:e94c0ba80a1157ffab5b5c6656fffc089c6446c7ed0604f3382910d1ef7dd40d")
PlatformConfigStateKey = match.StateKey{
Digest: "e94c0ba80a11", Name: "application/vnd.unknown.config.v1+json",
Digest: "e94c0ba80a11", Name: "application/vnd.oci.image.config.v1+json",
}

PlatformV10ConfigSize = 38
Expand All @@ -50,7 +50,7 @@ var (
Digest: "e94c0ba80a11", Name: "test/artifact+json",
}
PlatformV1DEfaultConfigStateKey = match.StateKey{
Digest: "e94c0ba80a11", Name: "application/vnd.unknown.config.v1+json",
Digest: "e94c0ba80a11", Name: "application/vnd.oci.image.config.v1+json",
}

FileBarName = "foobar/bar"
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/internal/utils/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ var (
Layout string
FromLayout string
ToLayout string
FromLayoutPath string
ToLayoutPath string
DistributionSpec string
ImageSpec string
}{
"--oci-layout",
"--from-oci-layout",
"--to-oci-layout",
"--from-oci-layout-path",
"--to-oci-layout-path",
"--distribution-spec",
"--image-spec",
}
Expand Down
87 changes: 86 additions & 1 deletion test/e2e/suite/command/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ var _ = Describe("OCI layout users:", func() {

It("should copy an image from a registry to an OCI image layout via digest", func() {
dstDir := GinkgoT().TempDir()
src := RegistryRef(ZOTHost, ImageRepo, foobar.Tag)
src := RegistryRef(ZOTHost, ImageRepo, foobar.Digest)
ORAS("cp", src, dstDir, "-v", Flags.ToLayout).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
// validate
srcManifest := ORAS("manifest", "fetch", src).WithDescription("fetch from source to validate").Exec().Out.Contents()
Expand Down Expand Up @@ -625,6 +625,91 @@ var _ = Describe("OCI layout users:", func() {
Expect(len(index.Manifests)).To(Equal(1))
Expect(index.Manifests[0].Digest.String()).To(Equal(ma.LinuxAMD64Referrer.Digest.String()))
})

// oci-layout-path tests

It("should copy an image from a registry to an OCI image layout via tag using --oci-layout-path", func() {
layoutDir := GinkgoT().TempDir()
src := RegistryRef(ZOTHost, ImageRepo, foobar.Tag)
ref := "copied"
dst := LayoutRef(layoutDir, ref)
ORAS("cp", src, ref, "-v", Flags.ToLayoutPath, layoutDir).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
// validate
srcManifest := ORAS("manifest", "fetch", src).WithDescription("fetch from source to validate").Exec().Out.Contents()
dstManifest := ORAS("manifest", "fetch", dst, Flags.Layout).WithDescription("fetch from destination to validate").Exec().Out.Contents()
Expect(srcManifest).To(Equal(dstManifest))
})

It("should copy an image from an OCI image layout to a registry via tag using --oci-layout-path", func() {
layoutDir := GinkgoT().TempDir()
ref := "copied"
src := LayoutRef(layoutDir, ref)
dst := RegistryRef(ZOTHost, cpTestRepo("from-layout-tag-path"), foobar.Tag)
// prepare
ORAS("cp", RegistryRef(ZOTHost, ImageRepo, foobar.Tag), src, Flags.ToLayout).Exec()
// test
ORAS("cp", ref, dst, "-v", Flags.FromLayoutPath, layoutDir).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
// validate
srcManifest := ORAS("manifest", "fetch", src, Flags.Layout).WithDescription("fetch from source to validate").Exec().Out.Contents()
dstManifest := ORAS("manifest", "fetch", dst).WithDescription("fetch from destination to validate").Exec().Out.Contents()
Expect(srcManifest).To(Equal(dstManifest))
})

It("should copy an image between OCI image layouts via tag using --oci-layout-path", func() {
srcDir := GinkgoT().TempDir()
toDir := GinkgoT().TempDir()
srcRef := "from"
dstRef := "to"
src := LayoutRef(srcDir, srcRef)
dst := LayoutRef(toDir, dstRef)
// prepare
ORAS("cp", RegistryRef(ZOTHost, ImageRepo, foobar.Tag), src, Flags.ToLayout).Exec()
// test
ORAS("cp", srcRef, dstRef, "-v", Flags.FromLayoutPath, srcDir, Flags.ToLayoutPath, toDir).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
// validate
srcManifest := ORAS("manifest", "fetch", src, Flags.Layout).WithDescription("fetch from source to validate").Exec().Out.Contents()
dstManifest := ORAS("manifest", "fetch", dst, Flags.Layout).WithDescription("fetch from destination to validate").Exec().Out.Contents()
Expect(srcManifest).To(Equal(dstManifest))
})

It("should copy an image from a registry to an OCI image layout via digest using --oci-layout-path", func() {
dstDir := GinkgoT().TempDir()
src := RegistryRef(ZOTHost, ImageRepo, foobar.Digest)
ORAS("cp", src, foobar.Digest, "-v", Flags.ToLayoutPath, dstDir).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
// validate
srcManifest := ORAS("manifest", "fetch", src).WithDescription("fetch from source to validate").Exec().Out.Contents()
dstManifest := ORAS("manifest", "fetch", LayoutRef(dstDir, foobar.Digest), Flags.Layout).WithDescription("fetch from destination to validate").Exec().Out.Contents()
Expect(srcManifest).To(Equal(dstManifest))
})

It("should copy an image from an OCI image layout to a registry via digest using --oci-layout-path", func() {
layoutDir := GinkgoT().TempDir()
src := LayoutRef(layoutDir, foobar.Digest)
dst := RegistryRef(ZOTHost, cpTestRepo("from-layout-digest-path"), "copied")
// prepare
ORAS("cp", RegistryRef(ZOTHost, ImageRepo, foobar.Tag), layoutDir, Flags.ToLayout).Exec()
// test
ORAS("cp", foobar.Digest, dst, "-v", Flags.FromLayoutPath, layoutDir).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
// validate
srcManifest := ORAS("manifest", "fetch", src, Flags.Layout).WithDescription("fetch from source to validate").Exec().Out.Contents()
dstManifest := ORAS("manifest", "fetch", dst).WithDescription("fetch from destination to validate").Exec().Out.Contents()
Expect(srcManifest).To(Equal(dstManifest))
})

It("should copy an image between OCI image layouts via digest", func() {
srcDir := GinkgoT().TempDir()
toDir := GinkgoT().TempDir()
src := LayoutRef(srcDir, foobar.Digest)
dst := LayoutRef(toDir, foobar.Digest)
// prepare
ORAS("cp", RegistryRef(ZOTHost, ImageRepo, foobar.Tag), srcDir, Flags.ToLayout).Exec()
// test
ORAS("cp", foobar.Digest, foobar.Digest, "-v", Flags.FromLayoutPath, srcDir, Flags.ToLayoutPath, toDir).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
// validate
srcManifest := ORAS("manifest", "fetch", src, Flags.Layout).WithDescription("fetch from source to validate").Exec().Out.Contents()
dstManifest := ORAS("manifest", "fetch", dst, Flags.Layout).WithDescription("fetch from destination to validate").Exec().Out.Contents()
Expect(srcManifest).To(Equal(dstManifest))
})
})
})

Expand Down
Loading

0 comments on commit b3709ff

Please sign in to comment.