2018-03-22 01:10:08 +00:00
|
|
|
package contentutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/containerd/containerd/content"
|
|
|
|
digest "github.com/opencontainers/go-digest"
|
2021-07-26 08:53:30 +00:00
|
|
|
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
|
2018-03-22 01:10:08 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCopy(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
ctx := context.TODO()
|
|
|
|
|
|
|
|
b0 := NewBuffer()
|
|
|
|
b1 := NewBuffer()
|
|
|
|
|
2021-07-26 08:53:30 +00:00
|
|
|
err := content.WriteBlob(ctx, b0, "foo", bytes.NewBuffer([]byte("foobar")), ocispecs.Descriptor{Size: -1})
|
2018-03-22 01:10:08 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-26 08:53:30 +00:00
|
|
|
err = Copy(ctx, b1, b0, ocispecs.Descriptor{Digest: digest.FromBytes([]byte("foobar")), Size: -1}, "", nil)
|
2018-03-22 01:10:08 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-26 08:53:30 +00:00
|
|
|
dt, err := content.ReadBlob(ctx, b1, ocispecs.Descriptor{Digest: digest.FromBytes([]byte("foobar"))})
|
2018-03-22 01:10:08 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, string(dt), "foobar")
|
|
|
|
}
|