Add testcase for commit already exist
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
83668f424f
commit
c0cb2f2568
@ -35,6 +35,7 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/content/testsuite"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/pkg/testutil"
|
||||
|
||||
"github.com/opencontainers/go-digest"
|
||||
@ -174,7 +175,9 @@ func TestContentWriter(t *testing.T) {
|
||||
|
||||
// now, attempt to write the same data again
|
||||
checkCopy(t, int64(len(p)), cw, bufio.NewReader(ioutil.NopCloser(bytes.NewReader(p))))
|
||||
if err := cw.Commit(ctx, int64(len(p)), expected); err != nil {
|
||||
if err := cw.Commit(ctx, int64(len(p)), expected); err == nil {
|
||||
t.Fatal("expected already exists error")
|
||||
} else if !errdefs.IsAlreadyExists(err) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/pkg/testutil"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
@ -41,6 +42,7 @@ import (
|
||||
func ContentSuite(t *testing.T, name string, storeFn func(ctx context.Context, root string) (context.Context, content.Store, func() error, error)) {
|
||||
t.Run("Writer", makeTest(t, name, storeFn, checkContentStoreWriter))
|
||||
t.Run("UpdateStatus", makeTest(t, name, storeFn, checkUpdateStatus))
|
||||
t.Run("CommitExists", makeTest(t, name, storeFn, checkCommitExists))
|
||||
t.Run("Resume", makeTest(t, name, storeFn, checkResumeWriter))
|
||||
t.Run("ResumeTruncate", makeTest(t, name, storeFn, checkResume(resumeTruncate)))
|
||||
t.Run("ResumeDiscard", makeTest(t, name, storeFn, checkResume(resumeDiscard)))
|
||||
@ -281,6 +283,39 @@ func checkResumeWriter(ctx context.Context, t *testing.T, cs content.Store) {
|
||||
}
|
||||
}
|
||||
|
||||
func checkCommitExists(ctx context.Context, t *testing.T, cs content.Store) {
|
||||
c1, d1 := createContent(256)
|
||||
if err := content.WriteBlob(ctx, cs, "c1", bytes.NewReader(c1), ocispec.Descriptor{Digest: d1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, tc := range []struct {
|
||||
expected digest.Digest
|
||||
}{
|
||||
{
|
||||
expected: d1,
|
||||
},
|
||||
{},
|
||||
} {
|
||||
w, err := cs.Writer(ctx, content.WithRef(fmt.Sprintf("c1-commitexists-%d", i)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := w.Write(c1); err != nil {
|
||||
w.Close()
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = w.Commit(ctx, int64(len(c1)), tc.expected)
|
||||
w.Close()
|
||||
if err == nil {
|
||||
t.Errorf("(%d) Expected already exists error", i)
|
||||
} else if !errdefs.IsAlreadyExists(err) {
|
||||
t.Fatalf("(%d) Unexpected error: %+v", i, err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func checkUpdateStatus(ctx context.Context, t *testing.T, cs content.Store) {
|
||||
c1, d1 := createContent(256)
|
||||
|
||||
@ -353,7 +388,7 @@ func checkUpdateStatus(ctx context.Context, t *testing.T, cs content.Store) {
|
||||
func checkLabels(ctx context.Context, t *testing.T, cs content.Store) {
|
||||
c1, d1 := createContent(256)
|
||||
|
||||
w1, err := cs.Writer(ctx, content.WithRef("c1"), content.WithDescriptor(ocispec.Descriptor{Size: 256, Digest: d1}))
|
||||
w1, err := cs.Writer(ctx, content.WithRef("c1-checklabels"), content.WithDescriptor(ocispec.Descriptor{Size: 256, Digest: d1}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user