Use moq to mock S3 interface

This commit is contained in:
Lena Fuhrimann 2018-04-24 22:35:21 +02:00
parent 200fc5c8c1
commit f7f0bfb51f
11 changed files with 531 additions and 140 deletions

6
Gopkg.lock generated
View file

@ -11,7 +11,7 @@
branch = "master" branch = "master"
name = "github.com/dustin/go-humanize" name = "github.com/dustin/go-humanize"
packages = ["."] packages = ["."]
revision = "bb3d318650d48840a39aa21a027c6630e198e626" revision = "02af3965c54e8cacf948b97fef38925c4120652c"
[[projects]] [[projects]]
name = "github.com/go-ini/ini" name = "github.com/go-ini/ini"
@ -88,7 +88,7 @@
"blake2b", "blake2b",
"ssh/terminal" "ssh/terminal"
] ]
revision = "e73bf333ef8920dbb52ad18d4bd38ad9d9bc76d7" revision = "b49d69b5da943f7ef3c9cf91c8777c1f78a0cc3c"
[[projects]] [[projects]]
branch = "master" branch = "master"
@ -106,7 +106,7 @@
"unix", "unix",
"windows" "windows"
] ]
revision = "79b0c6888797020a994db17c8510466c72fe75d9" revision = "cbbc999da32df943dac6cd71eb3ee39e1d7838b9"
[[projects]] [[projects]]
name = "golang.org/x/text" name = "golang.org/x/text"

View file

@ -1,15 +1,17 @@
.PHONY: all lint test build-docker deploy-cf
all: all:
go build ./cmd/s3manager go build ./cmd/...
lint: lint:
gometalinter ./... --vendor --tests gometalinter --vendor ./...
test: test:
go test ./... -race -cover go test -race -cover ./...
build-docker: build-docker:
docker build . -f build/docker/Dockerfile -t s3manager docker build -f build/docker/Dockerfile -t s3manager .
deploy-cf: deploy-cf:
GOOS=linux GOARCH=amd64 go build ./cmd/s3manager GOOS=linux go build -ldflags="-s -w" ./cmd/s3manager
cf push -f deployments/cf/manifest.yml cf push -f deployments/cf/manifest.yml

View file

@ -5,7 +5,7 @@ COPY . .
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
RUN dep ensure RUN dep ensure
RUN go build ./cmd/s3manager RUN go build -ldflags="-s -w" ./cmd/s3manager
EXPOSE 8080 EXPOSE 8080

View file

