Merge pull request #115 from fkautz/pr_out_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:46 -08:00
commit afd574af20
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) {
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

View File

@ -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)
}