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

master
Frederick F. Kautz IV 10 years ago
parent be7c9aacf8
commit a092b44cf1
  1. 3
      pkg/storage/inmemory/inmemory.go
  2. 13
      pkg/storage/storage_api_suite.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) { 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

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

Loading…
Cancel
Save