Adding test to ensure list objects returns an error for non existant buckets to match previous bug fix and fix for inmemory

This commit is contained in:
Frederick F. Kautz IV 2015-02-01 10:48:31 -08:00
parent be7c9aacf8
commit a092b44cf1
2 changed files with 16 additions and 0 deletions

View File

@ -88,6 +88,9 @@ func (storage *storage) StoreBucket(bucketName string) error {
} }
func (storage *storage) ListObjects(bucket, prefix string, count int) ([]mstorage.ObjectMetadata, bool, 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 // TODO prefix and count handling
var results []mstorage.ObjectMetadata var results []mstorage.ObjectMetadata
var keys []string var keys []string

View File

@ -2,6 +2,7 @@ package storage
import ( import (
"bytes" "bytes"
"log"
"math/rand" "math/rand"
"strconv" "strconv"
@ -18,6 +19,7 @@ func APITestSuite(c *C, create func() Storage) {
testPutObjectInSubdir(c, create) testPutObjectInSubdir(c, create)
testListBuckets(c, create) testListBuckets(c, create)
testListBucketsOrder(c, create) testListBucketsOrder(c, create)
testListObjectsTestsForNonExistantBucket(c, create)
} }
func testCreateBucket(c *C, create func() Storage) { 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) { 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++ { for i := 0; i < 10; i++ {
storage := create() storage := create()
// add one and test exists // add one and test exists
@ -209,3 +213,12 @@ func testListBucketsOrder(c *C, create func() Storage) {
c.Assert(buckets[1].Name, Equals, "bucket2") 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)
}