mirror of
https://github.com/minio/minio.git
synced 2025-01-11 23:13:23 -05:00
Merge pull request #111 from fkautz/pr_out_setting_order_when_retrieving_buckets
This commit is contained in:
commit
392ca7451f
@ -111,6 +111,12 @@ func (storage *storage) ListObjects(bucket, prefix string, count int) ([]mstorag
|
|||||||
return results, false, nil
|
return results, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ByBucketName []mstorage.BucketMetadata
|
||||||
|
|
||||||
|
func (b ByBucketName) Len() int { return len(b) }
|
||||||
|
func (b ByBucketName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||||
|
func (b ByBucketName) Less(i, j int) bool { return b[i].Name < b[j].Name }
|
||||||
|
|
||||||
func (storage *storage) ListBuckets(prefix string) ([]mstorage.BucketMetadata, error) {
|
func (storage *storage) ListBuckets(prefix string) ([]mstorage.BucketMetadata, error) {
|
||||||
var results []mstorage.BucketMetadata
|
var results []mstorage.BucketMetadata
|
||||||
for key, bucket := range storage.bucketdata {
|
for key, bucket := range storage.bucketdata {
|
||||||
@ -118,6 +124,7 @@ func (storage *storage) ListBuckets(prefix string) ([]mstorage.BucketMetadata, e
|
|||||||
results = append(results, bucket.metadata)
|
results = append(results, bucket.metadata)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sort.Sort(ByBucketName(results))
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ func APITestSuite(c *C, create func() Storage) {
|
|||||||
testBucketRecreateFails(c, create)
|
testBucketRecreateFails(c, create)
|
||||||
testPutObjectInSubdir(c, create)
|
testPutObjectInSubdir(c, create)
|
||||||
testListBuckets(c, create)
|
testListBuckets(c, create)
|
||||||
|
testListBucketsOrder(c, create)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCreateBucket(c *C, create func() Storage) {
|
func testCreateBucket(c *C, create func() Storage) {
|
||||||
@ -193,3 +194,18 @@ func testListBuckets(c *C, create func() Storage) {
|
|||||||
c.Assert(len(buckets), Equals, 2)
|
c.Assert(len(buckets), Equals, 2)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testListBucketsOrder(c *C, create func() Storage) {
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
storage := create()
|
||||||
|
// add one and test exists
|
||||||
|
storage.StoreBucket("bucket1")
|
||||||
|
storage.StoreBucket("bucket2")
|
||||||
|
|
||||||
|
buckets, err := storage.ListBuckets("bucket")
|
||||||
|
c.Assert(len(buckets), Equals, 2)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(buckets[0].Name, Equals, "bucket1")
|
||||||
|
c.Assert(buckets[1].Name, Equals, "bucket2")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"sort"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -323,12 +322,9 @@ func (s *MySuite) TestListBuckets(c *C) {
|
|||||||
listResponse, err = readListBucket(response.Body)
|
listResponse, err = readListBucket(response.Body)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(len(listResponse.Buckets.Bucket), Equals, 2)
|
c.Assert(len(listResponse.Buckets.Bucket), Equals, 2)
|
||||||
var buckets []string
|
|
||||||
buckets = append(buckets, listResponse.Buckets.Bucket[0].Name)
|
c.Assert(listResponse.Buckets.Bucket[0].Name, Equals, "bar")
|
||||||
buckets = append(buckets, listResponse.Buckets.Bucket[1].Name)
|
c.Assert(listResponse.Buckets.Bucket[1].Name, Equals, "foo")
|
||||||
sort.Strings(buckets)
|
|
||||||
c.Assert(buckets[0], Equals, "bar")
|
|
||||||
c.Assert(buckets[1], Equals, "foo")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func readListBucket(reader io.Reader) (BucketListResponse, error) {
|
func readListBucket(reader io.Reader) (BucketListResponse, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user