s3manager-web/internal/app/s3manager/mocks/s3.go

393 lines
12 KiB
Go
Raw Normal View History

2018-08-02 15:45:38 +02:00
// Code generated by moq; DO NOT EDIT.
2018-04-24 22:35:21 +02:00
// github.com/matryer/moq
2018-08-12 15:13:07 +02:00
package mocks
2017-05-08 23:07:07 +02:00
import (
"io"
2018-04-24 22:35:21 +02:00
"sync"
2020-06-14 00:03:42 +02:00
"github.com/minio/minio-go"
2018-04-24 22:35:21 +02:00
)
2017-05-08 23:07:07 +02:00
2018-04-24 22:35:21 +02:00
var (
lockS3MockGetObject sync.RWMutex
lockS3MockListBuckets sync.RWMutex
lockS3MockListObjectsV2 sync.RWMutex
lockS3MockMakeBucket sync.RWMutex
lockS3MockPutObject sync.RWMutex
lockS3MockRemoveBucket sync.RWMutex
lockS3MockRemoveObject sync.RWMutex
2017-05-08 23:07:07 +02:00
)
2018-04-24 22:35:21 +02:00
// S3Mock is a mock implementation of S3.
//
// func TestSomethingThatUsesS3(t *testing.T) {
//
// // make and configure a mocked S3
// mockedS3 := &S3Mock{
2018-08-02 15:45:38 +02:00
// GetObjectFunc: func(bucketName string, objectName string, opts minio.GetObjectOptions) (*minio.Object, error) {
2018-04-24 22:35:21 +02:00
// panic("TODO: mock out the GetObject method")
// },
// ListBucketsFunc: func() ([]minio.BucketInfo, error) {
// panic("TODO: mock out the ListBuckets method")
// },
2018-08-02 15:45:38 +02:00
// ListObjectsV2Func: func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo {
2018-04-24 22:35:21 +02:00
// panic("TODO: mock out the ListObjectsV2 method")
// },
2018-08-02 15:45:38 +02:00
// MakeBucketFunc: func(bucketName string, location string) error {
2018-04-24 22:35:21 +02:00
// panic("TODO: mock out the MakeBucket method")
// },
2018-08-02 15:45:38 +02:00
// PutObjectFunc: func(bucketName string, objectName string, reader io.Reader, objectSize int64, opts minio.PutObjectOptions) (int64, error) {
2018-04-24 22:35:21 +02:00
// panic("TODO: mock out the PutObject method")
// },
2018-08-02 15:45:38 +02:00
// RemoveBucketFunc: func(bucketName string) error {
2018-04-24 22:35:21 +02:00
// panic("TODO: mock out the RemoveBucket method")
// },
2018-08-02 15:45:38 +02:00
// RemoveObjectFunc: func(bucketName string, objectName string) error {
2018-04-24 22:35:21 +02:00
// panic("TODO: mock out the RemoveObject method")
// },
// }
//
// // TODO: use mockedS3 in code that requires S3
// // and then make assertions.
//
// }
type S3Mock struct {
// GetObjectFunc mocks the GetObject method.
2018-08-02 15:45:38 +02:00
GetObjectFunc func(bucketName string, objectName string, opts minio.GetObjectOptions) (*minio.Object, error)
2018-04-24 22:35:21 +02:00
// ListBucketsFunc mocks the ListBuckets method.
ListBucketsFunc func() ([]minio.BucketInfo, error)
// ListObjectsV2Func mocks the ListObjectsV2 method.
2018-08-02 15:45:38 +02:00
ListObjectsV2Func func(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo
2018-04-24 22:35:21 +02:00
// MakeBucketFunc mocks the MakeBucket method.
2018-08-02 15:45:38 +02:00
MakeBucketFunc func(bucketName string, location string) error
2018-04-24 22:35:21 +02:00
// PutObjectFunc mocks the PutObject method.
2018-08-02 15:45:38 +02:00
PutObjectFunc func(bucketName string, objectName string, reader io.Reader, objectSize int64, opts minio.PutObjectOptions) (int64, error)
2018-04-24 22:35:21 +02:00
// RemoveBucketFunc mocks the RemoveBucket method.
2018-08-02 15:45:38 +02:00
RemoveBucketFunc func(bucketName string) error
2018-04-24 22:35:21 +02:00
// RemoveObjectFunc mocks the RemoveObject method.
2018-08-02 15:45:38 +02:00
RemoveObjectFunc func(bucketName string, objectName string) error
2018-04-24 22:35:21 +02:00
// calls tracks calls to the methods.
calls struct {
// GetObject holds details about calls to the GetObject method.
GetObject []struct {
2018-08-02 15:45:38 +02:00
// BucketName is the bucketName argument value.
BucketName string
// ObjectName is the objectName argument value.
ObjectName string
// Opts is the opts argument value.
Opts minio.GetObjectOptions
2018-04-24 22:35:21 +02:00
}
// ListBuckets holds details about calls to the ListBuckets method.
ListBuckets []struct {
}
// ListObjectsV2 holds details about calls to the ListObjectsV2 method.
ListObjectsV2 []struct {
2018-08-02 15:45:38 +02:00
// BucketName is the bucketName argument value.
BucketName string
// ObjectPrefix is the objectPrefix argument value.
ObjectPrefix string
// Recursive is the recursive argument value.
Recursive bool
// DoneCh is the doneCh argument value.
DoneCh <-chan struct{}
2018-04-24 22:35:21 +02:00
}
// MakeBucket holds details about calls to the MakeBucket method.
MakeBucket []struct {
2018-08-02 15:45:38 +02:00
// BucketName is the bucketName argument value.
BucketName string
// Location is the location argument value.
Location string
2018-04-24 22:35:21 +02:00
}
// PutObject holds details about calls to the PutObject method.
PutObject []struct {
2018-08-02 15:45:38 +02:00
// BucketName is the bucketName argument value.
BucketName string
// ObjectName is the objectName argument value.
ObjectName string
// Reader is the reader argument value.
Reader io.Reader
// ObjectSize is the objectSize argument value.
ObjectSize int64
// Opts is the opts argument value.
Opts minio.PutObjectOptions
2018-04-24 22:35:21 +02:00
}
// RemoveBucket holds details about calls to the RemoveBucket method.
RemoveBucket []struct {
2018-08-02 15:45:38 +02:00
// BucketName is the bucketName argument value.
BucketName string
2018-04-24 22:35:21 +02:00
}
// RemoveObject holds details about calls to the RemoveObject method.
RemoveObject []struct {
2018-08-02 15:45:38 +02:00
// BucketName is the bucketName argument value.
BucketName string
// ObjectName is the objectName argument value.
ObjectName string
2018-04-24 22:35:21 +02:00
}
}
}
// GetObject calls GetObjectFunc.
2018-08-02 15:45:38 +02:00
func (mock *S3Mock) GetObject(bucketName string, objectName string, opts minio.GetObjectOptions) (*minio.Object, error) {
2018-04-24 22:35:21 +02:00
if mock.GetObjectFunc == nil {
2018-08-02 15:45:38 +02:00
panic("S3Mock.GetObjectFunc: method is nil but S3.GetObject was just called")
2018-04-24 22:35:21 +02:00
}
callInfo := struct {
2018-08-02 15:45:38 +02:00
BucketName string
ObjectName string
Opts minio.GetObjectOptions
2018-04-24 22:35:21 +02:00
}{
2018-08-02 15:45:38 +02:00
BucketName: bucketName,
ObjectName: objectName,
Opts: opts,
2018-04-24 22:35:21 +02:00
}
lockS3MockGetObject.Lock()
mock.calls.GetObject = append(mock.calls.GetObject, callInfo)
lockS3MockGetObject.Unlock()
2018-08-02 15:45:38 +02:00
return mock.GetObjectFunc(bucketName, objectName, opts)
2017-05-08 23:07:07 +02:00
}
2018-04-24 22:35:21 +02:00
// GetObjectCalls gets all the calls that were made to GetObject.
// Check the length with:
// len(mockedS3.GetObjectCalls())
func (mock *S3Mock) GetObjectCalls() []struct {
2018-08-02 15:45:38 +02:00
BucketName string
ObjectName string
Opts minio.GetObjectOptions
2018-04-24 22:35:21 +02:00
} {
var calls []struct {
2018-08-02 15:45:38 +02:00
BucketName string
ObjectName string
Opts minio.GetObjectOptions
2017-05-08 23:07:07 +02:00
}
2018-04-24 22:35:21 +02:00
lockS3MockGetObject.RLock()
calls = mock.calls.GetObject
lockS3MockGetObject.RUnlock()
return calls
}
2017-05-08 23:07:07 +02:00
2018-04-24 22:35:21 +02:00
// ListBuckets calls ListBucketsFunc.
func (mock *S3Mock) ListBuckets() ([]minio.BucketInfo, error) {
if mock.ListBucketsFunc == nil {
2018-08-02 15:45:38 +02:00
panic("S3Mock.ListBucketsFunc: method is nil but S3.ListBuckets was just called")
2018-04-24 22:35:21 +02:00
}
callInfo := struct {
}{}
lockS3MockListBuckets.Lock()
mock.calls.ListBuckets = append(mock.calls.ListBuckets, callInfo)
lockS3MockListBuckets.Unlock()
return mock.ListBucketsFunc()
2017-05-08 23:07:07 +02:00
}
2018-04-24 22:35:21 +02:00
// 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
2017-05-08 23:07:07 +02:00
}
2018-04-24 22:35:21 +02:00
// ListObjectsV2 calls ListObjectsV2Func.
2018-08-02 15:45:38 +02:00
func (mock *S3Mock) ListObjectsV2(bucketName string, objectPrefix string, recursive bool, doneCh <-chan struct{}) <-chan minio.ObjectInfo {
2018-04-24 22:35:21 +02:00
if mock.ListObjectsV2Func == nil {
2018-08-02 15:45:38 +02:00
panic("S3Mock.ListObjectsV2Func: method is nil but S3.ListObjectsV2 was just called")
2018-04-24 22:35:21 +02:00
}
callInfo := struct {
2018-08-02 15:45:38 +02:00
BucketName string
ObjectPrefix string
Recursive bool
DoneCh <-chan struct{}
2018-04-24 22:35:21 +02:00
}{
2018-08-02 15:45:38 +02:00
BucketName: bucketName,
ObjectPrefix: objectPrefix,
Recursive: recursive,
DoneCh: doneCh,
2017-05-08 23:07:07 +02:00
}
2018-04-24 22:35:21 +02:00
lockS3MockListObjectsV2.Lock()
mock.calls.ListObjectsV2 = append(mock.calls.ListObjectsV2, callInfo)
lockS3MockListObjectsV2.Unlock()
2018-08-02 15:45:38 +02:00
return mock.ListObjectsV2Func(bucketName, objectPrefix, recursive, doneCh)
2018-04-24 22:35:21 +02:00
}
2017-05-08 23:07:07 +02:00
2018-04-24 22:35:21 +02:00
// ListObjectsV2Calls gets all the calls that were made to ListObjectsV2.
// Check the length with:
// len(mockedS3.ListObjectsV2Calls())
func (mock *S3Mock) ListObjectsV2Calls() []struct {
2018-08-02 15:45:38 +02:00
BucketName string
ObjectPrefix string
Recursive bool
DoneCh <-chan struct{}
2018-04-24 22:35:21 +02:00
} {
var calls []struct {
2018-08-02 15:45:38 +02:00
BucketName string
ObjectPrefix string
Recursive bool
DoneCh <-chan struct{}
2017-05-08 23:07:07 +02:00
}
2018-04-24 22:35:21 +02:00
lockS3MockListObjectsV2.RLock()
calls = mock.calls.ListObjectsV2
lockS3MockListObjectsV2.RUnlock()
return calls
}
2017-05-08 23:07:07 +02:00
2018-04-24 22:35:21 +02:00
// MakeBucket calls MakeBucketFunc.
2018-08-02 15:45:38 +02:00
func (mock *S3Mock) MakeBucket(bucketName string, location string) error {
2018-04-24 22:35:21 +02:00
if mock.MakeBucketFunc == nil {
2018-08-02 15:45:38 +02:00
panic("S3Mock.MakeBucketFunc: method is nil but S3.MakeBucket was just called")
2018-04-24 22:35:21 +02:00
}
callInfo := struct {
2018-08-02 15:45:38 +02:00
BucketName string
Location string
2018-04-24 22:35:21 +02:00
}{
2018-08-02 15:45:38 +02:00
BucketName: bucketName,
Location: location,
2017-05-08 23:07:07 +02:00
}
2018-04-24 22:35:21 +02:00
lockS3MockMakeBucket.Lock()
mock.calls.MakeBucket = append(mock.calls.MakeBucket, callInfo)
lockS3MockMakeBucket.Unlock()
2018-08-02 15:45:38 +02:00
return mock.MakeBucketFunc(bucketName, location)
2018-04-24 22:35:21 +02:00
}
2017-05-08 23:07:07 +02:00
2018-04-24 22:35:21 +02:00
// MakeBucketCalls gets all the calls that were made to MakeBucket.
// Check the length with:
// len(mockedS3.MakeBucketCalls())
func (mock *S3Mock) MakeBucketCalls() []struct {
2018-08-02 15:45:38 +02:00
BucketName string
Location string
2018-04-24 22:35:21 +02:00
} {
var calls []struct {
2018-08-02 15:45:38 +02:00
BucketName string
Location string
2018-04-24 22:35:21 +02:00
}
lockS3MockMakeBucket.RLock()
calls = mock.calls.MakeBucket
lockS3MockMakeBucket.RUnlock()
return calls
}
2017-05-08 23:07:07 +02:00
2018-04-24 22:35:21 +02:00
// PutObject calls PutObjectFunc.
2018-08-02 15:45:38 +02:00
func (mock *S3Mock) PutObject(bucketName string, objectName string, reader io.Reader, objectSize int64, opts minio.PutObjectOptions) (int64, error) {
2018-04-24 22:35:21 +02:00
if mock.PutObjectFunc == nil {
2018-08-02 15:45:38 +02:00
panic("S3Mock.PutObjectFunc: method is nil but S3.PutObject was just called")
2017-05-08 23:07:07 +02:00
}
2018-04-24 22:35:21 +02:00
callInfo := struct {
2018-08-02 15:45:38 +02:00
BucketName string
ObjectName string
Reader io.Reader
ObjectSize int64
Opts minio.PutObjectOptions
2018-04-24 22:35:21 +02:00
}{
2018-08-02 15:45:38 +02:00
BucketName: bucketName,
ObjectName: objectName,
Reader: reader,
ObjectSize: objectSize,
Opts: opts,
2018-04-24 22:35:21 +02:00
}
lockS3MockPutObject.Lock()
mock.calls.PutObject = append(mock.calls.PutObject, callInfo)
lockS3MockPutObject.Unlock()
2018-08-02 15:45:38 +02:00
return mock.PutObjectFunc(bucketName, objectName, reader, objectSize, opts)
2018-04-24 22:35:21 +02:00
}
2017-05-08 23:07:07 +02:00
2018-04-24 22:35:21 +02:00
// PutObjectCalls gets all the calls that were made to PutObject.
// Check the length with:
// len(mockedS3.PutObjectCalls())
func (mock *S3Mock) PutObjectCalls() []struct {
2018-08-02 15:45:38 +02:00
BucketName string
ObjectName string
Reader io.Reader
ObjectSize int64
Opts minio.PutObjectOptions
2018-04-24 22:35:21 +02:00
} {
var calls []struct {
2018-08-02 15:45:38 +02:00
BucketName string
ObjectName string
Reader io.Reader
ObjectSize int64
Opts minio.PutObjectOptions
2018-04-24 22:35:21 +02:00
}
lockS3MockPutObject.RLock()
calls = mock.calls.PutObject
lockS3MockPutObject.RUnlock()
return calls
2017-05-08 23:07:07 +02:00
}
2018-04-24 22:35:21 +02:00
// RemoveBucket calls RemoveBucketFunc.
2018-08-02 15:45:38 +02:00
func (mock *S3Mock) RemoveBucket(bucketName string) error {
2018-04-24 22:35:21 +02:00
if mock.RemoveBucketFunc == nil {
2018-08-02 15:45:38 +02:00
panic("S3Mock.RemoveBucketFunc: method is nil but S3.RemoveBucket was just called")
2018-04-24 22:35:21 +02:00
}
callInfo := struct {
2018-08-02 15:45:38 +02:00
BucketName string
2018-04-24 22:35:21 +02:00
}{
2018-08-02 15:45:38 +02:00
BucketName: bucketName,
2018-04-24 22:35:21 +02:00
}
lockS3MockRemoveBucket.Lock()
mock.calls.RemoveBucket = append(mock.calls.RemoveBucket, callInfo)
lockS3MockRemoveBucket.Unlock()
2018-08-02 15:45:38 +02:00
return mock.RemoveBucketFunc(bucketName)
2017-05-08 23:07:07 +02:00
}
2018-04-24 22:35:21 +02:00
// RemoveBucketCalls gets all the calls that were made to RemoveBucket.
// Check the length with:
// len(mockedS3.RemoveBucketCalls())
func (mock *S3Mock) RemoveBucketCalls() []struct {
2018-08-02 15:45:38 +02:00
BucketName string
2018-04-24 22:35:21 +02:00
} {
var calls []struct {
2018-08-02 15:45:38 +02:00
BucketName string
2018-04-24 22:35:21 +02:00
}
lockS3MockRemoveBucket.RLock()
calls = mock.calls.RemoveBucket
lockS3MockRemoveBucket.RUnlock()
return calls
2017-05-08 23:07:07 +02:00
}
2018-04-24 22:35:21 +02:00
// RemoveObject calls RemoveObjectFunc.
2018-08-02 15:45:38 +02:00
func (mock *S3Mock) RemoveObject(bucketName string, objectName string) error {
2018-04-24 22:35:21 +02:00
if mock.RemoveObjectFunc == nil {
2018-08-02 15:45:38 +02:00
panic("S3Mock.RemoveObjectFunc: method is nil but S3.RemoveObject was just called")
2018-04-24 22:35:21 +02:00
}
callInfo := struct {
2018-08-02 15:45:38 +02:00
BucketName string
ObjectName string
2018-04-24 22:35:21 +02:00
}{
2018-08-02 15:45:38 +02:00
BucketName: bucketName,
ObjectName: objectName,
2018-04-24 22:35:21 +02:00
}
lockS3MockRemoveObject.Lock()
mock.calls.RemoveObject = append(mock.calls.RemoveObject, callInfo)
lockS3MockRemoveObject.Unlock()
2018-08-02 15:45:38 +02:00
return mock.RemoveObjectFunc(bucketName, objectName)
2017-05-08 23:07:07 +02:00
}
2018-04-24 22:35:21 +02:00
// RemoveObjectCalls gets all the calls that were made to RemoveObject.
// Check the length with:
// len(mockedS3.RemoveObjectCalls())
func (mock *S3Mock) RemoveObjectCalls() []struct {
2018-08-02 15:45:38 +02:00
BucketName string
ObjectName string
2018-04-24 22:35:21 +02:00
} {
var calls []struct {
2018-08-02 15:45:38 +02:00
BucketName string
ObjectName string
2018-04-24 22:35:21 +02:00
}
lockS3MockRemoveObject.RLock()
calls = mock.calls.RemoveObject
lockS3MockRemoveObject.RUnlock()
return calls
2017-05-08 23:07:07 +02:00
}