Storage: blobwriter.Write/Seek test case
Signed-off-by: Arthur Baars <arthur@semmle.com>master
							parent
							
								
									9f83bfc071
								
							
						
					
					
						commit
						26e7268a86
					
				|  | @ -17,6 +17,39 @@ import ( | |||
| 	"github.com/docker/distribution/testutil" | ||||
| ) | ||||
| 
 | ||||
| // TestWriteSeek tests that the current file size can be
 | ||||
| // obtained using Seek
 | ||||
| func TestWriteSeek(t *testing.T) { | ||||
| 	ctx := context.Background() | ||||
| 	imageName := "foo/bar" | ||||
| 	driver := inmemory.New() | ||||
| 	registry, err := NewRegistry(ctx, driver, BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider()), EnableDelete, EnableRedirect) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("error creating registry: %v", err) | ||||
| 	} | ||||
| 	repository, err := registry.Repository(ctx, imageName) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error getting repo: %v", err) | ||||
| 	} | ||||
| 	bs := repository.Blobs(ctx) | ||||
| 
 | ||||
| 	blobUpload, err := bs.Create(ctx) | ||||
| 
 | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error starting layer upload: %s", err) | ||||
| 	} | ||||
| 	contents := []byte{1, 2, 3} | ||||
| 	blobUpload.Write(contents) | ||||
| 	offset, err := blobUpload.Seek(0, os.SEEK_CUR) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error in blobUpload.Seek: %s", err) | ||||
| 	} | ||||
| 	if offset != int64(len(contents)) { | ||||
| 		t.Fatalf("unexpected value for blobUpload offset:  %v != %v", offset, len(contents)) | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| // TestSimpleBlobUpload covers the blob upload process, exercising common
 | ||||
| // error paths that might be seen during an upload.
 | ||||
| func TestSimpleBlobUpload(t *testing.T) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue