|
|
|
@ -58,7 +58,7 @@ func testMultipleObjectCreation(c *check.C, create func() Storage) { |
|
|
|
|
} |
|
|
|
|
key := "obj" + strconv.Itoa(i) |
|
|
|
|
objects[key] = []byte(randomString) |
|
|
|
|
err := storage.StoreObject("bucket", key, "", bytes.NewBufferString(randomString)) |
|
|
|
|
err := storage.CreateObject("bucket", key, "", bytes.NewBufferString(randomString)) |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -66,7 +66,7 @@ func testMultipleObjectCreation(c *check.C, create func() Storage) { |
|
|
|
|
etags := make(map[string]string) |
|
|
|
|
for key, value := range objects { |
|
|
|
|
var byteBuffer bytes.Buffer |
|
|
|
|
storage.CopyObjectToWriter(&byteBuffer, "bucket", key) |
|
|
|
|
storage.GetObject(&byteBuffer, "bucket", key) |
|
|
|
|
c.Assert(bytes.Equal(value, byteBuffer.Bytes()), check.Equals, true) |
|
|
|
|
|
|
|
|
|
metadata, err := storage.GetObjectMetadata("bucket", key, "") |
|
|
|
@ -90,7 +90,7 @@ func testPaging(c *check.C, create func() Storage) { |
|
|
|
|
// check before paging occurs
|
|
|
|
|
for i := 0; i < 5; i++ { |
|
|
|
|
key := "obj" + strconv.Itoa(i) |
|
|
|
|
storage.StoreObject("bucket", key, "", bytes.NewBufferString(key)) |
|
|
|
|
storage.CreateObject("bucket", key, "", bytes.NewBufferString(key)) |
|
|
|
|
resources.Maxkeys = 5 |
|
|
|
|
objects, resources, err = storage.ListObjects("bucket", resources) |
|
|
|
|
c.Assert(len(objects), check.Equals, i+1) |
|
|
|
@ -100,7 +100,7 @@ func testPaging(c *check.C, create func() Storage) { |
|
|
|
|
// check after paging occurs pages work
|
|
|
|
|
for i := 6; i <= 10; i++ { |
|
|
|
|
key := "obj" + strconv.Itoa(i) |
|
|
|
|
storage.StoreObject("bucket", key, "", bytes.NewBufferString(key)) |
|
|
|
|
storage.CreateObject("bucket", key, "", bytes.NewBufferString(key)) |
|
|
|
|
resources.Maxkeys = 5 |
|
|
|
|
objects, resources, err = storage.ListObjects("bucket", resources) |
|
|
|
|
c.Assert(len(objects), check.Equals, 5) |
|
|
|
@ -109,8 +109,8 @@ func testPaging(c *check.C, create func() Storage) { |
|
|
|
|
} |
|
|
|
|
// check paging with prefix at end returns less objects
|
|
|
|
|
{ |
|
|
|
|
storage.StoreObject("bucket", "newPrefix", "", bytes.NewBufferString("prefix1")) |
|
|
|
|
storage.StoreObject("bucket", "newPrefix2", "", bytes.NewBufferString("prefix2")) |
|
|
|
|
storage.CreateObject("bucket", "newPrefix", "", bytes.NewBufferString("prefix1")) |
|
|
|
|
storage.CreateObject("bucket", "newPrefix2", "", bytes.NewBufferString("prefix2")) |
|
|
|
|
resources.Prefix = "new" |
|
|
|
|
resources.Maxkeys = 5 |
|
|
|
|
objects, resources, err = storage.ListObjects("bucket", resources) |
|
|
|
@ -131,8 +131,8 @@ func testPaging(c *check.C, create func() Storage) { |
|
|
|
|
|
|
|
|
|
// check delimited results with delimiter and prefix
|
|
|
|
|
{ |
|
|
|
|
storage.StoreObject("bucket", "this/is/delimited", "", bytes.NewBufferString("prefix1")) |
|
|
|
|
storage.StoreObject("bucket", "this/is/also/delimited", "", bytes.NewBufferString("prefix2")) |
|
|
|
|
storage.CreateObject("bucket", "this/is/delimited", "", bytes.NewBufferString("prefix1")) |
|
|
|
|
storage.CreateObject("bucket", "this/is/also/delimited", "", bytes.NewBufferString("prefix2")) |
|
|
|
|
var prefixes []string |
|
|
|
|
resources.CommonPrefixes = prefixes // allocate new everytime
|
|
|
|
|
resources.Delimiter = "/" |
|
|
|
@ -184,12 +184,12 @@ func testPaging(c *check.C, create func() Storage) { |
|
|
|
|
func testObjectOverwriteFails(c *check.C, create func() Storage) { |
|
|
|
|
storage := create() |
|
|
|
|
storage.CreateBucket("bucket") |
|
|
|
|
err := storage.StoreObject("bucket", "object", "", bytes.NewBufferString("one")) |
|
|
|
|
err := storage.CreateObject("bucket", "object", "", bytes.NewBufferString("one")) |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
|
err = storage.StoreObject("bucket", "object", "", bytes.NewBufferString("three")) |
|
|
|
|
err = storage.CreateObject("bucket", "object", "", bytes.NewBufferString("three")) |
|
|
|
|
c.Assert(err, check.Not(check.IsNil)) |
|
|
|
|
var bytesBuffer bytes.Buffer |
|
|
|
|
length, err := storage.CopyObjectToWriter(&bytesBuffer, "bucket", "object") |
|
|
|
|
length, err := storage.GetObject(&bytesBuffer, "bucket", "object") |
|
|
|
|
c.Assert(length, check.Equals, int64(len("one"))) |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
|
c.Assert(string(bytesBuffer.Bytes()), check.Equals, "one") |
|
|
|
@ -197,7 +197,7 @@ func testObjectOverwriteFails(c *check.C, create func() Storage) { |
|
|
|
|
|
|
|
|
|
func testNonExistantBucketOperations(c *check.C, create func() Storage) { |
|
|
|
|
storage := create() |
|
|
|
|
err := storage.StoreObject("bucket", "object", "", bytes.NewBufferString("one")) |
|
|
|
|
err := storage.CreateObject("bucket", "object", "", bytes.NewBufferString("one")) |
|
|
|
|
c.Assert(err, check.Not(check.IsNil)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -213,10 +213,10 @@ func testPutObjectInSubdir(c *check.C, create func() Storage) { |
|
|
|
|
storage := create() |
|
|
|
|
err := storage.CreateBucket("bucket") |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
|
err = storage.StoreObject("bucket", "dir1/dir2/object", "", bytes.NewBufferString("hello world")) |
|
|
|
|
err = storage.CreateObject("bucket", "dir1/dir2/object", "", bytes.NewBufferString("hello world")) |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
|
var bytesBuffer bytes.Buffer |
|
|
|
|
length, err := storage.CopyObjectToWriter(&bytesBuffer, "bucket", "dir1/dir2/object") |
|
|
|
|
length, err := storage.GetObject(&bytesBuffer, "bucket", "dir1/dir2/object") |
|
|
|
|
c.Assert(len(bytesBuffer.Bytes()), check.Equals, len("hello world")) |
|
|
|
|
c.Assert(int64(len(bytesBuffer.Bytes())), check.Equals, length) |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
@ -286,7 +286,7 @@ func testNonExistantObjectInBucket(c *check.C, create func() Storage) { |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
|
|
|
|
|
|
var byteBuffer bytes.Buffer |
|
|
|
|
length, err := storage.CopyObjectToWriter(&byteBuffer, "bucket", "dir1") |
|
|
|
|
length, err := storage.GetObject(&byteBuffer, "bucket", "dir1") |
|
|
|
|
c.Assert(length, check.Equals, int64(0)) |
|
|
|
|
c.Assert(err, check.Not(check.IsNil)) |
|
|
|
|
c.Assert(len(byteBuffer.Bytes()), check.Equals, 0) |
|
|
|
@ -307,11 +307,11 @@ func testGetDirectoryReturnsObjectNotFound(c *check.C, create func() Storage) { |
|
|
|
|
err := storage.CreateBucket("bucket") |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
|
|
|
|
|
|
err = storage.StoreObject("bucket", "dir1/dir2/object", "", bytes.NewBufferString("hello world")) |
|
|
|
|
err = storage.CreateObject("bucket", "dir1/dir2/object", "", bytes.NewBufferString("hello world")) |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
|
|
|
|
|
|
var byteBuffer bytes.Buffer |
|
|
|
|
length, err := storage.CopyObjectToWriter(&byteBuffer, "bucket", "dir1") |
|
|
|
|
length, err := storage.GetObject(&byteBuffer, "bucket", "dir1") |
|
|
|
|
c.Assert(length, check.Equals, int64(0)) |
|
|
|
|
switch err := err.(type) { |
|
|
|
|
case ObjectNotFound: |
|
|
|
@ -328,7 +328,7 @@ func testGetDirectoryReturnsObjectNotFound(c *check.C, create func() Storage) { |
|
|
|
|
c.Assert(len(byteBuffer.Bytes()), check.Equals, 0) |
|
|
|
|
|
|
|
|
|
var byteBuffer2 bytes.Buffer |
|
|
|
|
length, err = storage.CopyObjectToWriter(&byteBuffer, "bucket", "dir1/") |
|
|
|
|
length, err = storage.GetObject(&byteBuffer, "bucket", "dir1/") |
|
|
|
|
c.Assert(length, check.Equals, int64(0)) |
|
|
|
|
switch err := err.(type) { |
|
|
|
|
case ObjectNotFound: |
|
|
|
@ -351,19 +351,19 @@ func testDefaultContentType(c *check.C, create func() Storage) { |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
|
|
|
|
|
|
// test empty
|
|
|
|
|
err = storage.StoreObject("bucket", "one", "", bytes.NewBufferString("one")) |
|
|
|
|
err = storage.CreateObject("bucket", "one", "", bytes.NewBufferString("one")) |
|
|
|
|
metadata, err := storage.GetObjectMetadata("bucket", "one", "") |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
|
c.Assert(metadata.ContentType, check.Equals, "application/octet-stream") |
|
|
|
|
|
|
|
|
|
// test custom
|
|
|
|
|
storage.StoreObject("bucket", "two", "application/text", bytes.NewBufferString("two")) |
|
|
|
|
storage.CreateObject("bucket", "two", "application/text", bytes.NewBufferString("two")) |
|
|
|
|
metadata, err = storage.GetObjectMetadata("bucket", "two", "") |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
|
c.Assert(metadata.ContentType, check.Equals, "application/text") |
|
|
|
|
|
|
|
|
|
// test trim space
|
|
|
|
|
storage.StoreObject("bucket", "three", "\tapplication/json ", bytes.NewBufferString("three")) |
|
|
|
|
storage.CreateObject("bucket", "three", "\tapplication/json ", bytes.NewBufferString("three")) |
|
|
|
|
metadata, err = storage.GetObjectMetadata("bucket", "three", "") |
|
|
|
|
c.Assert(err, check.IsNil) |
|
|
|
|
c.Assert(metadata.ContentType, check.Equals, "application/json") |
|
|
|
|