mirror of
https://github.com/minio/minio.git
synced 2025-01-15 16:53:16 -05:00
Merge pull request #418 from fkautz/pr_out_moving_api_test_to_fixtures_for_drivers
This commit is contained in:
commit
0491e1bbf1
@ -23,6 +23,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -40,31 +41,66 @@ import (
|
|||||||
func Test(t *testing.T) { TestingT(t) }
|
func Test(t *testing.T) { TestingT(t) }
|
||||||
|
|
||||||
type MySuite struct {
|
type MySuite struct {
|
||||||
Driver func() drivers.Driver
|
Driver drivers.Driver
|
||||||
|
MockDriver *mocks.Driver
|
||||||
|
initDriver func() (drivers.Driver, string)
|
||||||
|
Root string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Suite(&MySuite{
|
var _ = Suite(&MySuite{
|
||||||
Driver: func() drivers.Driver {
|
initDriver: func() (drivers.Driver, string) {
|
||||||
return startMockDriver()
|
return startMockDriver(), ""
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
var _ = Suite(&MySuite{
|
var _ = Suite(&MySuite{
|
||||||
Driver: func() drivers.Driver {
|
initDriver: func() (drivers.Driver, string) {
|
||||||
_, _, driver := memory.Start()
|
_, _, driver := memory.Start()
|
||||||
return driver
|
return driver, ""
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
func (s *MySuite) TestNonExistantObject(c *C) {
|
var _ = Suite(&MySuite{
|
||||||
driver := s.Driver()
|
initDriver: func() (drivers.Driver, string) {
|
||||||
switch typedDriver := driver.(type) {
|
_, _, driver := memory.Start()
|
||||||
|
return driver, ""
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
func (s *MySuite) SetUpTest(c *C) {
|
||||||
|
driver, root := s.initDriver()
|
||||||
|
s.Root = root
|
||||||
|
var typedDriver *mocks.Driver
|
||||||
|
switch driver := driver.(type) {
|
||||||
case *mocks.Driver:
|
case *mocks.Driver:
|
||||||
{
|
{
|
||||||
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(drivers.ObjectMetadata{}, drivers.BucketNotFound{Bucket: "bucket"}).Once()
|
typedDriver = driver
|
||||||
defer typedDriver.AssertExpectations(c)
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
typedDriver = startMockDriver()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s.Driver = driver
|
||||||
|
s.MockDriver = typedDriver
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MySuite) TearDownTest(c *C) {
|
||||||
|
switch driver := s.Driver.(type) {
|
||||||
|
case *mocks.Driver:
|
||||||
|
{
|
||||||
|
driver.AssertExpectations(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if s.Root != "" {
|
||||||
|
os.RemoveAll(s.Root)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MySuite) TestNonExistantObject(c *C) {
|
||||||
|
driver := s.Driver
|
||||||
|
s.MockDriver.On("GetObjectMetadata", "bucket", "object", "").Return(drivers.ObjectMetadata{}, drivers.BucketNotFound{Bucket: "bucket"}).Once()
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
@ -76,10 +112,8 @@ func (s *MySuite) TestNonExistantObject(c *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestEmptyObject(c *C) {
|
func (s *MySuite) TestEmptyObject(c *C) {
|
||||||
driver := s.Driver()
|
driver := s.Driver
|
||||||
switch typedDriver := driver.(type) {
|
typedDriver := s.MockDriver
|
||||||
case *mocks.Driver:
|
|
||||||
{
|
|
||||||
metadata := drivers.ObjectMetadata{
|
metadata := drivers.ObjectMetadata{
|
||||||
Bucket: "bucket",
|
Bucket: "bucket",
|
||||||
Key: "key",
|
Key: "key",
|
||||||
@ -93,9 +127,6 @@ func (s *MySuite) TestEmptyObject(c *C) {
|
|||||||
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(metadata, nil).Once()
|
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(metadata, nil).Once()
|
||||||
typedDriver.On("GetObject", mock.Anything, "bucket", "object").Return(int64(0), nil).Once()
|
typedDriver.On("GetObject", mock.Anything, "bucket", "object").Return(int64(0), nil).Once()
|
||||||
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(metadata, nil).Once()
|
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(metadata, nil).Once()
|
||||||
defer typedDriver.AssertExpectations(c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
@ -112,16 +143,14 @@ func (s *MySuite) TestEmptyObject(c *C) {
|
|||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(true, Equals, bytes.Equal(responseBody, buffer.Bytes()))
|
c.Assert(true, Equals, bytes.Equal(responseBody, buffer.Bytes()))
|
||||||
|
|
||||||
metadata, err := driver.GetObjectMetadata("bucket", "object", "")
|
resMetadata, err := driver.GetObjectMetadata("bucket", "object", "")
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
verifyHeaders(c, response.Header, metadata.Created, 0, "application/octet-stream", metadata.Md5)
|
verifyHeaders(c, response.Header, resMetadata.Created, 0, "application/octet-stream", resMetadata.Md5)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestObject(c *C) {
|
func (s *MySuite) TestObject(c *C) {
|
||||||
driver := s.Driver()
|
driver := s.Driver
|
||||||
switch typedDriver := driver.(type) {
|
typedDriver := s.MockDriver
|
||||||
case *mocks.Driver:
|
|
||||||
{
|
|
||||||
metadata := drivers.ObjectMetadata{
|
metadata := drivers.ObjectMetadata{
|
||||||
Bucket: "bucket",
|
Bucket: "bucket",
|
||||||
Key: "key",
|
Key: "key",
|
||||||
@ -135,9 +164,7 @@ func (s *MySuite) TestObject(c *C) {
|
|||||||
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(metadata, nil).Twice()
|
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(metadata, nil).Twice()
|
||||||
typedDriver.SetGetObjectWriter("bucket", "object", []byte("hello world"))
|
typedDriver.SetGetObjectWriter("bucket", "object", []byte("hello world"))
|
||||||
typedDriver.On("GetObject", mock.Anything, "bucket", "object").Return(int64(0), nil).Once()
|
typedDriver.On("GetObject", mock.Anything, "bucket", "object").Return(int64(0), nil).Once()
|
||||||
defer typedDriver.AssertExpectations(c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
@ -154,26 +181,14 @@ func (s *MySuite) TestObject(c *C) {
|
|||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(responseBody, DeepEquals, []byte("hello world"))
|
c.Assert(responseBody, DeepEquals, []byte("hello world"))
|
||||||
|
|
||||||
metadata, err := driver.GetObjectMetadata("bucket", "object", "")
|
resMetadata, err := driver.GetObjectMetadata("bucket", "object", "")
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
verifyHeaders(c, response.Header, metadata.Created, len("hello world"), "application/octet-stream", metadata.Md5)
|
verifyHeaders(c, response.Header, resMetadata.Created, len("hello world"), "application/octet-stream", metadata.Md5)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestMultipleObjects(c *C) {
|
func (s *MySuite) TestMultipleObjects(c *C) {
|
||||||
driver := s.Driver()
|
driver := s.Driver
|
||||||
var typedDriver *mocks.Driver
|
typedDriver := s.MockDriver
|
||||||
switch driver := driver.(type) {
|
|
||||||
case *mocks.Driver:
|
|
||||||
{
|
|
||||||
typedDriver = driver
|
|
||||||
|
|
||||||
defer typedDriver.AssertExpectations(c)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
typedDriver = startMockDriver()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
metadata1 := drivers.ObjectMetadata{
|
metadata1 := drivers.ObjectMetadata{
|
||||||
Bucket: "bucket",
|
Bucket: "bucket",
|
||||||
Key: "object1",
|
Key: "object1",
|
||||||
@ -295,20 +310,7 @@ func (s *MySuite) TestMultipleObjects(c *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestNotImplemented(c *C) {
|
func (s *MySuite) TestNotImplemented(c *C) {
|
||||||
driver := s.Driver()
|
driver := s.Driver
|
||||||
var typedDriver *mocks.Driver
|
|
||||||
switch driver := driver.(type) {
|
|
||||||
case *mocks.Driver:
|
|
||||||
{
|
|
||||||
typedDriver = driver
|
|
||||||
defer typedDriver.AssertExpectations(c)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
// we never assert expectations
|
|
||||||
typedDriver = startMockDriver()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
@ -319,21 +321,8 @@ func (s *MySuite) TestNotImplemented(c *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestHeader(c *C) {
|
func (s *MySuite) TestHeader(c *C) {
|
||||||
driver := s.Driver()
|
driver := s.Driver
|
||||||
var typedDriver *mocks.Driver
|
typedDriver := s.MockDriver
|
||||||
switch driver := driver.(type) {
|
|
||||||
case *mocks.Driver:
|
|
||||||
{
|
|
||||||
typedDriver = driver
|
|
||||||
defer driver.AssertExpectations(c)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
// we never assert expectations
|
|
||||||
typedDriver = startMockDriver()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedDriver.AssertExpectations(c)
|
typedDriver.AssertExpectations(c)
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
@ -374,20 +363,8 @@ func (s *MySuite) TestHeader(c *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestPutBucket(c *C) {
|
func (s *MySuite) TestPutBucket(c *C) {
|
||||||
driver := s.Driver()
|
driver := s.Driver
|
||||||
var typedDriver *mocks.Driver
|
typedDriver := s.MockDriver
|
||||||
switch driver := driver.(type) {
|
|
||||||
case *mocks.Driver:
|
|
||||||
{
|
|
||||||
typedDriver = driver
|
|
||||||
defer driver.AssertExpectations(c)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
// we never assert expectations
|
|
||||||
typedDriver = startMockDriver()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
@ -416,20 +393,8 @@ func (s *MySuite) TestPutBucket(c *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestPutObject(c *C) {
|
func (s *MySuite) TestPutObject(c *C) {
|
||||||
driver := s.Driver()
|
driver := s.Driver
|
||||||
var typedDriver *mocks.Driver
|
typedDriver := s.MockDriver
|
||||||
switch driver := driver.(type) {
|
|
||||||
case *mocks.Driver:
|
|
||||||
{
|
|
||||||
typedDriver = driver
|
|
||||||
defer driver.AssertExpectations(c)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
// we never assert expectations
|
|
||||||
typedDriver = startMockDriver()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
@ -503,20 +468,8 @@ func (s *MySuite) TestPutObject(c *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestListBuckets(c *C) {
|
func (s *MySuite) TestListBuckets(c *C) {
|
||||||
driver := s.Driver()
|
driver := s.Driver
|
||||||
var typedDriver *mocks.Driver
|
typedDriver := s.MockDriver
|
||||||
switch driver := driver.(type) {
|
|
||||||
case *mocks.Driver:
|
|
||||||
{
|
|
||||||
typedDriver = driver
|
|
||||||
defer driver.AssertExpectations(c)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
// we never assert expectations
|
|
||||||
typedDriver = startMockDriver()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
@ -608,20 +561,9 @@ func verifyHeaders(c *C, header http.Header, date time.Time, size int, contentTy
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestXMLNameNotInBucketListJson(c *C) {
|
func (s *MySuite) TestXMLNameNotInBucketListJson(c *C) {
|
||||||
driver := s.Driver()
|
driver := s.Driver
|
||||||
var typedDriver *mocks.Driver
|
typedDriver := s.MockDriver
|
||||||
switch driver := driver.(type) {
|
|
||||||
case *mocks.Driver:
|
|
||||||
{
|
|
||||||
typedDriver = driver
|
|
||||||
defer driver.AssertExpectations(c)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
// we never assert expectations
|
|
||||||
typedDriver = startMockDriver()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
@ -648,20 +590,8 @@ func (s *MySuite) TestXMLNameNotInBucketListJson(c *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestXMLNameNotInObjectListJson(c *C) {
|
func (s *MySuite) TestXMLNameNotInObjectListJson(c *C) {
|
||||||
driver := s.Driver()
|
driver := s.Driver
|
||||||
var typedDriver *mocks.Driver
|
typedDriver := s.MockDriver
|
||||||
switch driver := driver.(type) {
|
|
||||||
case *mocks.Driver:
|
|
||||||
{
|
|
||||||
typedDriver = driver
|
|
||||||
defer driver.AssertExpectations(c)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
// we never assert expectations
|
|
||||||
typedDriver = startMockDriver()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
@ -688,20 +618,9 @@ func (s *MySuite) TestXMLNameNotInObjectListJson(c *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestContentTypePersists(c *C) {
|
func (s *MySuite) TestContentTypePersists(c *C) {
|
||||||
driver := s.Driver()
|
driver := s.Driver
|
||||||
var typedDriver *mocks.Driver
|
typedDriver := s.MockDriver
|
||||||
switch driver := driver.(type) {
|
|
||||||
case *mocks.Driver:
|
|
||||||
{
|
|
||||||
typedDriver = driver
|
|
||||||
defer driver.AssertExpectations(c)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
// we never assert expectations
|
|
||||||
typedDriver = startMockDriver()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
@ -775,20 +694,9 @@ func (s *MySuite) TestContentTypePersists(c *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestPartialContent(c *C) {
|
func (s *MySuite) TestPartialContent(c *C) {
|
||||||
driver := s.Driver()
|
driver := s.Driver
|
||||||
var typedDriver *mocks.Driver
|
typedDriver := s.MockDriver
|
||||||
switch driver := driver.(type) {
|
|
||||||
case *mocks.Driver:
|
|
||||||
{
|
|
||||||
typedDriver = driver
|
|
||||||
defer driver.AssertExpectations(c)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
// we never assert expectations
|
|
||||||
typedDriver = startMockDriver()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpHandler := api.HTTPHandler("", driver)
|
httpHandler := api.HTTPHandler("", driver)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user