From f7f0bfb51fe60aa311d6fdc6e2598ead0334b30f Mon Sep 17 00:00:00 2001 From: Lena Fuhrimann <6780471+cloudlena@users.noreply.github.com> Date: Tue, 24 Apr 2018 22:35:21 +0200 Subject: [PATCH] Use moq to mock S3 interface --- Gopkg.lock | 6 +- Makefile | 12 +- build/docker/Dockerfile | 2 +- internal/app/s3manager/bucket_view_test.go | 80 ++-- internal/app/s3manager/buckets_view_test.go | 24 +- internal/app/s3manager/create_bucket_test.go | 24 +- internal/app/s3manager/delete_bucket_test.go | 16 +- internal/app/s3manager/delete_object_test.go | 16 +- internal/app/s3manager/get_object_test.go | 13 +- internal/app/s3manager/s3.go | 2 + internal/app/s3manager/s3_test.go | 476 ++++++++++++++++--- 11 files changed, 531 insertions(+), 140 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 08f7fd0..f38e61f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -11,7 +11,7 @@ branch = "master" name = "github.com/dustin/go-humanize" packages = ["."] - revision = "bb3d318650d48840a39aa21a027c6630e198e626" + revision = "02af3965c54e8cacf948b97fef38925c4120652c" [[projects]] name = "github.com/go-ini/ini" @@ -88,7 +88,7 @@ "blake2b", "ssh/terminal" ] - revision = "e73bf333ef8920dbb52ad18d4bd38ad9d9bc76d7" + revision = "b49d69b5da943f7ef3c9cf91c8777c1f78a0cc3c" [[projects]] branch = "master" @@ -106,7 +106,7 @@ "unix", "windows" ] - revision = "79b0c6888797020a994db17c8510466c72fe75d9" + revision = "cbbc999da32df943dac6cd71eb3ee39e1d7838b9" [[projects]] name = "golang.org/x/text" diff --git a/Makefile b/Makefile index 192e770..7b4b756 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,17 @@ +.PHONY: all lint test build-docker deploy-cf + all: - go build ./cmd/s3manager + go build ./cmd/... lint: - gometalinter ./... --vendor --tests + gometalinter --vendor ./... test: - go test ./... -race -cover + go test -race -cover ./... build-docker: - docker build . -f build/docker/Dockerfile -t s3manager + docker build -f build/docker/Dockerfile -t s3manager . 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 diff --git a/build/docker/Dockerfile b/build/docker/Dockerfile index b517a2d..02c34ec 100644 --- a/build/docker/Dockerfile +++ b/build/docker/Dockerfile @@ -5,7 +5,7 @@ COPY . . RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh RUN dep ensure -RUN go build ./cmd/s3manager +RUN go build -ldflags="-s -w" ./cmd/s3manager EXPOSE 8080 diff --git a/internal/app/s3manager/bucket_view_test.go b/internal/app/s3manager/bucket_view_test.go index 81536e6..7840efb 100644 --- a/internal/app/s3manager/bucket_view_test.go +++ b/internal/app/s3manager/bucket_view_test.go @@ -17,82 +17,82 @@ import ( func TestBucketViewHandler(t *testing.T) { cases := map[string]struct { - s3 s3manager.S3 + listObjectsV2Func func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo bucketName string expectedStatusCode int expectedBodyContains string }{ "renders a bucket containing a file": { - s3: &s3Mock{ - Buckets: []minio.BucketInfo{ - {Name: "testBucket"}, - }, - Objects: []minio.ObjectInfo{ - {Key: "testFile"}, - }, + 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{Key: "testFile"} + return objCh }, bucketName: "testBucket", expectedStatusCode: http.StatusOK, - expectedBodyContains: "testBucket", + expectedBodyContains: "testFile", }, "renders placeholder for an empty bucket": { - s3: &s3Mock{ - Buckets: []minio.BucketInfo{ - {Name: "testBucket"}, - }, + listObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo { + objCh := make(chan minio.ObjectInfo) + defer close(objCh) + return objCh }, bucketName: "testBucket", expectedStatusCode: http.StatusOK, expectedBodyContains: "No objects in", }, "renders a bucket containing an archive": { - s3: &s3Mock{ - Buckets: []minio.BucketInfo{ - {Name: "testBucket"}, - }, - Objects: []minio.ObjectInfo{ - {Key: "archive.tar.gz"}, - }, + 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{Key: "archive.tar.gz"} + return objCh }, bucketName: "testBucket", expectedStatusCode: http.StatusOK, expectedBodyContains: "archive", }, "renders a bucket containing an image": { - s3: &s3Mock{ - Buckets: []minio.BucketInfo{ - {Name: "testBucket"}, - }, - Objects: []minio.ObjectInfo{ - {Key: "testImage.png"}, - }, + 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{Key: "testImage.png"} + return objCh }, bucketName: "testBucket", expectedStatusCode: http.StatusOK, expectedBodyContains: "photo", }, "renders a bucket containing a sound file": { - s3: &s3Mock{ - Buckets: []minio.BucketInfo{ - {Name: "testBucket"}, - }, - Objects: []minio.ObjectInfo{ - {Key: "testSound.mp3"}, - }, + 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{Key: "testSound.mp3"} + return objCh }, bucketName: "testBucket", expectedStatusCode: http.StatusOK, expectedBodyContains: "music_note", }, "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", expectedStatusCode: http.StatusNotFound, expectedBodyContains: http.StatusText(http.StatusNotFound), }, "returns error if there is an S3 error": { - s3: &s3Mock{ - Err: errors.New("mocked S3 error"), + 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: errors.New("mocked S3 error")} + return objCh }, bucketName: "testBucket", expectedStatusCode: http.StatusInternalServerError, @@ -104,12 +104,16 @@ func TestBucketViewHandler(t *testing.T) { t.Run(tcID, func(t *testing.T) { assert := assert.New(t) + s3 := &S3Mock{ + ListObjectsV2Func: tc.listObjectsV2Func, + } + tmplDir := filepath.Join("..", "..", "..", "web", "template") r := mux.NewRouter() r. Methods(http.MethodGet). Path("/buckets/{bucketName}"). - Handler(s3manager.BucketViewHandler(tc.s3, tmplDir)) + Handler(s3manager.BucketViewHandler(s3, tmplDir)) ts := httptest.NewServer(r) defer ts.Close() diff --git a/internal/app/s3manager/buckets_view_test.go b/internal/app/s3manager/buckets_view_test.go index 9c79b41..cba0352 100644 --- a/internal/app/s3manager/buckets_view_test.go +++ b/internal/app/s3manager/buckets_view_test.go @@ -15,27 +15,27 @@ import ( func TestBucketsViewHandler(t *testing.T) { cases := map[string]struct { - s3 s3manager.S3 + listBucketsFunc func() ([]minio.BucketInfo, error) expectedStatusCode int expectedBodyContains string }{ "renders a list of buckets": { - s3: &s3Mock{ - Buckets: []minio.BucketInfo{ - {Name: "testBucket"}, - }, + listBucketsFunc: func() ([]minio.BucketInfo, error) { + return []minio.BucketInfo{{Name: "testBucket"}}, nil }, expectedStatusCode: http.StatusOK, expectedBodyContains: "testBucket", }, "renders placeholder if no buckets": { - s3: &s3Mock{}, + listBucketsFunc: func() ([]minio.BucketInfo, error) { + return []minio.BucketInfo{}, nil + }, expectedStatusCode: http.StatusOK, expectedBodyContains: "No buckets yet", }, "returns error if there is an S3 error": { - s3: &s3Mock{ - Err: errors.New("mocked S3 error"), + listBucketsFunc: func() ([]minio.BucketInfo, error) { + return []minio.BucketInfo{}, errors.New("mocked S3 error") }, expectedStatusCode: http.StatusInternalServerError, expectedBodyContains: http.StatusText(http.StatusInternalServerError), @@ -46,18 +46,22 @@ func TestBucketsViewHandler(t *testing.T) { t.Run(tcID, func(t *testing.T) { assert := assert.New(t) + s3 := &S3Mock{ + ListBucketsFunc: tc.listBucketsFunc, + } + tmplDir := filepath.Join("..", "..", "..", "web", "template") r := mux.NewRouter() r. Methods(http.MethodGet). Path("/buckets/{bucketName}"). - Handler(s3manager.BucketViewHandler(tc.s3, tmplDir)) + Handler(s3manager.BucketViewHandler(s3, tmplDir)) req, err := http.NewRequest(http.MethodGet, "/buckets", nil) assert.NoError(err, tcID) rr := httptest.NewRecorder() - handler := s3manager.BucketsViewHandler(tc.s3, tmplDir) + handler := s3manager.BucketsViewHandler(s3, tmplDir) handler.ServeHTTP(rr, req) resp := rr.Result() diff --git a/internal/app/s3manager/create_bucket_test.go b/internal/app/s3manager/create_bucket_test.go index 5896475..68ec8ad 100644 --- a/internal/app/s3manager/create_bucket_test.go +++ b/internal/app/s3manager/create_bucket_test.go @@ -13,32 +13,38 @@ import ( func TestCreateBucketHandler(t *testing.T) { cases := map[string]struct { - s3 s3manager.S3 + makeBucketFunc func(string, string) error body string expectedStatusCode int expectedBodyContains string }{ "creates a new bucket": { - s3: &s3Mock{}, + makeBucketFunc: func(bucketName string, location string) error { + return nil + }, body: "{\"name\":\"myBucket\"}", expectedStatusCode: http.StatusCreated, expectedBodyContains: "{\"name\":\"myBucket\",\"creationDate\":\"0001-01-01T00:00:00Z\"}\n", }, "returns error for empty request": { - s3: &s3Mock{}, + makeBucketFunc: func(bucketName string, location string) error { + return nil + }, body: "", expectedStatusCode: http.StatusUnprocessableEntity, expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity), }, "returns error for malformed request": { - s3: &s3Mock{}, + makeBucketFunc: func(bucketName string, location string) error { + return nil + }, body: "}", expectedStatusCode: http.StatusUnprocessableEntity, expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity), }, "returns error if there is an S3 error": { - s3: &s3Mock{ - Err: errors.New("mocked S3 error"), + makeBucketFunc: func(bucketName string, location string) error { + return errors.New("mocked S3 error") }, body: "{\"name\":\"myBucket\"}", expectedStatusCode: http.StatusInternalServerError, @@ -50,11 +56,15 @@ func TestCreateBucketHandler(t *testing.T) { t.Run(tcID, func(t *testing.T) { assert := assert.New(t) + s3 := &S3Mock{ + MakeBucketFunc: tc.makeBucketFunc, + } + req, err := http.NewRequest(http.MethodPost, "/api/buckets", bytes.NewBufferString(tc.body)) assert.NoError(err, tcID) rr := httptest.NewRecorder() - handler := s3manager.CreateBucketHandler(tc.s3) + handler := s3manager.CreateBucketHandler(s3) handler.ServeHTTP(rr, req) resp := rr.Result() diff --git a/internal/app/s3manager/delete_bucket_test.go b/internal/app/s3manager/delete_bucket_test.go index c8c9983..5201a8e 100644 --- a/internal/app/s3manager/delete_bucket_test.go +++ b/internal/app/s3manager/delete_bucket_test.go @@ -12,18 +12,20 @@ import ( func TestDeleteBucketHandler(t *testing.T) { cases := map[string]struct { - s3 s3manager.S3 + removeBucketFunc func(string) error expectedStatusCode int expectedBodyContains string }{ "deletes an existing bucket": { - s3: &s3Mock{}, + removeBucketFunc: func(bucketName string) error { + return nil + }, expectedStatusCode: http.StatusNoContent, expectedBodyContains: "", }, "returns error if there is an S3 error": { - s3: &s3Mock{ - Err: errors.New("mocked S3 error"), + removeBucketFunc: func(bucketName string) error { + return errors.New("mocked S3 error") }, expectedStatusCode: http.StatusInternalServerError, expectedBodyContains: http.StatusText(http.StatusInternalServerError), @@ -34,11 +36,15 @@ func TestDeleteBucketHandler(t *testing.T) { t.Run(tcID, func(t *testing.T) { assert := assert.New(t) + s3 := &S3Mock{ + RemoveBucketFunc: tc.removeBucketFunc, + } + req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName", nil) assert.NoError(err, tcID) rr := httptest.NewRecorder() - handler := s3manager.DeleteBucketHandler(tc.s3) + handler := s3manager.DeleteBucketHandler(s3) handler.ServeHTTP(rr, req) resp := rr.Result() diff --git a/internal/app/s3manager/delete_object_test.go b/internal/app/s3manager/delete_object_test.go index 988d355..8e24e8a 100644 --- a/internal/app/s3manager/delete_object_test.go +++ b/internal/app/s3manager/delete_object_test.go @@ -12,18 +12,20 @@ import ( func TestDeleteObjectHandler(t *testing.T) { cases := map[string]struct { - s3 s3manager.S3 + removeObjectFunc func(string, string) error expectedStatusCode int expectedBodyContains string }{ "deletes an existing object": { - s3: &s3Mock{}, + removeObjectFunc: func(bucketName string, objectName string) error { + return nil + }, expectedStatusCode: http.StatusNoContent, expectedBodyContains: "", }, "returns error if there is an S3 error": { - s3: &s3Mock{ - Err: errors.New("mocked S3 error"), + removeObjectFunc: func(bucketName string, objectName string) error { + return errors.New("mocked S3 error") }, expectedStatusCode: http.StatusInternalServerError, expectedBodyContains: http.StatusText(http.StatusInternalServerError), @@ -34,11 +36,15 @@ func TestDeleteObjectHandler(t *testing.T) { t.Run(tcID, func(t *testing.T) { assert := assert.New(t) + s3 := &S3Mock{ + RemoveObjectFunc: tc.removeObjectFunc, + } + req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName/objects/objectName", nil) assert.NoError(err, tcID) rr := httptest.NewRecorder() - handler := s3manager.DeleteObjectHandler(tc.s3) + handler := s3manager.DeleteObjectHandler(s3) handler.ServeHTTP(rr, req) diff --git a/internal/app/s3manager/get_object_test.go b/internal/app/s3manager/get_object_test.go index 7ca92e8..708fb45 100644 --- a/internal/app/s3manager/get_object_test.go +++ b/internal/app/s3manager/get_object_test.go @@ -10,20 +10,21 @@ import ( "github.com/gorilla/mux" "github.com/mastertinner/s3manager/internal/app/s3manager" + minio "github.com/minio/minio-go" "github.com/stretchr/testify/assert" ) func TestGetObjectHandler(t *testing.T) { cases := map[string]struct { - s3 s3manager.S3 + getObjectFunc func(string, string, minio.GetObjectOptions) (*minio.Object, error) bucketName string objectName string expectedStatusCode int expectedBodyContains string }{ "returns error if there is an S3 error": { - s3: &s3Mock{ - Err: errors.New("mocked S3 error"), + getObjectFunc: func(bucketName string, objectName string, opts minio.GetObjectOptions) (*minio.Object, error) { + return nil, errors.New("mocked S3 error") }, bucketName: "testBucket", objectName: "testObject", @@ -36,11 +37,15 @@ func TestGetObjectHandler(t *testing.T) { t.Run(tcID, func(t *testing.T) { assert := assert.New(t) + s3 := &S3Mock{ + GetObjectFunc: tc.getObjectFunc, + } + r := mux.NewRouter() r. Methods(http.MethodGet). Path("/buckets/{bucketName}/objects/{objectName}"). - Handler(s3manager.GetObjectHandler(tc.s3)) + Handler(s3manager.GetObjectHandler(s3)) ts := httptest.NewServer(r) defer ts.Close() diff --git a/internal/app/s3manager/s3.go b/internal/app/s3manager/s3.go index d0588e2..aaf3ba9 100644 --- a/internal/app/s3manager/s3.go +++ b/internal/app/s3manager/s3.go @@ -6,6 +6,8 @@ import ( 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. type S3 interface { CopyObject(minio.DestinationInfo, minio.SourceInfo) error diff --git a/internal/app/s3manager/s3_test.go b/internal/app/s3manager/s3_test.go index 2b8131c..f82084e 100644 --- a/internal/app/s3manager/s3_test.go +++ b/internal/app/s3manager/s3_test.go @@ -1,88 +1,440 @@ +// Code generated by moq; DO NOT EDIT +// github.com/matryer/moq + package s3manager_test import ( + "github.com/minio/minio-go" "io" - - "github.com/mastertinner/s3manager/internal/app/s3manager" - minio "github.com/minio/minio-go" + "sync" ) -// s3Mock is a mocked S3 client. -type s3Mock struct { - Buckets []minio.BucketInfo - Objects []minio.ObjectInfo - Err error -} +var ( + lockS3MockCopyObject sync.RWMutex + lockS3MockGetObject sync.RWMutex + lockS3MockListBuckets sync.RWMutex + lockS3MockListObjectsV2 sync.RWMutex + lockS3MockMakeBucket sync.RWMutex + lockS3MockPutObject sync.RWMutex + lockS3MockRemoveBucket sync.RWMutex + lockS3MockRemoveObject sync.RWMutex +) -// CopyObject mocks minio.Client.CopyObject. -func (s *s3Mock) CopyObject(minio.DestinationInfo, minio.SourceInfo) error { - return s.Err -} +// S3Mock is a mock implementation of S3. +// +// 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. -func (s *s3Mock) GetObject(bucketName string, objectName string, opts minio.GetObjectOptions) (*minio.Object, error) { - if s.Err != nil { - return nil, s.Err - } + // GetObjectFunc mocks the GetObject method. + GetObjectFunc func(in1 string, in2 string, in3 minio.GetObjectOptions) (*minio.Object, error) - return &minio.Object{}, nil -} + // ListBucketsFunc mocks the ListBuckets method. + ListBucketsFunc func() ([]minio.BucketInfo, error) -// ListBuckets mocks minio.Client.ListBuckets. -func (s *s3Mock) ListBuckets() ([]minio.BucketInfo, error) { - return s.Buckets, s.Err -} + // ListObjectsV2Func mocks the ListObjectsV2 method. + ListObjectsV2Func func(in1 string, in2 string, in3 bool, in4 <-chan struct{}) <-chan minio.ObjectInfo -// ListObjectsV2 mocks minio.Client.ListObjectsV2. -func (s *s3Mock) ListObjectsV2(name string, p string, r bool, d <-chan struct{}) <-chan minio.ObjectInfo { - // Add error if exists - if s.Err != nil { - s.Objects = append(s.Objects, minio.ObjectInfo{ - Err: s.Err, - }) - } + // MakeBucketFunc mocks the MakeBucket method. + MakeBucketFunc func(in1 string, in2 string) error - // Check if bucket exists - found := false - for _, b := range s.Buckets { - if b.Name == name { - found = true - break + // PutObjectFunc mocks the PutObject method. + PutObjectFunc func(in1 string, in2 string, in3 io.Reader, in4 int64, in5 minio.PutObjectOptions) (int64, error) + + // RemoveBucketFunc mocks the RemoveBucket method. + RemoveBucketFunc func(in1 string) error + + // 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") } - - objCh := make(chan minio.ObjectInfo, len(s.Objects)) - defer close(objCh) - - for _, obj := range s.Objects { - objCh <- obj + callInfo := struct { + In1 minio.DestinationInfo + In2 minio.SourceInfo + }{ + In1: in1, + In2: in2, } - - return objCh + lockS3MockCopyObject.Lock() + mock.calls.CopyObject = append(mock.calls.CopyObject, callInfo) + lockS3MockCopyObject.Unlock() + return mock.CopyObjectFunc(in1, in2) } -// MakeBucket mocks minio.Client.MakeBucket. -func (s *s3Mock) MakeBucket(string, string) error { - return s.Err +// CopyObjectCalls gets all the calls that were made to CopyObject. +// Check the length with: +// 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. -func (s *s3Mock) PutObject(string, string, io.Reader, int64, minio.PutObjectOptions) (int64, error) { - return 0, s.Err +// GetObject calls GetObjectFunc. +func (mock *S3Mock) GetObject(in1 string, in2 string, in3 minio.GetObjectOptions) (*minio.Object, error) { + 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. -func (s *s3Mock) RemoveBucket(string) error { - return s.Err +// GetObjectCalls gets all the calls that were made to GetObject. +// Check the length with: +// 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. -func (s *s3Mock) RemoveObject(string, string) error { - return s.Err +// ListBuckets calls ListBucketsFunc. +func (mock *S3Mock) ListBuckets() ([]minio.BucketInfo, error) { + 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 }