diff --git a/pkg/storage/inmemory/inmemory.go b/pkg/storage/inmemory/inmemory.go index 241304458..bb3c9d673 100644 --- a/pkg/storage/inmemory/inmemory.go +++ b/pkg/storage/inmemory/inmemory.go @@ -88,6 +88,9 @@ func (storage *storage) StoreBucket(bucketName string) error { } func (storage *storage) ListObjects(bucket, prefix string, count int) ([]mstorage.ObjectMetadata, bool, error) { + if _, ok := storage.bucketdata[bucket]; ok == false { + return []mstorage.ObjectMetadata{}, false, mstorage.BucketNotFound{Bucket: bucket} + } // TODO prefix and count handling var results []mstorage.ObjectMetadata var keys []string diff --git a/pkg/storage/storage_api_suite.go b/pkg/storage/storage_api_suite.go index 5f5e916ca..f25ec33c1 100644 --- a/pkg/storage/storage_api_suite.go +++ b/pkg/storage/storage_api_suite.go @@ -2,6 +2,7 @@ package storage import ( "bytes" + "log" "math/rand" "strconv" @@ -18,6 +19,7 @@ func APITestSuite(c *C, create func() Storage) { testPutObjectInSubdir(c, create) testListBuckets(c, create) testListBucketsOrder(c, create) + testListObjectsTestsForNonExistantBucket(c, create) } func testCreateBucket(c *C, create func() Storage) { @@ -196,6 +198,8 @@ func testListBuckets(c *C, create func() Storage) { } func testListBucketsOrder(c *C, create func() Storage) { + // if implementation contains a map, order of map keys will vary. + // this ensures they return in the same order each time for i := 0; i < 10; i++ { storage := create() // add one and test exists @@ -209,3 +213,12 @@ func testListBucketsOrder(c *C, create func() Storage) { c.Assert(buckets[1].Name, Equals, "bucket2") } } + +func testListObjectsTestsForNonExistantBucket(c *C, create func() Storage) { + storage := create() + objects, isTruncated, err := storage.ListObjects("bucket", "", 1000) + log.Println("EH:", err) + c.Assert(err, Not(IsNil)) + c.Assert(isTruncated, Equals, false) + c.Assert(len(objects), Equals, 0) +}