|
|
@ -1,11 +1,12 @@ |
|
|
|
package minio |
|
|
|
package minio |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"github.com/gorilla/mux" |
|
|
|
. "gopkg.in/check.v1" |
|
|
|
. "gopkg.in/check.v1" |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
|
"log" |
|
|
|
|
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"net/http/httptest" |
|
|
|
"net/http/httptest" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"testing" |
|
|
|
"testing" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
@ -16,21 +17,41 @@ var _ = Suite(&MySuite{}) |
|
|
|
func Test(t *testing.T) { TestingT(t) } |
|
|
|
func Test(t *testing.T) { TestingT(t) } |
|
|
|
|
|
|
|
|
|
|
|
func (s *MySuite) TestPrintsGateway(c *C) { |
|
|
|
func (s *MySuite) TestPrintsGateway(c *C) { |
|
|
|
server := httptest.NewServer(http.HandlerFunc(GatewayHandler)) |
|
|
|
// set up router with in memory storage driver
|
|
|
|
|
|
|
|
router := mux.NewRouter() |
|
|
|
|
|
|
|
config := GatewayConfig{StorageDriver: InMemoryStorageDriver} |
|
|
|
|
|
|
|
RegisterGatewayHandlers(router, config) |
|
|
|
|
|
|
|
server := httptest.NewServer(router) |
|
|
|
defer server.Close() |
|
|
|
defer server.Close() |
|
|
|
res, err := http.Get(server.URL) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
// GET request, empty
|
|
|
|
log.Fatal(err) |
|
|
|
getReq1, _ := http.NewRequest("GET", server.URL+"/one/two/three", nil) |
|
|
|
} |
|
|
|
client := &http.Client{} |
|
|
|
body, err := ioutil.ReadAll(res.Body) |
|
|
|
resp, err := client.Do(getReq1) |
|
|
|
res.Body.Close() |
|
|
|
c.Assert(resp.StatusCode, Equals, 404) |
|
|
|
if err != nil { |
|
|
|
c.Assert(err, IsNil) |
|
|
|
log.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
// assert object not found response
|
|
|
|
bodyString := string(body) |
|
|
|
body, _ := ioutil.ReadAll(resp.Body) |
|
|
|
if bodyString == "" { |
|
|
|
c.Assert(string(body), Equals, "Object not found\n") |
|
|
|
log.Fatal("Expected '', Received '" + bodyString + "'") |
|
|
|
c.Assert(err, IsNil) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// add new object
|
|
|
|
|
|
|
|
putReq, _ := http.NewRequest("PUT", server.URL+"/one/two/three", strings.NewReader("hello")) |
|
|
|
|
|
|
|
resp, err = client.Do(putReq) |
|
|
|
|
|
|
|
c.Assert(resp.StatusCode, Equals, 200) |
|
|
|
|
|
|
|
c.Assert(err, IsNil) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// verify object exists
|
|
|
|
|
|
|
|
getReq2, _ := http.NewRequest("GET", server.URL+"/one/two/three", strings.NewReader("hello")) |
|
|
|
|
|
|
|
resp, err = client.Do(getReq2) |
|
|
|
|
|
|
|
c.Assert(resp.StatusCode, Equals, 200) |
|
|
|
|
|
|
|
c.Assert(err, IsNil) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// verify object's contents
|
|
|
|
|
|
|
|
body2, _ := ioutil.ReadAll(resp.Body) |
|
|
|
|
|
|
|
c.Assert(string(body2), Equals, "hello") |
|
|
|
|
|
|
|
c.Assert(err, IsNil) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type TestContext struct{} |
|
|
|
type TestContext struct{} |
|
|
@ -38,9 +59,10 @@ type TestContext struct{} |
|
|
|
func (s *MySuite) TestBucketCreation(c *C) { |
|
|
|
func (s *MySuite) TestBucketCreation(c *C) { |
|
|
|
requestBucketChan := make(chan BucketRequest) |
|
|
|
requestBucketChan := make(chan BucketRequest) |
|
|
|
defer close(requestBucketChan) |
|
|
|
defer close(requestBucketChan) |
|
|
|
go SynchronizedBucketService(requestBucketChan) |
|
|
|
go SynchronizedBucketService(requestBucketChan, GatewayConfig{StorageDriver: InMemoryStorageDriver}) |
|
|
|
context := TestContext{} |
|
|
|
context := TestContext{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get new bucket A
|
|
|
|
var bucketA1 Bucket |
|
|
|
var bucketA1 Bucket |
|
|
|
callback := make(chan Bucket) |
|
|
|
callback := make(chan Bucket) |
|
|
|
requestBucketChan <- BucketRequest{ |
|
|
|
requestBucketChan <- BucketRequest{ |
|
|
@ -51,6 +73,7 @@ func (s *MySuite) TestBucketCreation(c *C) { |
|
|
|
bucketA1 = <-callback |
|
|
|
bucketA1 = <-callback |
|
|
|
c.Assert(bucketA1.GetName(context), Equals, "bucketA") |
|
|
|
c.Assert(bucketA1.GetName(context), Equals, "bucketA") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get bucket A again
|
|
|
|
var bucketA2 Bucket |
|
|
|
var bucketA2 Bucket |
|
|
|
callback = make(chan Bucket) |
|
|
|
callback = make(chan Bucket) |
|
|
|
requestBucketChan <- BucketRequest{ |
|
|
|
requestBucketChan <- BucketRequest{ |
|
|
@ -60,9 +83,9 @@ func (s *MySuite) TestBucketCreation(c *C) { |
|
|
|
} |
|
|
|
} |
|
|
|
bucketA2 = <-callback |
|
|
|
bucketA2 = <-callback |
|
|
|
c.Assert(bucketA2.GetName(context), Equals, "bucketA") |
|
|
|
c.Assert(bucketA2.GetName(context), Equals, "bucketA") |
|
|
|
|
|
|
|
|
|
|
|
c.Assert(bucketA1, DeepEquals, bucketA2) |
|
|
|
c.Assert(bucketA1, DeepEquals, bucketA2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get new bucket B
|
|
|
|
var bucketB Bucket |
|
|
|
var bucketB Bucket |
|
|
|
callback = make(chan Bucket) |
|
|
|
callback = make(chan Bucket) |
|
|
|
requestBucketChan <- BucketRequest{ |
|
|
|
requestBucketChan <- BucketRequest{ |
|
|
@ -74,29 +97,33 @@ func (s *MySuite) TestBucketCreation(c *C) { |
|
|
|
c.Assert(bucketB.GetName(context), Equals, "bucketB") |
|
|
|
c.Assert(bucketB.GetName(context), Equals, "bucketB") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *MySuite) TestBucketOperations(c *C) { |
|
|
|
func (s *MySuite) TestInMemoryBucketOperations(c *C) { |
|
|
|
|
|
|
|
// Test in memory bucket operations
|
|
|
|
requestBucketChan := make(chan BucketRequest) |
|
|
|
requestBucketChan := make(chan BucketRequest) |
|
|
|
defer close(requestBucketChan) |
|
|
|
defer close(requestBucketChan) |
|
|
|
go SynchronizedBucketService(requestBucketChan) |
|
|
|
go SynchronizedBucketService(requestBucketChan, GatewayConfig{StorageDriver: InMemoryStorageDriver}) |
|
|
|
context := TestContext{} |
|
|
|
context := TestContext{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get bucket
|
|
|
|
callback := make(chan Bucket) |
|
|
|
callback := make(chan Bucket) |
|
|
|
requestBucketChan <- BucketRequest{ |
|
|
|
requestBucketChan <- BucketRequest{ |
|
|
|
name: "bucket", |
|
|
|
name: "bucket", |
|
|
|
context: context, |
|
|
|
context: context, |
|
|
|
callback: callback, |
|
|
|
callback: callback, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bucket := <-callback |
|
|
|
bucket := <-callback |
|
|
|
c.Assert(bucket.GetName(context), Equals, "bucket") |
|
|
|
c.Assert(bucket.GetName(context), Equals, "bucket") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get missing value
|
|
|
|
nilResult, err := bucket.Get(context, "foo") |
|
|
|
nilResult, err := bucket.Get(context, "foo") |
|
|
|
c.Assert(nilResult, IsNil) |
|
|
|
c.Assert(nilResult, IsNil) |
|
|
|
c.Assert(err, IsNil) |
|
|
|
c.Assert(err, IsNil) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add new value
|
|
|
|
err = bucket.Put(context, "foo", []byte("bar")) |
|
|
|
err = bucket.Put(context, "foo", []byte("bar")) |
|
|
|
c.Assert(err, IsNil) |
|
|
|
c.Assert(err, IsNil) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// retrieve value
|
|
|
|
barResult, err := bucket.Get(context, "foo") |
|
|
|
barResult, err := bucket.Get(context, "foo") |
|
|
|
c.Assert(err, IsNil) |
|
|
|
c.Assert(err, IsNil) |
|
|
|
c.Assert(string(barResult), Equals, "bar") |
|
|
|
c.Assert(string(barResult), Equals, "bar") |
|
|
|