@@ -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
4138func 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+ }
474510func 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