Storage: blobwriter.Write/Seek test case
Signed-off-by: Arthur Baars <arthur@semmle.com>
This commit is contained in:
parent
6a248e115b
commit
586b3d47a7
@ -17,6 +17,39 @@ import (
|
|||||||
"github.com/docker/distribution/testutil"
|
"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
|
// TestSimpleBlobUpload covers the blob upload process, exercising common
|
||||||
// error paths that might be seen during an upload.
|
// error paths that might be seen during an upload.
|
||||||
func TestSimpleBlobUpload(t *testing.T) {
|
func TestSimpleBlobUpload(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user