@ -17,82 +17,82 @@ import (
func TestBucketViewHandler(t *testing.T) { func TestBucketViewHandler(t *testing.T) {
cases := map[string]struct { cases := map[string]struct {
s3 s3manager.S3 listObjectsV2Func func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo
bucketName string bucketName string
expectedStatusCode int expectedStatusCode int
expectedBodyContains string expectedBodyContains string
}{ }{
"renders a bucket containing a file": { "renders a bucket containing a file": {
s3: &s3Mock{ listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo {
Buckets: []minio.BucketInfo{ objCh := make(chan minio.ObjectInfo, 1)
{Name: "testBucket"}, defer close(objCh)
}, objCh <- minio.ObjectInfo{Key: "testFile"}
Objects: []minio.ObjectInfo{ return objCh
{Key: "testFile"},
},
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "testBucket", expectedBodyContains: "testFile",
}, },
"renders placeholder for an empty bucket": { "renders placeholder for an empty bucket": {
s3: &s3Mock{ listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo {
Buckets: []minio.BucketInfo{ objCh := make(chan minio.ObjectInfo)
{Name: "testBucket"}, defer close(objCh)
}, return objCh
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "No objects in", expectedBodyContains: "No objects in",
}, },
"renders a bucket containing an archive": { "renders a bucket containing an archive": {
s3: &s3Mock{ listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo {
Buckets: []minio.BucketInfo{ objCh := make(chan minio.ObjectInfo, 1)
{Name: "testBucket"}, defer close(objCh)
}, objCh <- minio.ObjectInfo{Key: "archive.tar.gz"}
Objects: []minio.ObjectInfo{ return objCh
{Key: "archive.tar.gz"},
},
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "archive", expectedBodyContains: "archive",
}, },
"renders a bucket containing an image": { "renders a bucket containing an image": {
s3: &s3Mock{ listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo {
Buckets: []minio.BucketInfo{ objCh := make(chan minio.ObjectInfo, 1)
{Name: "testBucket"}, defer close(objCh)
}, objCh <- minio.ObjectInfo{Key: "testImage.png"}
Objects: []minio.ObjectInfo{ return objCh
{Key: "testImage.png"},
},
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "photo", expectedBodyContains: "photo",
}, },
"renders a bucket containing a sound file": { "renders a bucket containing a sound file": {
s3: &s3Mock{ listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo {
Buckets: []minio.BucketInfo{ objCh := make(chan minio.ObjectInfo, 1)
{Name: "testBucket"}, defer close(objCh)
}, objCh <- minio.ObjectInfo{Key: "testSound.mp3"}
Objects: []minio.ObjectInfo{ return objCh
{Key: "testSound.mp3"},
},
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "music_note", expectedBodyContains: "music_note",
}, },
"returns error if the bucket doesn't exist": { "returns error if the bucket doesn't exist": {
s3: &s3Mock{}, listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo, 1)
defer close(objCh)
objCh <- minio.ObjectInfo{Err: s3manager.ErrBucketDoesNotExist}
return objCh
},
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusNotFound, expectedStatusCode: http.StatusNotFound,
expectedBodyContains: http.StatusText(http.StatusNotFound), expectedBodyContains: http.StatusText(http.StatusNotFound),
}, },
"returns error if there is an S3 error": { "returns error if there is an S3 error": {
s3: &s3Mock{ listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo {
Err: errors.New("mocked S3 error"), objCh := make(chan minio.ObjectInfo, 1)
defer close(objCh)
objCh <- minio.ObjectInfo{Err: errors.New("mocked S3 error")}
return objCh
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusInternalServerError, expectedStatusCode: http.StatusInternalServerError,
@ -104,12 +104,16 @@ func TestBucketViewHandler(t *testing.T) {
t.Run(tcID, func(t *testing.T) { t.Run(tcID, func(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
s3 := &S3Mock{
ListObjectsV2Func: tc.listObjectsV2Func,
}
tmplDir := filepath.Join("..", "..", "..", "web", "template") tmplDir := filepath.Join("..", "..", "..", "web", "template")
r := mux.NewRouter() r := mux.NewRouter()
r. r.
Methods(http.MethodGet). Methods(http.MethodGet).
Path("/buckets/{bucketName}"). Path("/buckets/{bucketName}").
Handler(s3manager.BucketViewHandler(tc.s3, tmplDir)) Handler(s3manager.BucketViewHandler(s3, tmplDir))
ts := httptest.NewServer(r) ts := httptest.NewServer(r)
defer ts.Close() defer ts.Close()

View file

@ -15,27 +15,27 @@ import (
func TestBucketsViewHandler(t *testing.T) { func TestBucketsViewHandler(t *testing.T) {
cases := map[string]struct { cases := map[string]struct {
s3 s3manager.S3 listBucketsFunc func() ([]minio.BucketInfo, error)
expectedStatusCode int expectedStatusCode int
expectedBodyContains string expectedBodyContains string
}{ }{
"renders a list of buckets": { "renders a list of buckets": {
s3: &s3Mock{ listBucketsFunc: func() ([]minio.BucketInfo, error) {
Buckets: []minio.BucketInfo{ return []minio.BucketInfo{{Name: "testBucket"}}, nil
{Name: "testBucket"},
},
}, },
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "testBucket", expectedBodyContains: "testBucket",
}, },
"renders placeholder if no buckets": { "renders placeholder if no buckets": {
s3: &s3Mock{}, listBucketsFunc: func() ([]minio.BucketInfo, error) {
return []minio.BucketInfo{}, nil
},
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "No buckets yet", expectedBodyContains: "No buckets yet",
}, },
"returns error if there is an S3 error": { "returns error if there is an S3 error": {
s3: &s3Mock{ listBucketsFunc: func() ([]minio.BucketInfo, error) {
Err: errors.New("mocked S3 error"), return []minio.BucketInfo{}, errors.New("mocked S3 error")
}, },
expectedStatusCode: http.StatusInternalServerError, expectedStatusCode: http.StatusInternalServerError,
expectedBodyContains: http.StatusText(http.StatusInternalServerError), expectedBodyContains: http.StatusText(http.StatusInternalServerError),
@ -46,18 +46,22 @@ func TestBucketsViewHandler(t *testing.T) {
t.Run(tcID, func(t *testing.T) { t.Run(tcID, func(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
s3 := &S3Mock{
ListBucketsFunc: tc.listBucketsFunc,
}
tmplDir := filepath.Join("..", "..", "..", "web", "template") tmplDir := filepath.Join("..", "..", "..", "web", "template")
r := mux.NewRouter() r := mux.NewRouter()
r. r.
Methods(http.MethodGet). Methods(http.MethodGet).
Path("/buckets/{bucketName}"). Path("/buckets/{bucketName}").
Handler(s3manager.BucketViewHandler(tc.s3, tmplDir)) Handler(s3manager.BucketViewHandler(s3, tmplDir))
req, err := http.NewRequest(http.MethodGet, "/buckets", nil) req, err := http.NewRequest(http.MethodGet, "/buckets", nil)
assert.NoError(err, tcID) assert.NoError(err, tcID)
rr := httptest.NewRecorder() rr := httptest.NewRecorder()
handler := s3manager.BucketsViewHandler(tc.s3, tmplDir) handler := s3manager.BucketsViewHandler(s3, tmplDir)
handler.ServeHTTP(rr, req) handler.ServeHTTP(rr, req)
resp := rr.Result() resp := rr.Result()

View file

@ -13,32 +13,38 @@ import (
func TestCreateBucketHandler(t *testing.T) { func TestCreateBucketHandler(t *testing.T) {
cases := map[string]struct { cases := map[string]struct {
s3 s3manager.S3 makeBucketFunc func(string, string) error
body string body string
expectedStatusCode int expectedStatusCode int
expectedBodyContains string expectedBodyContains string
}{ }{
"creates a new bucket": { "creates a new bucket": {
s3: &s3Mock{}, makeBucketFunc: func(bucketName string, location string) error {
return nil
},
body: "{\"name\":\"myBucket\"}", body: "{\"name\":\"myBucket\"}",
expectedStatusCode: http.StatusCreated, expectedStatusCode: http.StatusCreated,
expectedBodyContains: "{\"name\":\"myBucket\",\"creationDate\":\"0001-01-01T00:00:00Z\"}\n", expectedBodyContains: "{\"name\":\"myBucket\",\"creationDate\":\"0001-01-01T00:00:00Z\"}\n",
}, },
"returns error for empty request": { "returns error for empty request": {
s3: &s3Mock{}, makeBucketFunc: func(bucketName string, location string) error {
return nil
},
body: "", body: "",
expectedStatusCode: http.StatusUnprocessableEntity, expectedStatusCode: http.StatusUnprocessableEntity,
expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity), expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity),
}, },
"returns error for malformed request": { "returns error for malformed request": {
s3: &s3Mock{}, makeBucketFunc: func(bucketName string, location string) error {
return nil
},
body: "}", body: "}",
expectedStatusCode: http.StatusUnprocessableEntity, expectedStatusCode: http.StatusUnprocessableEntity,
expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity), expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity),
}, },
"returns error if there is an S3 error": { "returns error if there is an S3 error": {
s3: &s3Mock{ makeBucketFunc: func(bucketName string, location string) error {
Err: errors.New("mocked S3 error"), return errors.New("mocked S3 error")
}, },
body: "{\"name\":\"myBucket\"}", body: "{\"name\":\"myBucket\"}",
expectedStatusCode: http.StatusInternalServerError, expectedStatusCode: http.StatusInternalServerError,
@ -50,11 +56,15 @@ func TestCreateBucketHandler(t *testing.T) {
t.Run(tcID, func(t *testing.T) { t.Run(tcID, func(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
s3 := &S3Mock{
MakeBucketFunc: tc.makeBucketFunc,
}
req, err := http.NewRequest(http.MethodPost, "/api/buckets", bytes.NewBufferString(tc.body)) req, err := http.NewRequest(http.MethodPost, "/api/buckets", bytes.NewBufferString(tc.body))
assert.NoError(err, tcID) assert.NoError(err, tcID)
rr := httptest.NewRecorder() rr := httptest.NewRecorder()
handler := s3manager.CreateBucketHandler(tc.s3) handler := s3manager.CreateBucketHandler(s3)
handler.ServeHTTP(rr, req) handler.ServeHTTP(rr, req)
resp := rr.Result() resp := rr.Result()

View file

@ -12,18 +12,20 @@ import (
func TestDeleteBucketHandler(t *testing.T) { func TestDeleteBucketHandler(t *testing.T) {
cases := map[string]struct { cases := map[string]struct {
s3 s3manager.S3 removeBucketFunc func(string) error
expectedStatusCode int expectedStatusCode int
expectedBodyContains string expectedBodyContains string
}{ }{
"deletes an existing bucket": { "deletes an existing bucket": {
s3: &s3Mock{}, removeBucketFunc: func(bucketName string) error {
return nil
},
expectedStatusCode: http.StatusNoContent, expectedStatusCode: http.StatusNoContent,
expectedBodyContains: "", expectedBodyContains: "",
}, },
"returns error if there is an S3 error": { "returns error if there is an S3 error": {
s3: &s3Mock{ removeBucketFunc: func(bucketName string) error {
Err: errors.New("mocked S3 error"), return errors.New("mocked S3 error")
}, },
expectedStatusCode: http.StatusInternalServerError, expectedStatusCode: http.StatusInternalServerError,
expectedBodyContains: http.StatusText(http.StatusInternalServerError), expectedBodyContains: http.StatusText(http.StatusInternalServerError),
@ -34,11 +36,15 @@ func TestDeleteBucketHandler(t *testing.T) {
t.Run(tcID, func(t *testing.T) { t.Run(tcID, func(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
s3 := &S3Mock{
RemoveBucketFunc: tc.removeBucketFunc,
}
req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName", nil) req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName", nil)
assert.NoError(err, tcID) assert.NoError(err, tcID)
rr := httptest.NewRecorder() rr := httptest.NewRecorder()
handler := s3manager.DeleteBucketHandler(tc.s3) handler := s3manager.DeleteBucketHandler(s3)
handler.ServeHTTP(rr, req) handler.ServeHTTP(rr, req)
resp := rr.Result() resp := rr.Result()

View file

@ -12,18 +12,20 @@ import (
func TestDeleteObjectHandler(t *testing.T) { func TestDeleteObjectHandler(t *testing.T) {
cases := map[string]struct { cases := map[string]struct {
s3 s3manager.S3 removeObjectFunc func(string, string) error
expectedStatusCode int expectedStatusCode int
expectedBodyContains string expectedBodyContains string
}{ }{
"deletes an existing object": { "deletes an existing object": {
s3: &s3Mock{}, removeObjectFunc: func(bucketName string, objectName string) error {
return nil
},
expectedStatusCode: http.StatusNoContent, expectedStatusCode: http.StatusNoContent,
expectedBodyContains: "", expectedBodyContains: "",
}, },
"returns error if there is an S3 error": { "returns error if there is an S3 error": {
s3: &s3Mock{ removeObjectFunc: func(bucketName string, objectName string) error {
Err: errors.New("mocked S3 error"), return errors.New("mocked S3 error")
}, },
expectedStatusCode: http.StatusInternalServerError, expectedStatusCode: http.StatusInternalServerError,
expectedBodyContains: http.StatusText(http.StatusInternalServerError), expectedBodyContains: http.StatusText(http.StatusInternalServerError),
@ -34,11 +36,15 @@ func TestDeleteObjectHandler(t *testing.T) {
t.Run(tcID, func(t *testing.T) { t.Run(tcID, func(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
s3 := &S3Mock{
RemoveObjectFunc: tc.removeObjectFunc,
}
req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName/objects/objectName", nil) req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName/objects/objectName", nil)
assert.NoError(err, tcID) assert.NoError(err, tcID)
rr := httptest.NewRecorder() rr := httptest.NewRecorder()
handler := s3manager.DeleteObjectHandler(tc.s3) handler := s3manager.DeleteObjectHandler(s3)
handler.ServeHTTP(rr, req) handler.ServeHTTP(rr, req)

View file

@ -10,20 +10,21 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/mastertinner/s3manager/internal/app/s3manager" "github.com/mastertinner/s3manager/internal/app/s3manager"
minio "github.com/minio/minio-go"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestGetObjectHandler(t *testing.T) { func TestGetObjectHandler(t *testing.T) {
cases := map[string]struct { cases := map[string]struct {
s3 s3manager.S3 getObjectFunc func(string, string, minio.GetObjectOptions) (*minio.Object, error)
bucketName string bucketName string
objectName string objectName string
expectedStatusCode int expectedStatusCode int
expectedBodyContains string expectedBodyContains string
}{ }{
"returns error if there is an S3 error": { "returns error if there is an S3 error": {
s3: &s3Mock{ getObjectFunc: func(bucketName string, objectName string, opts minio.GetObjectOptions) (*minio.Object, error) {
Err: errors.New("mocked S3 error"), return nil, errors.New("mocked S3 error")
}, },
bucketName: "testBucket", bucketName: "testBucket",
objectName: "testObject", objectName: "testObject",
@ -36,11 +37,15 @@ func TestGetObjectHandler(t *testing.T) {
t.Run(tcID, func(t *testing.T) { t.Run(tcID, func(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
s3 := &S3Mock{
GetObjectFunc: tc.getObjectFunc,
}
r := mux.NewRouter() r := mux.NewRouter()
r. r.
Methods(http.MethodGet). Methods(http.MethodGet).
Path("/buckets/{bucketName}/objects/{objectName}"). Path("/buckets/{bucketName}/objects/{objectName}").
Handler(s3manager.GetObjectHandler(tc.s3)) Handler(s3manager.GetObjectHandler(s3))
ts := httptest.NewServer(r) ts := httptest.NewServer(r)
defer ts.Close() defer ts.Close()

View file

@ -6,6 +6,8 @@ import (
minio "github.com/minio/minio-go" minio "github.com/minio/minio-go"
) )
//go:generate moq -out s3_test.go -pkg s3manager_test . S3
// S3 is a client to interact with S3 storage. // S3 is a client to interact with S3 storage.
type S3 interface { type S3 interface {
CopyObject(minio.DestinationInfo, minio.SourceInfo) error CopyObject(minio.DestinationInfo, minio.SourceInfo) error

View file

@ -1,88 +1,440 @@
// Code generated by moq; DO NOT EDIT
// github.com/matryer/moq
package s3manager_test package s3manager_test
import ( import (
"github.com/minio/minio-go"
"io" "io"
"sync"
"github.com/mastertinner/s3manager/internal/app/s3manager"
minio "github.com/minio/minio-go"
) )
// s3Mock is a mocked S3 client. var (
type s3Mock struct { lockS3MockCopyObject sync.RWMutex
Buckets []minio.BucketInfo lockS3MockGetObject sync.RWMutex
Objects []minio.ObjectInfo lockS3MockListBuckets sync.RWMutex
Err error lockS3MockListObjectsV2 sync.RWMutex
} lockS3MockMakeBucket sync.RWMutex
lockS3MockPutObject sync.RWMutex
lockS3MockRemoveBucket sync.RWMutex
lockS3MockRemoveObject sync.RWMutex
)
// CopyObject mocks minio.Client.CopyObject. // S3Mock is a mock implementation of S3.
func (s *s3Mock) CopyObject(minio.DestinationInfo, minio.SourceInfo) error { //
return s.Err // func TestSomethingThatUsesS3(t *testing.T) {
} //
// // make and configure a mocked S3
// mockedS3 := &S3Mock{
// CopyObjectFunc: func(in1 minio.DestinationInfo, in2 minio.SourceInfo) error {
// panic("TODO: mock out the CopyObject method")
// },
// GetObjectFunc: func(in1 string, in2 string, in3 minio.GetObjectOptions) (*minio.Object, error) {
// panic("TODO: mock out the GetObject method")
// },
// ListBucketsFunc: func() ([]minio.BucketInfo, error) {
// panic("TODO: mock out the ListBuckets method")
// },
// ListObjectsV2Func: func(in1 string, in2 string, in3 bool, in4 <-chan struct{}) <-chan minio.ObjectInfo {
// panic("TODO: mock out the ListObjectsV2 method")
// },
// MakeBucketFunc: func(in1 string, in2 string) error {
// panic("TODO: mock out the MakeBucket method")
// },
// PutObjectFunc: func(in1 string, in2 string, in3 io.Reader, in4 int64, in5 minio.PutObjectOptions) (int64, error) {
// panic("TODO: mock out the PutObject method")
// },
// RemoveBucketFunc: func(in1 string) error {
// panic("TODO: mock out the RemoveBucket method")
// },
// RemoveObjectFunc: func(in1 string, in2 string) error {
// panic("TODO: mock out the RemoveObject method")
// },
// }
//
// // TODO: use mockedS3 in code that requires S3
// // and then make assertions.
//
// }
type S3Mock struct {
// CopyObjectFunc mocks the CopyObject method.
CopyObjectFunc func(in1 minio.DestinationInfo, in2 minio.SourceInfo) error
// GetObject mocks minio.Client.GetObject. // GetObjectFunc mocks the GetObject method.
func (s *s3Mock) GetObject(bucketName string, objectName string, opts minio.GetObjectOptions) (*minio.Object, error) { GetObjectFunc func(in1 string, in2 string, in3 minio.GetObjectOptions) (*minio.Object, error)
if s.Err != nil {
return nil, s.Err
}
return &minio.Object{}, nil // ListBucketsFunc mocks the ListBuckets method.
} ListBucketsFunc func() ([]minio.BucketInfo, error)
// ListBuckets mocks minio.Client.ListBuckets. // ListObjectsV2Func mocks the ListObjectsV2 method.
func (s *s3Mock) ListBuckets() ([]minio.BucketInfo, error) { ListObjectsV2Func func(in1 string, in2 string, in3 bool, in4 <-chan struct{}) <-chan minio.ObjectInfo
return s.Buckets, s.Err
}
// ListObjectsV2 mocks minio.Client.ListObjectsV2. // MakeBucketFunc mocks the MakeBucket method.
func (s *s3Mock) ListObjectsV2(name string, p string, r bool, d <-chan struct{}) <-chan minio.ObjectInfo { MakeBucketFunc func(in1 string, in2 string) error
// Add error if exists
if s.Err != nil {
s.Objects = append(s.Objects, minio.ObjectInfo{
Err: s.Err,
})
}
// Check if bucket exists // PutObjectFunc mocks the PutObject method.
found := false PutObjectFunc func(in1 string, in2 string, in3 io.Reader, in4 int64, in5 minio.PutObjectOptions) (int64, error)
for _, b := range s.Buckets {
if b.Name == name { // RemoveBucketFunc mocks the RemoveBucket method.
found = true RemoveBucketFunc func(in1 string) error
break
// RemoveObjectFunc mocks the RemoveObject method.
RemoveObjectFunc func(in1 string, in2 string) error
// calls tracks calls to the methods.
calls struct {
// CopyObject holds details about calls to the CopyObject method.
CopyObject []struct {
// In1 is the in1 argument value.
In1 minio.DestinationInfo
// In2 is the in2 argument value.
In2 minio.SourceInfo
}
// GetObject holds details about calls to the GetObject method.
GetObject []struct {
// In1 is the in1 argument value.
In1 string
// In2 is the in2 argument value.
In2 string
// In3 is the in3 argument value.
In3 minio.GetObjectOptions
}
// ListBuckets holds details about calls to the ListBuckets method.
ListBuckets []struct {
}
// ListObjectsV2 holds details about calls to the ListObjectsV2 method.
ListObjectsV2 []struct {
// In1 is the in1 argument value.
In1 string
// In2 is the in2 argument value.
In2 string
// In3 is the in3 argument value.
In3 bool
// In4 is the in4 argument value.
In4 <-chan struct{}
}
// MakeBucket holds details about calls to the MakeBucket method.
MakeBucket []struct {
// In1 is the in1 argument value.
In1 string
// In2 is the in2 argument value.
In2 string
}
// PutObject holds details about calls to the PutObject method.
PutObject []struct {
// In1 is the in1 argument value.
In1 string
// In2 is the in2 argument value.
In2 string
// In3 is the in3 argument value.
In3 io.Reader
// In4 is the in4 argument value.
In4 int64
// In5 is the in5 argument value.
In5 minio.PutObjectOptions
}
// RemoveBucket holds details about calls to the RemoveBucket method.
RemoveBucket []struct {
// In1 is the in1 argument value.
In1 string
}
// RemoveObject holds details about calls to the RemoveObject method.
RemoveObject []struct {
// In1 is the in1 argument value.
In1 string
// In2 is the in2 argument value.
In2 string
} }
} }
if !found { }
s.Objects = append(s.Objects, minio.ObjectInfo{
Err: s3manager.ErrBucketDoesNotExist,
})
// CopyObject calls CopyObjectFunc.
func (mock *S3Mock) CopyObject(in1 minio.DestinationInfo, in2 minio.SourceInfo) error {
if mock.CopyObjectFunc == nil {
panic("moq: S3Mock.CopyObjectFunc is nil but S3.CopyObject was just called")
} }
callInfo := struct {
objCh := make(chan minio.ObjectInfo, len(s.Objects)) In1 minio.DestinationInfo
defer close(objCh) In2 minio.SourceInfo
}{
for _, obj := range s.Objects { In1: in1,
objCh <- obj In2: in2,
} }
lockS3MockCopyObject.Lock()
return objCh mock.calls.CopyObject = append(mock.calls.CopyObject, callInfo)
lockS3MockCopyObject.Unlock()
return mock.CopyObjectFunc(in1, in2)
} }
// MakeBucket mocks minio.Client.MakeBucket. // CopyObjectCalls gets all the calls that were made to CopyObject.
func (s *s3Mock) MakeBucket(string, string) error { // Check the length with:
return s.Err // len(mockedS3.CopyObjectCalls())
func (mock *S3Mock) CopyObjectCalls() []struct {
In1 minio.DestinationInfo
In2 minio.SourceInfo
} {
var calls []struct {
In1 minio.DestinationInfo
In2 minio.SourceInfo
}
lockS3MockCopyObject.RLock()
calls = mock.calls.CopyObject
lockS3MockCopyObject.RUnlock()
return calls
} }
// PutObject mocks minio.Client.PutObject. // GetObject calls GetObjectFunc.
func (s *s3Mock) PutObject(string, string, io.Reader, int64, minio.PutObjectOptions) (int64, error) { func (mock *S3Mock) GetObject(in1 string, in2 string, in3 minio.GetObjectOptions) (*minio.Object, error) {
return 0, s.Err if mock.GetObjectFunc == nil {
panic("moq: S3Mock.GetObjectFunc is nil but S3.GetObject was just called")
}
callInfo := struct {
In1 string
In2 string
In3 minio.GetObjectOptions
}{
In1: in1,
In2: in2,
In3: in3,
}
lockS3MockGetObject.Lock()
mock.calls.GetObject = append(mock.calls.GetObject, callInfo)
lockS3MockGetObject.Unlock()
return mock.GetObjectFunc(in1, in2, in3)
} }
// RemoveBucket mocks minio.Client.RemoveBucket. // GetObjectCalls gets all the calls that were made to GetObject.
func (s *s3Mock) RemoveBucket(string) error { // Check the length with:
return s.Err // len(mockedS3.GetObjectCalls())
func (mock *S3Mock) GetObjectCalls() []struct {
In1 string
In2 string
In3 minio.GetObjectOptions
} {
var calls []struct {
In1 string
In2 string
In3 minio.GetObjectOptions
}
lockS3MockGetObject.RLock()
calls = mock.calls.GetObject
lockS3MockGetObject.RUnlock()
return calls
} }
// RemoveObject mocks minio.Client.RemoveObject. // ListBuckets calls ListBucketsFunc.
func (s *s3Mock) RemoveObject(string, string) error { func (mock *S3Mock) ListBuckets() ([]minio.BucketInfo, error) {
return s.Err if mock.ListBucketsFunc == nil {
panic("moq: S3Mock.ListBucketsFunc is nil but S3.ListBuckets was just called")
}
callInfo := struct {
}{}
lockS3MockListBuckets.Lock()
mock.calls.ListBuckets = append(mock.calls.ListBuckets, callInfo)
lockS3MockListBuckets.Unlock()
return mock.ListBucketsFunc()
}
// ListBucketsCalls gets all the calls that were made to ListBuckets.
// Check the length with:
// len(mockedS3.ListBucketsCalls())
func (mock *S3Mock) ListBucketsCalls() []struct {
} {
var calls []struct {
}
lockS3MockListBuckets.RLock()
calls = mock.calls.ListBuckets
lockS3MockListBuckets.RUnlock()
return calls
}
// ListObjectsV2 calls ListObjectsV2Func.
func (mock *S3Mock) ListObjectsV2(in1 string, in2 string, in3 bool, in4 <-chan struct{}) <-chan minio.ObjectInfo {
if mock.ListObjectsV2Func == nil {
panic("moq: S3Mock.ListObjectsV2Func is nil but S3.ListObjectsV2 was just called")
}
callInfo := struct {
In1 string
In2 string
In3 bool
In4 <-chan struct{}
}{
In1: in1,
In2: in2,
In3: in3,
In4: in4,
}
lockS3MockListObjectsV2.Lock()
mock.calls.ListObjectsV2 = append(mock.calls.ListObjectsV2, callInfo)
lockS3MockListObjectsV2.Unlock()
return mock.ListObjectsV2Func(in1, in2, in3, in4)
}
// ListObjectsV2Calls gets all the calls that were made to ListObjectsV2.
// Check the length with:
// len(mockedS3.ListObjectsV2Calls())
func (mock *S3Mock) ListObjectsV2Calls() []struct {
In1 string
In2 string
In3 bool
In4 <-chan struct{}
} {
var calls []struct {
In1 string
In2 string
In3 bool
In4 <-chan struct{}
}
lockS3MockListObjectsV2.RLock()
calls = mock.calls.ListObjectsV2
lockS3MockListObjectsV2.RUnlock()
return calls
}
// MakeBucket calls MakeBucketFunc.
func (mock *S3Mock) MakeBucket(in1 string, in2 string) error {
if mock.MakeBucketFunc == nil {
panic("moq: S3Mock.MakeBucketFunc is nil but S3.MakeBucket was just called")
}
callInfo := struct {
In1 string
In2 string
}{
In1: in1,
In2: in2,
}
lockS3MockMakeBucket.Lock()
mock.calls.MakeBucket = append(mock.calls.MakeBucket, callInfo)
lockS3MockMakeBucket.Unlock()
return mock.MakeBucketFunc(in1, in2)
}
// MakeBucketCalls gets all the calls that were made to MakeBucket.
// Check the length with:
// len(mockedS3.MakeBucketCalls())
func (mock *S3Mock) MakeBucketCalls() []struct {
In1 string
In2 string
} {
var calls []struct {
In1 string
In2 string
}
lockS3MockMakeBucket.RLock()
calls = mock.calls.MakeBucket
lockS3MockMakeBucket.RUnlock()
return calls
}
// PutObject calls PutObjectFunc.
func (mock *S3Mock) PutObject(in1 string, in2 string, in3 io.Reader, in4 int64, in5 minio.PutObjectOptions) (int64, error) {
if mock.PutObjectFunc == nil {
panic("moq: S3Mock.PutObjectFunc is nil but S3.PutObject was just called")
}
callInfo := struct {
In1 string
In2 string
In3 io.Reader
In4 int64
In5 minio.PutObjectOptions
}{
In1: in1,
In2: in2,
In3: in3,
In4: in4,
In5: in5,
}
lockS3MockPutObject.Lock()
mock.calls.PutObject = append(mock.calls.PutObject, callInfo)
lockS3MockPutObject.Unlock()
return mock.PutObjectFunc(in1, in2, in3, in4, in5)
}
// PutObjectCalls gets all the calls that were made to PutObject.
// Check the length with:
// len(mockedS3.PutObjectCalls())
func (mock *S3Mock) PutObjectCalls() []struct {
In1 string
In2 string
In3 io.Reader
In4 int64
In5 minio.PutObjectOptions
} {
var calls []struct {
In1 string
In2 string
In3 io.Reader
In4 int64
In5 minio.PutObjectOptions
}
lockS3MockPutObject.RLock()
calls = mock.calls.PutObject
lockS3MockPutObject.RUnlock()
return calls
}
// RemoveBucket calls RemoveBucketFunc.
func (mock *S3Mock) RemoveBucket(in1 string) error {
if mock.RemoveBucketFunc == nil {
panic("moq: S3Mock.RemoveBucketFunc is nil but S3.RemoveBucket was just called")
}
callInfo := struct {
In1 string
}{
In1: in1,
}
lockS3MockRemoveBucket.Lock()
mock.calls.RemoveBucket = append(mock.calls.RemoveBucket, callInfo)
lockS3MockRemoveBucket.Unlock()
return mock.RemoveBucketFunc(in1)
}
// RemoveBucketCalls gets all the calls that were made to RemoveBucket.
// Check the length with:
// len(mockedS3.RemoveBucketCalls())
func (mock *S3Mock) RemoveBucketCalls() []struct {
In1 string
} {
var calls []struct {
In1 string
}
lockS3MockRemoveBucket.RLock()
calls = mock.calls.RemoveBucket
lockS3MockRemoveBucket.RUnlock()
return calls
}
// RemoveObject calls RemoveObjectFunc.
func (mock *S3Mock) RemoveObject(in1 string, in2 string) error {
if mock.RemoveObjectFunc == nil {
panic("moq: S3Mock.RemoveObjectFunc is nil but S3.RemoveObject was just called")
}
callInfo := struct {
In1 string
In2 string
}{
In1: in1,
In2: in2,
}
lockS3MockRemoveObject.Lock()
mock.calls.RemoveObject = append(mock.calls.RemoveObject, callInfo)
lockS3MockRemoveObject.Unlock()
return mock.RemoveObjectFunc(in1, in2)
}
// RemoveObjectCalls gets all the calls that were made to RemoveObject.
// Check the length with:
// len(mockedS3.RemoveObjectCalls())
func (mock *S3Mock) RemoveObjectCalls() []struct {
In1 string
In2 string
} {
var calls []struct {
In1 string
In2 string
}
lockS3MockRemoveObject.RLock()
calls = mock.calls.RemoveObject
lockS3MockRemoveObject.RUnlock()
return calls
} }