From 0cd54031a73cb383182000624e8960596f7ef79e Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Fri, 30 Jan 2015 17:34:18 -0800 Subject: [PATCH] Adding list api test --- pkg/webapi/minioapi/minioapi_test.go | 48 +++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/pkg/webapi/minioapi/minioapi_test.go b/pkg/webapi/minioapi/minioapi_test.go index debe2900f..6cadd5560 100644 --- a/pkg/webapi/minioapi/minioapi_test.go +++ b/pkg/webapi/minioapi/minioapi_test.go @@ -18,6 +18,8 @@ package minioapi import ( "bytes" + "encoding/xml" + "io" "io/ioutil" "net/http" "net/http/httptest" @@ -284,7 +286,51 @@ func (s *MySuite) TestPutObject(c *C) { } func (s *MySuite) TestListBuckets(c *C) { - // TODO Implement + _, _, storage := inmemory.Start() + httpHandler := HttpHandler(storage) + testServer := httptest.NewServer(httpHandler) + defer testServer.Close() + + response, err := http.Get(testServer.URL + "/") + defer response.Body.Close() + c.Assert(err, IsNil) + c.Assert(response.StatusCode, Equals, http.StatusOK) + + listResponse, err := readListBucket(response.Body) + c.Assert(err, IsNil) + c.Assert(len(listResponse.Buckets.Bucket), Equals, 0) + + storage.StoreBucket("foo") + + response, err = http.Get(testServer.URL + "/") + defer response.Body.Close() + c.Assert(err, IsNil) + c.Assert(response.StatusCode, Equals, http.StatusOK) + + listResponse, err = readListBucket(response.Body) + c.Assert(err, IsNil) + c.Assert(len(listResponse.Buckets.Bucket), Equals, 1) + c.Assert(listResponse.Buckets.Bucket[0].Name, Equals, "foo") + + storage.StoreBucket("bar") + + response, err = http.Get(testServer.URL + "/") + defer response.Body.Close() + c.Assert(err, IsNil) + c.Assert(response.StatusCode, Equals, http.StatusOK) + + listResponse, err = readListBucket(response.Body) + c.Assert(err, IsNil) + c.Assert(len(listResponse.Buckets.Bucket), Equals, 2) + c.Assert(listResponse.Buckets.Bucket[0].Name, Equals, "foo") + c.Assert(listResponse.Buckets.Bucket[1].Name, Equals, "bar") +} + +func readListBucket(reader io.Reader) (BucketListResponse, error) { + var results BucketListResponse + decoder := xml.NewDecoder(reader) + err := decoder.Decode(&results) + return results, err } func (s *MySuite) TestListObjects(c *C) {