Adding bucket management system with in memory storage driver

This commit is contained in:
Frederick F. Kautz IV
2014-11-06 21:34:46 -05:00
parent bd99a2185e
commit 0c68f52caf
24 changed files with 4906 additions and 4 deletions
+77 -1
View File
@@ -1,6 +1,7 @@
package minio
import (
. "gopkg.in/check.v1"
"io/ioutil"
"log"
"net/http"
@@ -8,7 +9,13 @@ import (
"testing"
)
func TestPrintsGateway(t *testing.T) {
type MySuite struct{}
var _ = Suite(&MySuite{})
func Test(t *testing.T) { TestingT(t) }
func (s *MySuite) TestPrintsGateway(c *C) {
server := httptest.NewServer(http.HandlerFunc(GatewayHandler))
defer server.Close()
res, err := http.Get(server.URL)
@@ -25,3 +32,72 @@ func TestPrintsGateway(t *testing.T) {
log.Fatal("Expected 'Gateway', Received '" + bodyString + "'")
}
}
type TestContext struct{}
func (s *MySuite) TestBucketCreation(c *C) {
requestBucketChan := make(chan BucketRequest)
defer close(requestBucketChan)
go SynchronizedBucketService(requestBucketChan)
context := TestContext{}
var bucketA1 Bucket
callback := make(chan Bucket)
requestBucketChan <- BucketRequest{
name: "bucketA",
context: context,
callback: callback,
}
bucketA1 = <-callback
c.Assert(bucketA1.GetName(context), Equals, "bucketA")
var bucketA2 Bucket
callback = make(chan Bucket)
requestBucketChan <- BucketRequest{
name: "bucketA",
context: context,
callback: callback,
}
bucketA2 = <-callback
c.Assert(bucketA2.GetName(context), Equals, "bucketA")
c.Assert(bucketA1, DeepEquals, bucketA2)
var bucketB Bucket
callback = make(chan Bucket)
requestBucketChan <- BucketRequest{
name: "bucketB",
context: context,
callback: callback,
}
bucketB = <-callback
c.Assert(bucketB.GetName(context), Equals, "bucketB")
}
func (s *MySuite) TestBucketOperations(c *C) {
requestBucketChan := make(chan BucketRequest)
defer close(requestBucketChan)
go SynchronizedBucketService(requestBucketChan)
context := TestContext{}
callback := make(chan Bucket)
requestBucketChan <- BucketRequest{
name: "bucket",
context: context,
callback: callback,
}
bucket := <-callback
c.Assert(bucket.GetName(context), Equals, "bucket")
nilResult, err := bucket.Get(context, "foo")
c.Assert(nilResult, IsNil)
c.Assert(err, IsNil)
err = bucket.Put(context, "foo", []byte("bar"))
c.Assert(err, IsNil)
barResult, err := bucket.Get(context, "foo")
c.Assert(err, IsNil)
c.Assert(string(barResult), Equals, "bar")
}