mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Merge pull request #97 from fkautz/pr_out_adding_list_bucket_tests_and_fixing_inmemory_behavior
This commit is contained in:
commit
58da5c0f87
@ -112,10 +112,11 @@ func (storage *storage) ListObjects(bucket, prefix string, count int) ([]mstorag
|
||||
}
|
||||
|
||||
func (storage *storage) ListBuckets(prefix string) ([]mstorage.BucketMetadata, error) {
|
||||
// TODO prefix handling
|
||||
var results []mstorage.BucketMetadata
|
||||
for _, bucket := range storage.bucketdata {
|
||||
results = append(results, bucket.metadata)
|
||||
for key, bucket := range storage.bucketdata {
|
||||
if strings.HasPrefix(key, prefix) {
|
||||
results = append(results, bucket.metadata)
|
||||
}
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ func APITestSuite(c *C, create func() Storage) {
|
||||
testNonExistantBucketOperations(c, create)
|
||||
testBucketRecreateFails(c, create)
|
||||
testPutObjectInSubdir(c, create)
|
||||
testListBuckets(c, create)
|
||||
}
|
||||
|
||||
func testCreateBucket(c *C, create func() Storage) {
|
||||
@ -156,3 +157,39 @@ func testPutObjectInSubdir(c *C, create func() Storage) {
|
||||
c.Assert(int64(len(bytesBuffer.Bytes())), Equals, length)
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
func testListBuckets(c *C, create func() Storage) {
|
||||
storage := create()
|
||||
|
||||
// test empty list
|
||||
buckets, err := storage.ListBuckets("")
|
||||
c.Assert(len(buckets), Equals, 0)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
// add one and test exists
|
||||
err = storage.StoreBucket("bucket1")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
buckets, err = storage.ListBuckets("")
|
||||
c.Assert(len(buckets), Equals, 1)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
// add two and test exists
|
||||
err = storage.StoreBucket("bucket2")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
buckets, err = storage.ListBuckets("")
|
||||
c.Assert(len(buckets), Equals, 2)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
// add three and test exists + prefix
|
||||
err = storage.StoreBucket("bucket22")
|
||||
|
||||
buckets, err = storage.ListBuckets("")
|
||||
c.Assert(len(buckets), Equals, 3)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
buckets, err = storage.ListBuckets("bucket2")
|
||||
c.Assert(len(buckets), Equals, 2)
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user