Adding list api test

master
Frederick F. Kautz IV 10 years ago
parent 0903b7c46d
commit 0cd54031a7
  1. 48
      pkg/webapi/minioapi/minioapi_test.go

@ -18,6 +18,8 @@ package minioapi
import ( import (
"bytes" "bytes"
"encoding/xml"
"io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -284,7 +286,51 @@ func (s *MySuite) TestPutObject(c *C) {
} }
func (s *MySuite) TestListBuckets(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) { func (s *MySuite) TestListObjects(c *C) {

Loading…
Cancel
Save