mirror of
https://github.com/minio/minio.git
synced 2025-02-27 13:29:15 -05:00
pkg/fs: test, bench, and drop unnecessary check in ListBuckets
There is now a simple test and a benchmark for ListBuckets. I also dropped an unnecessary check that was simply repeated from above, guaranteed to be true.
This commit is contained in:
parent
114f9de5eb
commit
a5d0bef4e2
@ -78,7 +78,7 @@ func (fs Filesystem) ListBuckets() ([]BucketMetadata, *probe.Error) {
|
|||||||
}
|
}
|
||||||
// If directories are found with odd names, skip them.
|
// If directories are found with odd names, skip them.
|
||||||
dirName := strings.ToLower(file.Name())
|
dirName := strings.ToLower(file.Name())
|
||||||
if file.IsDir() && !IsValidBucketName(dirName) {
|
if !IsValidBucketName(dirName) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
metadata := BucketMetadata{
|
metadata := BucketMetadata{
|
||||||
|
@ -19,10 +19,51 @@ package fs
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestListBuckets(t *testing.T) {
|
||||||
|
// Make a temporary directory to use as the filesystem.
|
||||||
|
directory, fserr := ioutil.TempDir("", "minio-benchmark")
|
||||||
|
if fserr != nil {
|
||||||
|
t.Fatal(fserr)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(directory)
|
||||||
|
|
||||||
|
// Create the filesystem.
|
||||||
|
filesystem, err := New(directory, 0)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a few buckets.
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
err = filesystem.MakeBucket("testbucket."+strconv.Itoa(i), "public-read")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// List, and ensure that they are all there.
|
||||||
|
metadatas, err := filesystem.ListBuckets()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(metadatas) != 10 {
|
||||||
|
t.Errorf("incorrect length of metadatas (%i)\n", len(metadatas))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate over the buckets, ensuring that the name is correct.
|
||||||
|
for i := 0; i < len(metadatas); i++ {
|
||||||
|
if !strings.Contains(metadatas[i].Name, "testbucket") {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDeleteBucket(t *testing.T) {
|
func TestDeleteBucket(t *testing.T) {
|
||||||
// Make a temporary directory to use as the filesystem.
|
// Make a temporary directory to use as the filesystem.
|
||||||
directory, fserr := ioutil.TempDir("", "minio-benchmark")
|
directory, fserr := ioutil.TempDir("", "minio-benchmark")
|
||||||
@ -44,6 +85,39 @@ func TestDeleteBucket(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkListBuckets(b *testing.B) {
|
||||||
|
// Make a temporary directory to use as the filesystem.
|
||||||
|
directory, fserr := ioutil.TempDir("", "minio-benchmark")
|
||||||
|
if fserr != nil {
|
||||||
|
b.Fatal(fserr)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(directory)
|
||||||
|
|
||||||
|
// Create the filesystem.
|
||||||
|
filesystem, err := New(directory, 0)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a few buckets.
|
||||||
|
for i := 0; i < 20; i++ {
|
||||||
|
err = filesystem.MakeBucket("bucket."+strconv.Itoa(i), "public-read")
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
|
// List the buckets over and over and over.
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
_, err = filesystem.ListBuckets()
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkDeleteBucket(b *testing.B) {
|
func BenchmarkDeleteBucket(b *testing.B) {
|
||||||
// Make a temporary directory to use as the filesystem.
|
// Make a temporary directory to use as the filesystem.
|
||||||
directory, fserr := ioutil.TempDir("", "minio-benchmark")
|
directory, fserr := ioutil.TempDir("", "minio-benchmark")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user