Skip to content

Commit eaee9f5

Browse files
stevvooeAkihiroSuda
authored andcommitted
content/testsuite: include small blob test in standard suite
Signed-off-by: Stephen J Day <[email protected]> Signed-off-by: Akihiro Suda <[email protected]>
1 parent abef389 commit eaee9f5

2 files changed

Lines changed: 40 additions & 80 deletions

File tree

content/testsuite/provideringester.go

Lines changed: 0 additions & 76 deletions
This file was deleted.

content/testsuite/testsuite.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ func ContentSuite(t *testing.T, name string, storeFn func(ctx context.Context, r
3131
t.Run("ResumeCopy", makeTest(t, name, storeFn, checkResume(resumeCopy)))
3232
t.Run("ResumeCopySeeker", makeTest(t, name, storeFn, checkResume(resumeCopySeeker)))
3333
t.Run("ResumeCopyReaderAt", makeTest(t, name, storeFn, checkResume(resumeCopyReaderAt)))
34+
t.Run("SmallBlob", makeTest(t, name, storeFn, checkSmallBlob))
3435
t.Run("Labels", makeTest(t, name, storeFn, checkLabels))
35-
36-
t.Run("SmallBlob", makeTest(t, name, storeFn, func(ctx context.Context, t *testing.T, cs content.Store) {
37-
TestSmallBlob(ctx, t, cs)
38-
}))
3936
}
4037

4138
func makeTest(t *testing.T, name string, storeFn func(ctx context.Context, root string) (context.Context, content.Store, func() error, error), fn func(ctx context.Context, t *testing.T, cs content.Store)) func(t *testing.T) {
@@ -471,6 +468,45 @@ func resumeCopyReaderAt(ctx context.Context, w content.Writer, b []byte, _, size
471468
return errors.Wrap(content.Copy(ctx, w, r, size, dgst), "copy failed")
472469
}
473470

471+
// checkSmallBlob tests reading a blob which is smaller than the read size.
472+
func checkSmallBlob(ctx context.Context, t *testing.T, store content.Store) {
473+
blob := []byte(`foobar`)
474+
blobSize := int64(len(blob))
475+
blobDigest := digest.FromBytes(blob)
476+
// test write
477+
w, err := store.Writer(ctx, t.Name(), blobSize, blobDigest)
478+
if err != nil {
479+
t.Fatal(err)
480+
}
481+
if _, err := w.Write(blob); err != nil {
482+
t.Fatal(err)
483+
}
484+
if err := w.Commit(ctx, blobSize, blobDigest); err != nil {
485+
t.Fatal(err)
486+
}
487+
if err := w.Close(); err != nil {
488+
t.Fatal(err)
489+
}
490+
// test read.
491+
readSize := blobSize + 1
492+
ra, err := store.ReaderAt(ctx, blobDigest)
493+
if err != nil {
494+
t.Fatal(err)
495+
}
496+
r := io.NewSectionReader(ra, 0, readSize)
497+
b, err := ioutil.ReadAll(r)
498+
if err != nil {
499+
t.Fatal(err)
500+
}
501+
if err := ra.Close(); err != nil {
502+
t.Fatal(err)
503+
}
504+
d := digest.FromBytes(b)
505+
if blobDigest != d {
506+
t.Fatalf("expected %s (%q), got %s (%q)", blobDigest, string(blob),
507+
d, string(b))
508+
}
509+
}
474510
func checkStatus(t *testing.T, w content.Writer, expected content.Status, d digest.Digest, preStart, postStart, preUpdate, postUpdate time.Time) {
475511
t.Helper()
476512
st, err := w.Status()

0 commit comments

Comments
 (0)