2015-01-21 02:16:06 -05:00
|
|
|
/*
|
|
|
|
* Mini Object Storage, (C) 2014 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-03-06 04:50:51 -05:00
|
|
|
package minioapi_test
|
2015-01-20 19:08:14 -05:00
|
|
|
|
|
|
|
import (
|
2015-01-23 22:33:56 -05:00
|
|
|
"bytes"
|
2015-01-30 20:34:18 -05:00
|
|
|
"encoding/xml"
|
|
|
|
"io"
|
2015-01-23 22:33:56 -05:00
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
2015-01-24 16:12:34 -05:00
|
|
|
"strconv"
|
2015-02-04 17:21:47 -05:00
|
|
|
"strings"
|
2015-01-20 19:08:14 -05:00
|
|
|
"testing"
|
2015-01-24 16:12:34 -05:00
|
|
|
"time"
|
2015-01-23 22:33:56 -05:00
|
|
|
|
2015-03-06 04:50:51 -05:00
|
|
|
"github.com/minio-io/minio/pkg/api/minioapi"
|
2015-02-26 20:23:42 -05:00
|
|
|
mstorage "github.com/minio-io/minio/pkg/storage"
|
2015-03-16 14:46:16 -04:00
|
|
|
"github.com/minio-io/minio/pkg/storage/memory"
|
2015-03-06 04:50:51 -05:00
|
|
|
|
2015-01-23 22:33:56 -05:00
|
|
|
. "gopkg.in/check.v1"
|
2015-01-20 19:08:14 -05:00
|
|
|
)
|
|
|
|
|
2015-01-23 22:33:56 -05:00
|
|
|
func Test(t *testing.T) { TestingT(t) }
|
|
|
|
|
|
|
|
type MySuite struct{}
|
|
|
|
|
|
|
|
var _ = Suite(&MySuite{})
|
|
|
|
|
|
|
|
func (s *MySuite) TestNonExistantObject(c *C) {
|
2015-03-16 14:46:16 -04:00
|
|
|
_, _, storage := memory.Start()
|
2015-03-06 04:50:51 -05:00
|
|
|
httpHandler := minioapi.HTTPHandler("", storage)
|
2015-01-23 22:33:56 -05:00
|
|
|
testServer := httptest.NewServer(httpHandler)
|
|
|
|
defer testServer.Close()
|
|
|
|
|
|
|
|
response, err := http.Get(testServer.URL + "/bucket/object")
|
|
|
|
c.Assert(err, IsNil)
|
2015-02-11 06:23:15 -05:00
|
|
|
c.Log(response.StatusCode)
|
2015-01-23 22:33:56 -05:00
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusNotFound)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MySuite) TestEmptyObject(c *C) {
|
2015-03-16 14:46:16 -04:00
|
|
|
_, _, storage := memory.Start()
|
2015-03-06 04:50:51 -05:00
|
|
|
httpHandler := minioapi.HTTPHandler("", storage)
|
2015-01-23 22:33:56 -05:00
|
|
|
testServer := httptest.NewServer(httpHandler)
|
|
|
|
defer testServer.Close()
|
|
|
|
|
|
|
|
buffer := bytes.NewBufferString("")
|
2015-03-11 23:14:40 -04:00
|
|
|
storage.CreateBucket("bucket")
|
2015-03-12 03:36:33 -04:00
|
|
|
storage.CreateObject("bucket", "object", "", buffer)
|
2015-01-23 22:33:56 -05:00
|
|
|
|
|
|
|
response, err := http.Get(testServer.URL + "/bucket/object")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
responseBody, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(true, Equals, bytes.Equal(responseBody, buffer.Bytes()))
|
|
|
|
|
2015-03-07 22:10:55 -05:00
|
|
|
metadata, err := storage.GetObjectMetadata("bucket", "object", "")
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(err, IsNil)
|
2015-02-05 17:05:43 -05:00
|
|
|
verifyHeaders(c, response.Header, metadata.Created, 0, "application/octet-stream", metadata.ETag)
|
2015-01-24 16:12:34 -05:00
|
|
|
|
2015-01-23 22:33:56 -05:00
|
|
|
// TODO Test Headers
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MySuite) TestObject(c *C) {
|
2015-03-16 14:46:16 -04:00
|
|
|
_, _, storage := memory.Start()
|
2015-03-06 04:50:51 -05:00
|
|
|
httpHandler := minioapi.HTTPHandler("", storage)
|
2015-01-23 22:33:56 -05:00
|
|
|
testServer := httptest.NewServer(httpHandler)
|
|
|
|
defer testServer.Close()
|
|
|
|
|
|
|
|
buffer := bytes.NewBufferString("hello world")
|
2015-03-11 23:14:40 -04:00
|
|
|
storage.CreateBucket("bucket")
|
2015-03-12 03:36:33 -04:00
|
|
|
storage.CreateObject("bucket", "object", "", buffer)
|
2015-01-23 22:33:56 -05:00
|
|
|
|
|
|
|
response, err := http.Get(testServer.URL + "/bucket/object")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
responseBody, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello world")))
|
|
|
|
|
2015-03-07 22:10:55 -05:00
|
|
|
metadata, err := storage.GetObjectMetadata("bucket", "object", "")
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(err, IsNil)
|
2015-02-05 17:05:43 -05:00
|
|
|
verifyHeaders(c, response.Header, metadata.Created, len("hello world"), "application/octet-stream", metadata.ETag)
|
2015-01-23 22:33:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MySuite) TestMultipleObjects(c *C) {
|
2015-03-16 14:46:16 -04:00
|
|
|
_, _, storage := memory.Start()
|
2015-03-06 04:50:51 -05:00
|
|
|
httpHandler := minioapi.HTTPHandler("", storage)
|
2015-01-23 22:33:56 -05:00
|
|
|
testServer := httptest.NewServer(httpHandler)
|
|
|
|
defer testServer.Close()
|
|
|
|
|
|
|
|
buffer1 := bytes.NewBufferString("hello one")
|
|
|
|
buffer2 := bytes.NewBufferString("hello two")
|
|
|
|
buffer3 := bytes.NewBufferString("hello three")
|
|
|
|
|
2015-03-11 23:14:40 -04:00
|
|
|
storage.CreateBucket("bucket")
|
2015-03-12 03:36:33 -04:00
|
|
|
storage.CreateObject("bucket", "object1", "", buffer1)
|
|
|
|
storage.CreateObject("bucket", "object2", "", buffer2)
|
|
|
|
storage.CreateObject("bucket", "object3", "", buffer3)
|
2015-01-23 22:33:56 -05:00
|
|
|
|
|
|
|
// test non-existant object
|
|
|
|
response, err := http.Get(testServer.URL + "/bucket/object")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusNotFound)
|
|
|
|
// TODO Test Headers
|
|
|
|
|
2015-01-24 16:12:34 -05:00
|
|
|
//// test object 1
|
|
|
|
|
|
|
|
// get object
|
2015-01-23 22:33:56 -05:00
|
|
|
response, err = http.Get(testServer.URL + "/bucket/object1")
|
|
|
|
c.Assert(err, IsNil)
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
// get metadata
|
2015-03-07 22:10:55 -05:00
|
|
|
metadata, err := storage.GetObjectMetadata("bucket", "object1", "")
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(err, IsNil)
|
2015-01-23 22:33:56 -05:00
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
// verify headers
|
2015-02-05 17:05:43 -05:00
|
|
|
verifyHeaders(c, response.Header, metadata.Created, len("hello one"), "application/octet-stream", metadata.ETag)
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
// verify response data
|
2015-01-23 22:33:56 -05:00
|
|
|
responseBody, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello one")))
|
|
|
|
|
|
|
|
// test object 2
|
2015-01-24 16:12:34 -05:00
|
|
|
// get object
|
2015-01-23 22:33:56 -05:00
|
|
|
response, err = http.Get(testServer.URL + "/bucket/object2")
|
|
|
|
c.Assert(err, IsNil)
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
// get metadata
|
2015-03-07 22:10:55 -05:00
|
|
|
metadata, err = storage.GetObjectMetadata("bucket", "object2", "")
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(err, IsNil)
|
2015-01-23 22:33:56 -05:00
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
// verify headers
|
2015-02-05 17:05:43 -05:00
|
|
|
verifyHeaders(c, response.Header, metadata.Created, len("hello two"), "application/octet-stream", metadata.ETag)
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
// verify response data
|
2015-01-23 22:33:56 -05:00
|
|
|
responseBody, err = ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello two")))
|
|
|
|
|
|
|
|
// test object 3
|
2015-01-24 16:12:34 -05:00
|
|
|
// get object
|
2015-01-23 22:33:56 -05:00
|
|
|
response, err = http.Get(testServer.URL + "/bucket/object3")
|
|
|
|
c.Assert(err, IsNil)
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
// get metadata
|
2015-03-07 22:10:55 -05:00
|
|
|
metadata, err = storage.GetObjectMetadata("bucket", "object3", "")
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(err, IsNil)
|
2015-01-23 22:33:56 -05:00
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
// verify headers
|
2015-02-05 17:05:43 -05:00
|
|
|
verifyHeaders(c, response.Header, metadata.Created, len("hello three"), "application/octet-stream", metadata.ETag)
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
// verify object
|
2015-01-23 22:33:56 -05:00
|
|
|
responseBody, err = ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(true, Equals, bytes.Equal(responseBody, []byte("hello three")))
|
2015-01-20 19:08:14 -05:00
|
|
|
}
|
2015-01-24 16:12:34 -05:00
|
|
|
|
2015-01-24 19:35:33 -05:00
|
|
|
func (s *MySuite) TestNotImplemented(c *C) {
|
2015-03-16 14:46:16 -04:00
|
|
|
_, _, storage := memory.Start()
|
2015-03-06 04:50:51 -05:00
|
|
|
httpHandler := minioapi.HTTPHandler("", storage)
|
2015-01-24 19:35:33 -05:00
|
|
|
testServer := httptest.NewServer(httpHandler)
|
|
|
|
defer testServer.Close()
|
|
|
|
|
|
|
|
response, err := http.Get(testServer.URL + "/bucket/object?acl")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusNotImplemented)
|
|
|
|
}
|
|
|
|
|
2015-01-24 16:12:34 -05:00
|
|
|
func (s *MySuite) TestHeader(c *C) {
|
2015-03-16 14:46:16 -04:00
|
|
|
_, _, storage := memory.Start()
|
2015-03-06 04:50:51 -05:00
|
|
|
httpHandler := minioapi.HTTPHandler("", storage)
|
2015-01-24 16:12:34 -05:00
|
|
|
testServer := httptest.NewServer(httpHandler)
|
|
|
|
defer testServer.Close()
|
|
|
|
|
|
|
|
response, err := http.Get(testServer.URL + "/bucket/object")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusNotFound)
|
|
|
|
|
|
|
|
buffer := bytes.NewBufferString("hello world")
|
2015-03-11 23:14:40 -04:00
|
|
|
storage.CreateBucket("bucket")
|
2015-03-12 03:36:33 -04:00
|
|
|
storage.CreateObject("bucket", "object", "", buffer)
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
response, err = http.Get(testServer.URL + "/bucket/object")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-03-07 22:10:55 -05:00
|
|
|
metadata, err := storage.GetObjectMetadata("bucket", "object", "")
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(err, IsNil)
|
2015-02-05 17:05:43 -05:00
|
|
|
verifyHeaders(c, response.Header, metadata.Created, len("hello world"), "application/octet-stream", metadata.ETag)
|
2015-01-24 16:12:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MySuite) TestPutBucket(c *C) {
|
2015-03-16 14:46:16 -04:00
|
|
|
_, _, storage := memory.Start()
|
2015-03-06 04:50:51 -05:00
|
|
|
httpHandler := minioapi.HTTPHandler("", storage)
|
2015-01-24 16:12:34 -05:00
|
|
|
testServer := httptest.NewServer(httpHandler)
|
|
|
|
defer testServer.Close()
|
|
|
|
|
2015-02-15 20:03:27 -05:00
|
|
|
buckets, err := storage.ListBuckets()
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(len(buckets), Equals, 0)
|
2015-01-25 18:35:08 -05:00
|
|
|
c.Assert(err, IsNil)
|
2015-01-24 16:12:34 -05:00
|
|
|
|
2015-02-06 23:47:21 -05:00
|
|
|
request, err := http.NewRequest("PUT", testServer.URL+"/bucket", bytes.NewBufferString(""))
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
// check bucket exists
|
2015-02-15 20:03:27 -05:00
|
|
|
buckets, err = storage.ListBuckets()
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(len(buckets), Equals, 1)
|
2015-01-25 18:35:08 -05:00
|
|
|
c.Assert(err, IsNil)
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(buckets[0].Name, Equals, "bucket")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MySuite) TestPutObject(c *C) {
|
2015-03-16 14:46:16 -04:00
|
|
|
_, _, storage := memory.Start()
|
2015-03-06 04:50:51 -05:00
|
|
|
httpHandler := minioapi.HTTPHandler("", storage)
|
2015-01-24 16:12:34 -05:00
|
|
|
testServer := httptest.NewServer(httpHandler)
|
|
|
|
defer testServer.Close()
|
|
|
|
|
2015-02-26 20:23:42 -05:00
|
|
|
resources := mstorage.BucketResourcesMetadata{}
|
|
|
|
|
|
|
|
resources.Maxkeys = 1000
|
|
|
|
resources.Prefix = ""
|
|
|
|
objects, resources, err := storage.ListObjects("bucket", resources)
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(len(objects), Equals, 0)
|
2015-02-26 20:23:42 -05:00
|
|
|
c.Assert(resources.IsTruncated, Equals, false)
|
2015-02-01 20:21:12 -05:00
|
|
|
c.Assert(err, Not(IsNil))
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
date1 := time.Now()
|
|
|
|
|
2015-01-24 18:42:24 -05:00
|
|
|
// Put Bucket before - Put Object into a bucket
|
2015-02-06 23:47:21 -05:00
|
|
|
request, err := http.NewRequest("PUT", testServer.URL+"/bucket", bytes.NewBufferString(""))
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-01-24 18:42:24 -05:00
|
|
|
request, err = http.NewRequest("PUT", testServer.URL+"/bucket/two", bytes.NewBufferString("hello world"))
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
2015-01-24 16:12:34 -05:00
|
|
|
date2 := time.Now()
|
|
|
|
|
2015-02-26 20:23:42 -05:00
|
|
|
resources.Maxkeys = 1000
|
|
|
|
resources.Prefix = ""
|
|
|
|
|
|
|
|
objects, resources, err = storage.ListObjects("bucket", resources)
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(len(objects), Equals, 1)
|
2015-02-26 20:23:42 -05:00
|
|
|
c.Assert(resources.IsTruncated, Equals, false)
|
2015-01-25 18:35:08 -05:00
|
|
|
c.Assert(err, IsNil)
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
var writer bytes.Buffer
|
|
|
|
|
2015-03-12 03:36:33 -04:00
|
|
|
storage.GetObject(&writer, "bucket", "two")
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
c.Assert(bytes.Equal(writer.Bytes(), []byte("hello world")), Equals, true)
|
|
|
|
|
2015-03-07 22:10:55 -05:00
|
|
|
metadata, err := storage.GetObjectMetadata("bucket", "two", "")
|
2015-01-24 16:12:34 -05:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
lastModified := metadata.Created
|
|
|
|
|
|
|
|
c.Assert(date1.Before(lastModified), Equals, true)
|
|
|
|
c.Assert(lastModified.Before(date2), Equals, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MySuite) TestListBuckets(c *C) {
|
2015-03-16 14:46:16 -04:00
|
|
|
_, _, storage := memory.Start()
|
2015-03-06 04:50:51 -05:00
|
|
|
httpHandler := minioapi.HTTPHandler("", storage)
|
2015-01-30 20:34:18 -05:00
|
|
|
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)
|
|
|
|
|
2015-03-11 23:14:40 -04:00
|
|
|
storage.CreateBucket("foo")
|
2015-01-30 20:34:18 -05:00
|
|
|
|
|
|
|
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")
|
|
|
|
|
2015-03-11 23:14:40 -04:00
|
|
|
storage.CreateBucket("bar")
|
2015-01-30 20:34:18 -05:00
|
|
|
|
|
|
|
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)
|
2015-02-01 03:16:25 -05:00
|
|
|
|
|
|
|
c.Assert(listResponse.Buckets.Bucket[0].Name, Equals, "bar")
|
|
|
|
c.Assert(listResponse.Buckets.Bucket[1].Name, Equals, "foo")
|
2015-01-30 20:34:18 -05:00
|
|
|
}
|
|
|
|
|
2015-03-06 04:50:51 -05:00
|
|
|
func readListBucket(reader io.Reader) (minioapi.BucketListResponse, error) {
|
|
|
|
var results minioapi.BucketListResponse
|
2015-01-30 20:34:18 -05:00
|
|
|
decoder := xml.NewDecoder(reader)
|
|
|
|
err := decoder.Decode(&results)
|
|
|
|
return results, err
|
2015-01-24 16:12:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MySuite) TestListObjects(c *C) {
|
|
|
|
// TODO Implement
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MySuite) TestShouldNotBeAbleToCreateObjectInNonexistantBucket(c *C) {
|
|
|
|
// TODO Implement
|
|
|
|
}
|
|
|
|
|
2015-01-25 14:22:38 -05:00
|
|
|
func (s *MySuite) TestHeadOnObject(c *C) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MySuite) TestDateFormat(c *C) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2015-01-24 16:12:34 -05:00
|
|
|
func verifyHeaders(c *C, header http.Header, date time.Time, size int, contentType string, etag string) {
|
|
|
|
// Verify date
|
2015-03-11 04:01:49 -04:00
|
|
|
c.Log(header)
|
|
|
|
c.Assert(header.Get("Last-Modified"), Equals, date.Format(time.RFC1123))
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
// verify size
|
2015-03-11 04:01:49 -04:00
|
|
|
c.Assert(header.Get("Content-Length"), Equals, strconv.Itoa(size))
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
// verify content type
|
2015-03-11 04:01:49 -04:00
|
|
|
c.Assert(header.Get("Content-Type"), Equals, contentType)
|
2015-01-24 16:12:34 -05:00
|
|
|
|
|
|
|
// verify etag
|
2015-03-11 04:01:49 -04:00
|
|
|
c.Assert(header.Get("Etag"), Equals, etag)
|
2015-01-24 16:12:34 -05:00
|
|
|
}
|
2015-02-04 17:21:47 -05:00
|
|
|
|
|
|
|
func (s *MySuite) TestXMLNameNotInBucketListJson(c *C) {
|
2015-03-16 14:46:16 -04:00
|
|
|
_, _, storage := memory.Start()
|
2015-03-06 04:50:51 -05:00
|
|
|
httpHandler := minioapi.HTTPHandler("", storage)
|
2015-02-04 17:21:47 -05:00
|
|
|
testServer := httptest.NewServer(httpHandler)
|
|
|
|
defer testServer.Close()
|
|
|
|
|
2015-03-11 23:14:40 -04:00
|
|
|
err := storage.CreateBucket("foo")
|
2015-02-04 17:21:47 -05:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
request, err := http.NewRequest("GET", testServer.URL+"/", bytes.NewBufferString(""))
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
request.Header.Add("Accept", "application/json")
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
byteResults, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(strings.Contains(string(byteResults), "XML"), Equals, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MySuite) TestXMLNameNotInObjectListJson(c *C) {
|
2015-03-16 14:46:16 -04:00
|
|
|
_, _, storage := memory.Start()
|
2015-03-06 04:50:51 -05:00
|
|
|
httpHandler := minioapi.HTTPHandler("", storage)
|
2015-02-04 17:21:47 -05:00
|
|
|
testServer := httptest.NewServer(httpHandler)
|
|
|
|
defer testServer.Close()
|
|
|
|
|
2015-03-11 23:14:40 -04:00
|
|
|
err := storage.CreateBucket("foo")
|
2015-02-04 17:21:47 -05:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
2015-02-06 23:47:21 -05:00
|
|
|
request, err := http.NewRequest("GET", testServer.URL+"/foo", bytes.NewBufferString(""))
|
2015-02-04 17:21:47 -05:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
request.Header.Add("Accept", "application/json")
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
response, err := client.Do(request)
|
|
|
|
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
byteResults, err := ioutil.ReadAll(response.Body)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(strings.Contains(string(byteResults), "XML"), Equals, false)
|
|
|
|
}
|
2015-02-05 17:05:43 -05:00
|
|
|
|
|
|
|
func (s *MySuite) TestContentTypePersists(c *C) {
|
2015-03-16 14:46:16 -04:00
|
|
|
_, _, storage := memory.Start()
|
2015-03-06 04:50:51 -05:00
|
|
|
httpHandler := minioapi.HTTPHandler("", storage)
|
2015-02-05 17:05:43 -05:00
|
|
|
testServer := httptest.NewServer(httpHandler)
|
|
|
|
defer testServer.Close()
|
|
|
|
|
2015-03-11 23:14:40 -04:00
|
|
|
err := storage.CreateBucket("bucket")
|
2015-02-05 17:05:43 -05:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
request, err := http.NewRequest("PUT", testServer.URL+"/bucket/one", bytes.NewBufferString("hello world"))
|
|
|
|
delete(request.Header, "Content-Type")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
response, err := client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
// test head
|
|
|
|
request, err = http.NewRequest("HEAD", testServer.URL+"/bucket/one", bytes.NewBufferString(""))
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
2015-03-11 04:01:49 -04:00
|
|
|
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
|
2015-02-05 17:05:43 -05:00
|
|
|
|
|
|
|
// test get object
|
|
|
|
response, err = http.Get(testServer.URL + "/bucket/one")
|
2015-03-11 04:01:49 -04:00
|
|
|
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
|
2015-02-05 17:05:43 -05:00
|
|
|
|
|
|
|
request, err = http.NewRequest("PUT", testServer.URL+"/bucket/two", bytes.NewBufferString("hello world"))
|
|
|
|
delete(request.Header, "Content-Type")
|
|
|
|
request.Header.Add("Content-Type", "application/json")
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
|
|
|
|
|
|
|
request, err = http.NewRequest("HEAD", testServer.URL+"/bucket/two", bytes.NewBufferString(""))
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
response, err = client.Do(request)
|
|
|
|
c.Assert(err, IsNil)
|
2015-03-11 04:01:49 -04:00
|
|
|
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
|
2015-02-05 17:05:43 -05:00
|
|
|
|
|
|
|
// test get object
|
|
|
|
response, err = http.Get(testServer.URL + "/bucket/two")
|
2015-03-11 04:01:49 -04:00
|
|
|
c.Assert(response.Header.Get("Content-Type"), Equals, "application/octet-stream")
|
2015-02-05 17:05:43 -05:00
|
|
|
}
|