diff --git a/backend/backend.go b/backend/backend.go index 5270d5d..342d982 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -10,6 +10,7 @@ import ( ) //go:generate moq -out backend_moq_test.go . Backend +//go:generate moq -out ../s3api/controllers/backend_moq_test.go . Backend type Backend interface { fmt.Stringer GetIAMConfig() ([]byte, error) diff --git a/backend/backend_test.go b/backend/backend_test.go index 0b5540f..04d5164 100644 --- a/backend/backend_test.go +++ b/backend/backend_test.go @@ -2,11 +2,12 @@ package backend import ( "context" + "testing" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/aws-sdk-go-v2/service/s3/types" "github.com/versity/scoutgw/s3err" - "testing" ) func TestBackend_ListBuckets(t *testing.T) { diff --git a/s3api/controllers/backend_moq_test.go b/s3api/controllers/backend_moq_test.go new file mode 100644 index 0000000..7268584 --- /dev/null +++ b/s3api/controllers/backend_moq_test.go @@ -0,0 +1,1796 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package controllers + +import ( + "io" + "sync" + + "github.com/aws/aws-sdk-go-v2/service/s3" + "github.com/aws/aws-sdk-go-v2/service/s3/types" + "github.com/versity/scoutgw/backend" +) + +// Ensure, that BackendMock does implement Backend. +// If this is not the case, regenerate this file with moq. +var _ backend.Backend = &BackendMock{} + +// BackendMock is a mock implementation of Backend. +// +// func TestSomethingThatUsesBackend(t *testing.T) { +// +// // make and configure a mocked Backend +// mockedBackend := &BackendMock{ +// AbortMultipartUploadFunc: func(abortMultipartUploadInput *s3.AbortMultipartUploadInput) error { +// panic("mock out the AbortMultipartUpload method") +// }, +// CompleteMultipartUploadFunc: func(bucket string, object string, uploadID string, parts []types.Part) (*s3.CompleteMultipartUploadOutput, error) { +// panic("mock out the CompleteMultipartUpload method") +// }, +// CopyObjectFunc: func(srcBucket string, srcObject string, DstBucket string, dstObject string) (*s3.CopyObjectOutput, error) { +// panic("mock out the CopyObject method") +// }, +// CopyPartFunc: func(srcBucket string, srcObject string, DstBucket string, uploadID string, rangeHeader string, part int) (*types.CopyPartResult, error) { +// panic("mock out the CopyPart method") +// }, +// CreateMultipartUploadFunc: func(createMultipartUploadInput *s3.CreateMultipartUploadInput) (*s3.CreateMultipartUploadOutput, error) { +// panic("mock out the CreateMultipartUpload method") +// }, +// DeleteBucketFunc: func(bucket string) error { +// panic("mock out the DeleteBucket method") +// }, +// DeleteObjectFunc: func(bucket string, object string) error { +// panic("mock out the DeleteObject method") +// }, +// DeleteObjectsFunc: func(bucket string, objects *s3.DeleteObjectsInput) error { +// panic("mock out the DeleteObjects method") +// }, +// GetBucketAclFunc: func(bucket string) (*s3.GetBucketAclOutput, error) { +// panic("mock out the GetBucketAcl method") +// }, +// GetIAMConfigFunc: func() ([]byte, error) { +// panic("mock out the GetIAMConfig method") +// }, +// GetObjectFunc: func(bucket string, object string, startOffset int64, length int64, writer io.Writer, etag string) (*s3.GetObjectOutput, error) { +// panic("mock out the GetObject method") +// }, +// GetObjectAclFunc: func(bucket string, object string) (*s3.GetObjectAclOutput, error) { +// panic("mock out the GetObjectAcl method") +// }, +// GetObjectAttributesFunc: func(bucket string, object string, attributes []string) (*s3.GetObjectAttributesOutput, error) { +// panic("mock out the GetObjectAttributes method") +// }, +// GetTagsFunc: func(bucket string, object string) (map[string]string, error) { +// panic("mock out the GetTags method") +// }, +// HeadBucketFunc: func(bucket string) (*s3.HeadBucketOutput, error) { +// panic("mock out the HeadBucket method") +// }, +// HeadObjectFunc: func(bucket string, object string, etag string) (*s3.HeadObjectOutput, error) { +// panic("mock out the HeadObject method") +// }, +// IsTaggingSupportedFunc: func() bool { +// panic("mock out the IsTaggingSupported method") +// }, +// ListBucketsFunc: func() (*s3.ListBucketsOutput, error) { +// panic("mock out the ListBuckets method") +// }, +// ListMultipartUploadsFunc: func(output *s3.ListMultipartUploadsInput) (*s3.ListMultipartUploadsOutput, error) { +// panic("mock out the ListMultipartUploads method") +// }, +// ListObjectPartsFunc: func(bucket string, object string, uploadID string, partNumberMarker int, maxParts int) (*s3.ListPartsOutput, error) { +// panic("mock out the ListObjectParts method") +// }, +// ListObjectsFunc: func(bucket string, prefix string, marker string, delim string, maxkeys int) (*s3.ListBucketsOutput, error) { +// panic("mock out the ListObjects method") +// }, +// ListObjectsV2Func: func(bucket string, prefix string, marker string, delim string, maxkeys int) (*s3.ListBucketsOutput, error) { +// panic("mock out the ListObjectsV2 method") +// }, +// PutBucketFunc: func(bucket string) error { +// panic("mock out the PutBucket method") +// }, +// PutBucketAclFunc: func(putBucketAclInput *s3.PutBucketAclInput) error { +// panic("mock out the PutBucketAcl method") +// }, +// PutObjectFunc: func(bucket string, object string, r io.Reader) (string, error) { +// panic("mock out the PutObject method") +// }, +// PutObjectAclFunc: func(putObjectAclInput *s3.PutObjectAclInput) error { +// panic("mock out the PutObjectAcl method") +// }, +// PutObjectPartFunc: func(bucket string, object string, uploadID string, part int, r io.Reader) (string, error) { +// panic("mock out the PutObjectPart method") +// }, +// RemoveTagsFunc: func(bucket string, object string) error { +// panic("mock out the RemoveTags method") +// }, +// RestoreObjectFunc: func(bucket string, object string, restoreRequest *s3.RestoreObjectInput) error { +// panic("mock out the RestoreObject method") +// }, +// SetTagsFunc: func(bucket string, object string, tags map[string]string) error { +// panic("mock out the SetTags method") +// }, +// ShutdownFunc: func() { +// panic("mock out the Shutdown method") +// }, +// StringFunc: func() string { +// panic("mock out the String method") +// }, +// UploadPartFunc: func(bucket string, object string, uploadId string, Body io.ReadSeeker) (*s3.UploadPartOutput, error) { +// panic("mock out the UploadPart method") +// }, +// UploadPartCopyFunc: func(uploadPartCopyInput *s3.UploadPartCopyInput) (*s3.UploadPartCopyOutput, error) { +// panic("mock out the UploadPartCopy method") +// }, +// } +// +// // use mockedBackend in code that requires Backend +// // and then make assertions. +// +// } +type BackendMock struct { + // AbortMultipartUploadFunc mocks the AbortMultipartUpload method. + AbortMultipartUploadFunc func(abortMultipartUploadInput *s3.AbortMultipartUploadInput) error + + // CompleteMultipartUploadFunc mocks the CompleteMultipartUpload method. + CompleteMultipartUploadFunc func(bucket string, object string, uploadID string, parts []types.Part) (*s3.CompleteMultipartUploadOutput, error) + + // CopyObjectFunc mocks the CopyObject method. + CopyObjectFunc func(srcBucket string, srcObject string, DstBucket string, dstObject string) (*s3.CopyObjectOutput, error) + + // CopyPartFunc mocks the CopyPart method. + CopyPartFunc func(srcBucket string, srcObject string, DstBucket string, uploadID string, rangeHeader string, part int) (*types.CopyPartResult, error) + + // CreateMultipartUploadFunc mocks the CreateMultipartUpload method. + CreateMultipartUploadFunc func(createMultipartUploadInput *s3.CreateMultipartUploadInput) (*s3.CreateMultipartUploadOutput, error) + + // DeleteBucketFunc mocks the DeleteBucket method. + DeleteBucketFunc func(bucket string) error + + // DeleteObjectFunc mocks the DeleteObject method. + DeleteObjectFunc func(bucket string, object string) error + + // DeleteObjectsFunc mocks the DeleteObjects method. + DeleteObjectsFunc func(bucket string, objects *s3.DeleteObjectsInput) error + + // GetBucketAclFunc mocks the GetBucketAcl method. + GetBucketAclFunc func(bucket string) (*s3.GetBucketAclOutput, error) + + // GetIAMConfigFunc mocks the GetIAMConfig method. + GetIAMConfigFunc func() ([]byte, error) + + // GetObjectFunc mocks the GetObject method. + GetObjectFunc func(bucket string, object string, startOffset int64, length int64, writer io.Writer, etag string) (*s3.GetObjectOutput, error) + + // GetObjectAclFunc mocks the GetObjectAcl method. + GetObjectAclFunc func(bucket string, object string) (*s3.GetObjectAclOutput, error) + + // GetObjectAttributesFunc mocks the GetObjectAttributes method. + GetObjectAttributesFunc func(bucket string, object string, attributes []string) (*s3.GetObjectAttributesOutput, error) + + // GetTagsFunc mocks the GetTags method. + GetTagsFunc func(bucket string, object string) (map[string]string, error) + + // HeadBucketFunc mocks the HeadBucket method. + HeadBucketFunc func(bucket string) (*s3.HeadBucketOutput, error) + + // HeadObjectFunc mocks the HeadObject method. + HeadObjectFunc func(bucket string, object string, etag string) (*s3.HeadObjectOutput, error) + + // IsTaggingSupportedFunc mocks the IsTaggingSupported method. + IsTaggingSupportedFunc func() bool + + // ListBucketsFunc mocks the ListBuckets method. + ListBucketsFunc func() (*s3.ListBucketsOutput, error) + + // ListMultipartUploadsFunc mocks the ListMultipartUploads method. + ListMultipartUploadsFunc func(output *s3.ListMultipartUploadsInput) (*s3.ListMultipartUploadsOutput, error) + + // ListObjectPartsFunc mocks the ListObjectParts method. + ListObjectPartsFunc func(bucket string, object string, uploadID string, partNumberMarker int, maxParts int) (*s3.ListPartsOutput, error) + + // ListObjectsFunc mocks the ListObjects method. + ListObjectsFunc func(bucket string, prefix string, marker string, delim string, maxkeys int) (*s3.ListBucketsOutput, error) + + // ListObjectsV2Func mocks the ListObjectsV2 method. + ListObjectsV2Func func(bucket string, prefix string, marker string, delim string, maxkeys int) (*s3.ListBucketsOutput, error) + + // PutBucketFunc mocks the PutBucket method. + PutBucketFunc func(bucket string) error + + // PutBucketAclFunc mocks the PutBucketAcl method. + PutBucketAclFunc func(putBucketAclInput *s3.PutBucketAclInput) error + + // PutObjectFunc mocks the PutObject method. + PutObjectFunc func(bucket string, object string, r io.Reader) (string, error) + + // PutObjectAclFunc mocks the PutObjectAcl method. + PutObjectAclFunc func(putObjectAclInput *s3.PutObjectAclInput) error + + // PutObjectPartFunc mocks the PutObjectPart method. + PutObjectPartFunc func(bucket string, object string, uploadID string, part int, r io.Reader) (string, error) + + // RemoveTagsFunc mocks the RemoveTags method. + RemoveTagsFunc func(bucket string, object string) error + + // RestoreObjectFunc mocks the RestoreObject method. + RestoreObjectFunc func(bucket string, object string, restoreRequest *s3.RestoreObjectInput) error + + // SetTagsFunc mocks the SetTags method. + SetTagsFunc func(bucket string, object string, tags map[string]string) error + + // ShutdownFunc mocks the Shutdown method. + ShutdownFunc func() + + // StringFunc mocks the String method. + StringFunc func() string + + // UploadPartFunc mocks the UploadPart method. + UploadPartFunc func(bucket string, object string, uploadId string, Body io.ReadSeeker) (*s3.UploadPartOutput, error) + + // UploadPartCopyFunc mocks the UploadPartCopy method. + UploadPartCopyFunc func(uploadPartCopyInput *s3.UploadPartCopyInput) (*s3.UploadPartCopyOutput, error) + + // calls tracks calls to the methods. + calls struct { + // AbortMultipartUpload holds details about calls to the AbortMultipartUpload method. + AbortMultipartUpload []struct { + // AbortMultipartUploadInput is the abortMultipartUploadInput argument value. + AbortMultipartUploadInput *s3.AbortMultipartUploadInput + } + // CompleteMultipartUpload holds details about calls to the CompleteMultipartUpload method. + CompleteMultipartUpload []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + // UploadID is the uploadID argument value. + UploadID string + // Parts is the parts argument value. + Parts []types.Part + } + // CopyObject holds details about calls to the CopyObject method. + CopyObject []struct { + // SrcBucket is the srcBucket argument value. + SrcBucket string + // SrcObject is the srcObject argument value. + SrcObject string + // DstBucket is the DstBucket argument value. + DstBucket string + // DstObject is the dstObject argument value. + DstObject string + } + // CopyPart holds details about calls to the CopyPart method. + CopyPart []struct { + // SrcBucket is the srcBucket argument value. + SrcBucket string + // SrcObject is the srcObject argument value. + SrcObject string + // DstBucket is the DstBucket argument value. + DstBucket string + // UploadID is the uploadID argument value. + UploadID string + // RangeHeader is the rangeHeader argument value. + RangeHeader string + // Part is the part argument value. + Part int + } + // CreateMultipartUpload holds details about calls to the CreateMultipartUpload method. + CreateMultipartUpload []struct { + // CreateMultipartUploadInput is the createMultipartUploadInput argument value. + CreateMultipartUploadInput *s3.CreateMultipartUploadInput + } + // DeleteBucket holds details about calls to the DeleteBucket method. + DeleteBucket []struct { + // Bucket is the bucket argument value. + Bucket string + } + // DeleteObject holds details about calls to the DeleteObject method. + DeleteObject []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + } + // DeleteObjects holds details about calls to the DeleteObjects method. + DeleteObjects []struct { + // Bucket is the bucket argument value. + Bucket string + // Objects is the objects argument value. + Objects *s3.DeleteObjectsInput + } + // GetBucketAcl holds details about calls to the GetBucketAcl method. + GetBucketAcl []struct { + // Bucket is the bucket argument value. + Bucket string + } + // GetIAMConfig holds details about calls to the GetIAMConfig method. + GetIAMConfig []struct { + } + // GetObject holds details about calls to the GetObject method. + GetObject []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + // StartOffset is the startOffset argument value. + StartOffset int64 + // Length is the length argument value. + Length int64 + // Writer is the writer argument value. + Writer io.Writer + // Etag is the etag argument value. + Etag string + } + // GetObjectAcl holds details about calls to the GetObjectAcl method. + GetObjectAcl []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + } + // GetObjectAttributes holds details about calls to the GetObjectAttributes method. + GetObjectAttributes []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + // Attributes is the attributes argument value. + Attributes []string + } + // GetTags holds details about calls to the GetTags method. + GetTags []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + } + // HeadBucket holds details about calls to the HeadBucket method. + HeadBucket []struct { + // Bucket is the bucket argument value. + Bucket string + } + // HeadObject holds details about calls to the HeadObject method. + HeadObject []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + // Etag is the etag argument value. + Etag string + } + // IsTaggingSupported holds details about calls to the IsTaggingSupported method. + IsTaggingSupported []struct { + } + // ListBuckets holds details about calls to the ListBuckets method. + ListBuckets []struct { + } + // ListMultipartUploads holds details about calls to the ListMultipartUploads method. + ListMultipartUploads []struct { + // Output is the output argument value. + Output *s3.ListMultipartUploadsInput + } + // ListObjectParts holds details about calls to the ListObjectParts method. + ListObjectParts []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + // UploadID is the uploadID argument value. + UploadID string + // PartNumberMarker is the partNumberMarker argument value. + PartNumberMarker int + // MaxParts is the maxParts argument value. + MaxParts int + } + // ListObjects holds details about calls to the ListObjects method. + ListObjects []struct { + // Bucket is the bucket argument value. + Bucket string + // Prefix is the prefix argument value. + Prefix string + // Marker is the marker argument value. + Marker string + // Delim is the delim argument value. + Delim string + // Maxkeys is the maxkeys argument value. + Maxkeys int + } + // ListObjectsV2 holds details about calls to the ListObjectsV2 method. + ListObjectsV2 []struct { + // Bucket is the bucket argument value. + Bucket string + // Prefix is the prefix argument value. + Prefix string + // Marker is the marker argument value. + Marker string + // Delim is the delim argument value. + Delim string + // Maxkeys is the maxkeys argument value. + Maxkeys int + } + // PutBucket holds details about calls to the PutBucket method. + PutBucket []struct { + // Bucket is the bucket argument value. + Bucket string + } + // PutBucketAcl holds details about calls to the PutBucketAcl method. + PutBucketAcl []struct { + // PutBucketAclInput is the putBucketAclInput argument value. + PutBucketAclInput *s3.PutBucketAclInput + } + // PutObject holds details about calls to the PutObject method. + PutObject []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + // R is the r argument value. + R io.Reader + } + // PutObjectAcl holds details about calls to the PutObjectAcl method. + PutObjectAcl []struct { + // PutObjectAclInput is the putObjectAclInput argument value. + PutObjectAclInput *s3.PutObjectAclInput + } + // PutObjectPart holds details about calls to the PutObjectPart method. + PutObjectPart []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + // UploadID is the uploadID argument value. + UploadID string + // Part is the part argument value. + Part int + // R is the r argument value. + R io.Reader + } + // RemoveTags holds details about calls to the RemoveTags method. + RemoveTags []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + } + // RestoreObject holds details about calls to the RestoreObject method. + RestoreObject []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + // RestoreRequest is the restoreRequest argument value. + RestoreRequest *s3.RestoreObjectInput + } + // SetTags holds details about calls to the SetTags method. + SetTags []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + // Tags is the tags argument value. + Tags map[string]string + } + // Shutdown holds details about calls to the Shutdown method. + Shutdown []struct { + } + // String holds details about calls to the String method. + String []struct { + } + // UploadPart holds details about calls to the UploadPart method. + UploadPart []struct { + // Bucket is the bucket argument value. + Bucket string + // Object is the object argument value. + Object string + // UploadId is the uploadId argument value. + UploadId string + // Body is the Body argument value. + Body io.ReadSeeker + } + // UploadPartCopy holds details about calls to the UploadPartCopy method. + UploadPartCopy []struct { + // UploadPartCopyInput is the uploadPartCopyInput argument value. + UploadPartCopyInput *s3.UploadPartCopyInput + } + } + lockAbortMultipartUpload sync.RWMutex + lockCompleteMultipartUpload sync.RWMutex + lockCopyObject sync.RWMutex + lockCopyPart sync.RWMutex + lockCreateMultipartUpload sync.RWMutex + lockDeleteBucket sync.RWMutex + lockDeleteObject sync.RWMutex + lockDeleteObjects sync.RWMutex + lockGetBucketAcl sync.RWMutex + lockGetIAMConfig sync.RWMutex + lockGetObject sync.RWMutex + lockGetObjectAcl sync.RWMutex + lockGetObjectAttributes sync.RWMutex + lockGetTags sync.RWMutex + lockHeadBucket sync.RWMutex + lockHeadObject sync.RWMutex + lockIsTaggingSupported sync.RWMutex + lockListBuckets sync.RWMutex + lockListMultipartUploads sync.RWMutex + lockListObjectParts sync.RWMutex + lockListObjects sync.RWMutex + lockListObjectsV2 sync.RWMutex + lockPutBucket sync.RWMutex + lockPutBucketAcl sync.RWMutex + lockPutObject sync.RWMutex + lockPutObjectAcl sync.RWMutex + lockPutObjectPart sync.RWMutex + lockRemoveTags sync.RWMutex + lockRestoreObject sync.RWMutex + lockSetTags sync.RWMutex + lockShutdown sync.RWMutex + lockString sync.RWMutex + lockUploadPart sync.RWMutex + lockUploadPartCopy sync.RWMutex +} + +// AbortMultipartUpload calls AbortMultipartUploadFunc. +func (mock *BackendMock) AbortMultipartUpload(abortMultipartUploadInput *s3.AbortMultipartUploadInput) error { + if mock.AbortMultipartUploadFunc == nil { + panic("BackendMock.AbortMultipartUploadFunc: method is nil but Backend.AbortMultipartUpload was just called") + } + callInfo := struct { + AbortMultipartUploadInput *s3.AbortMultipartUploadInput + }{ + AbortMultipartUploadInput: abortMultipartUploadInput, + } + mock.lockAbortMultipartUpload.Lock() + mock.calls.AbortMultipartUpload = append(mock.calls.AbortMultipartUpload, callInfo) + mock.lockAbortMultipartUpload.Unlock() + return mock.AbortMultipartUploadFunc(abortMultipartUploadInput) +} + +// AbortMultipartUploadCalls gets all the calls that were made to AbortMultipartUpload. +// Check the length with: +// +// len(mockedBackend.AbortMultipartUploadCalls()) +func (mock *BackendMock) AbortMultipartUploadCalls() []struct { + AbortMultipartUploadInput *s3.AbortMultipartUploadInput +} { + var calls []struct { + AbortMultipartUploadInput *s3.AbortMultipartUploadInput + } + mock.lockAbortMultipartUpload.RLock() + calls = mock.calls.AbortMultipartUpload + mock.lockAbortMultipartUpload.RUnlock() + return calls +} + +// CompleteMultipartUpload calls CompleteMultipartUploadFunc. +func (mock *BackendMock) CompleteMultipartUpload(bucket string, object string, uploadID string, parts []types.Part) (*s3.CompleteMultipartUploadOutput, error) { + if mock.CompleteMultipartUploadFunc == nil { + panic("BackendMock.CompleteMultipartUploadFunc: method is nil but Backend.CompleteMultipartUpload was just called") + } + callInfo := struct { + Bucket string + Object string + UploadID string + Parts []types.Part + }{ + Bucket: bucket, + Object: object, + UploadID: uploadID, + Parts: parts, + } + mock.lockCompleteMultipartUpload.Lock() + mock.calls.CompleteMultipartUpload = append(mock.calls.CompleteMultipartUpload, callInfo) + mock.lockCompleteMultipartUpload.Unlock() + return mock.CompleteMultipartUploadFunc(bucket, object, uploadID, parts) +} + +// CompleteMultipartUploadCalls gets all the calls that were made to CompleteMultipartUpload. +// Check the length with: +// +// len(mockedBackend.CompleteMultipartUploadCalls()) +func (mock *BackendMock) CompleteMultipartUploadCalls() []struct { + Bucket string + Object string + UploadID string + Parts []types.Part +} { + var calls []struct { + Bucket string + Object string + UploadID string + Parts []types.Part + } + mock.lockCompleteMultipartUpload.RLock() + calls = mock.calls.CompleteMultipartUpload + mock.lockCompleteMultipartUpload.RUnlock() + return calls +} + +// CopyObject calls CopyObjectFunc. +func (mock *BackendMock) CopyObject(srcBucket string, srcObject string, DstBucket string, dstObject string) (*s3.CopyObjectOutput, error) { + if mock.CopyObjectFunc == nil { + panic("BackendMock.CopyObjectFunc: method is nil but Backend.CopyObject was just called") + } + callInfo := struct { + SrcBucket string + SrcObject string + DstBucket string + DstObject string + }{ + SrcBucket: srcBucket, + SrcObject: srcObject, + DstBucket: DstBucket, + DstObject: dstObject, + } + mock.lockCopyObject.Lock() + mock.calls.CopyObject = append(mock.calls.CopyObject, callInfo) + mock.lockCopyObject.Unlock() + return mock.CopyObjectFunc(srcBucket, srcObject, DstBucket, dstObject) +} + +// CopyObjectCalls gets all the calls that were made to CopyObject. +// Check the length with: +// +// len(mockedBackend.CopyObjectCalls()) +func (mock *BackendMock) CopyObjectCalls() []struct { + SrcBucket string + SrcObject string + DstBucket string + DstObject string +} { + var calls []struct { + SrcBucket string + SrcObject string + DstBucket string + DstObject string + } + mock.lockCopyObject.RLock() + calls = mock.calls.CopyObject + mock.lockCopyObject.RUnlock() + return calls +} + +// CopyPart calls CopyPartFunc. +func (mock *BackendMock) CopyPart(srcBucket string, srcObject string, DstBucket string, uploadID string, rangeHeader string, part int) (*types.CopyPartResult, error) { + if mock.CopyPartFunc == nil { + panic("BackendMock.CopyPartFunc: method is nil but Backend.CopyPart was just called") + } + callInfo := struct { + SrcBucket string + SrcObject string + DstBucket string + UploadID string + RangeHeader string + Part int + }{ + SrcBucket: srcBucket, + SrcObject: srcObject, + DstBucket: DstBucket, + UploadID: uploadID, + RangeHeader: rangeHeader, + Part: part, + } + mock.lockCopyPart.Lock() + mock.calls.CopyPart = append(mock.calls.CopyPart, callInfo) + mock.lockCopyPart.Unlock() + return mock.CopyPartFunc(srcBucket, srcObject, DstBucket, uploadID, rangeHeader, part) +} + +// CopyPartCalls gets all the calls that were made to CopyPart. +// Check the length with: +// +// len(mockedBackend.CopyPartCalls()) +func (mock *BackendMock) CopyPartCalls() []struct { + SrcBucket string + SrcObject string + DstBucket string + UploadID string + RangeHeader string + Part int +} { + var calls []struct { + SrcBucket string + SrcObject string + DstBucket string + UploadID string + RangeHeader string + Part int + } + mock.lockCopyPart.RLock() + calls = mock.calls.CopyPart + mock.lockCopyPart.RUnlock() + return calls +} + +// CreateMultipartUpload calls CreateMultipartUploadFunc. +func (mock *BackendMock) CreateMultipartUpload(createMultipartUploadInput *s3.CreateMultipartUploadInput) (*s3.CreateMultipartUploadOutput, error) { + if mock.CreateMultipartUploadFunc == nil { + panic("BackendMock.CreateMultipartUploadFunc: method is nil but Backend.CreateMultipartUpload was just called") + } + callInfo := struct { + CreateMultipartUploadInput *s3.CreateMultipartUploadInput + }{ + CreateMultipartUploadInput: createMultipartUploadInput, + } + mock.lockCreateMultipartUpload.Lock() + mock.calls.CreateMultipartUpload = append(mock.calls.CreateMultipartUpload, callInfo) + mock.lockCreateMultipartUpload.Unlock() + return mock.CreateMultipartUploadFunc(createMultipartUploadInput) +} + +// CreateMultipartUploadCalls gets all the calls that were made to CreateMultipartUpload. +// Check the length with: +// +// len(mockedBackend.CreateMultipartUploadCalls()) +func (mock *BackendMock) CreateMultipartUploadCalls() []struct { + CreateMultipartUploadInput *s3.CreateMultipartUploadInput +} { + var calls []struct { + CreateMultipartUploadInput *s3.CreateMultipartUploadInput + } + mock.lockCreateMultipartUpload.RLock() + calls = mock.calls.CreateMultipartUpload + mock.lockCreateMultipartUpload.RUnlock() + return calls +} + +// DeleteBucket calls DeleteBucketFunc. +func (mock *BackendMock) DeleteBucket(bucket string) error { + if mock.DeleteBucketFunc == nil { + panic("BackendMock.DeleteBucketFunc: method is nil but Backend.DeleteBucket was just called") + } + callInfo := struct { + Bucket string + }{ + Bucket: bucket, + } + mock.lockDeleteBucket.Lock() + mock.calls.DeleteBucket = append(mock.calls.DeleteBucket, callInfo) + mock.lockDeleteBucket.Unlock() + return mock.DeleteBucketFunc(bucket) +} + +// DeleteBucketCalls gets all the calls that were made to DeleteBucket. +// Check the length with: +// +// len(mockedBackend.DeleteBucketCalls()) +func (mock *BackendMock) DeleteBucketCalls() []struct { + Bucket string +} { + var calls []struct { + Bucket string + } + mock.lockDeleteBucket.RLock() + calls = mock.calls.DeleteBucket + mock.lockDeleteBucket.RUnlock() + return calls +} + +// DeleteObject calls DeleteObjectFunc. +func (mock *BackendMock) DeleteObject(bucket string, object string) error { + if mock.DeleteObjectFunc == nil { + panic("BackendMock.DeleteObjectFunc: method is nil but Backend.DeleteObject was just called") + } + callInfo := struct { + Bucket string + Object string + }{ + Bucket: bucket, + Object: object, + } + mock.lockDeleteObject.Lock() + mock.calls.DeleteObject = append(mock.calls.DeleteObject, callInfo) + mock.lockDeleteObject.Unlock() + return mock.DeleteObjectFunc(bucket, object) +} + +// DeleteObjectCalls gets all the calls that were made to DeleteObject. +// Check the length with: +// +// len(mockedBackend.DeleteObjectCalls()) +func (mock *BackendMock) DeleteObjectCalls() []struct { + Bucket string + Object string +} { + var calls []struct { + Bucket string + Object string + } + mock.lockDeleteObject.RLock() + calls = mock.calls.DeleteObject + mock.lockDeleteObject.RUnlock() + return calls +} + +// DeleteObjects calls DeleteObjectsFunc. +func (mock *BackendMock) DeleteObjects(bucket string, objects *s3.DeleteObjectsInput) error { + if mock.DeleteObjectsFunc == nil { + panic("BackendMock.DeleteObjectsFunc: method is nil but Backend.DeleteObjects was just called") + } + callInfo := struct { + Bucket string + Objects *s3.DeleteObjectsInput + }{ + Bucket: bucket, + Objects: objects, + } + mock.lockDeleteObjects.Lock() + mock.calls.DeleteObjects = append(mock.calls.DeleteObjects, callInfo) + mock.lockDeleteObjects.Unlock() + return mock.DeleteObjectsFunc(bucket, objects) +} + +// DeleteObjectsCalls gets all the calls that were made to DeleteObjects. +// Check the length with: +// +// len(mockedBackend.DeleteObjectsCalls()) +func (mock *BackendMock) DeleteObjectsCalls() []struct { + Bucket string + Objects *s3.DeleteObjectsInput +} { + var calls []struct { + Bucket string + Objects *s3.DeleteObjectsInput + } + mock.lockDeleteObjects.RLock() + calls = mock.calls.DeleteObjects + mock.lockDeleteObjects.RUnlock() + return calls +} + +// GetBucketAcl calls GetBucketAclFunc. +func (mock *BackendMock) GetBucketAcl(bucket string) (*s3.GetBucketAclOutput, error) { + if mock.GetBucketAclFunc == nil { + panic("BackendMock.GetBucketAclFunc: method is nil but Backend.GetBucketAcl was just called") + } + callInfo := struct { + Bucket string + }{ + Bucket: bucket, + } + mock.lockGetBucketAcl.Lock() + mock.calls.GetBucketAcl = append(mock.calls.GetBucketAcl, callInfo) + mock.lockGetBucketAcl.Unlock() + return mock.GetBucketAclFunc(bucket) +} + +// GetBucketAclCalls gets all the calls that were made to GetBucketAcl. +// Check the length with: +// +// len(mockedBackend.GetBucketAclCalls()) +func (mock *BackendMock) GetBucketAclCalls() []struct { + Bucket string +} { + var calls []struct { + Bucket string + } + mock.lockGetBucketAcl.RLock() + calls = mock.calls.GetBucketAcl + mock.lockGetBucketAcl.RUnlock() + return calls +} + +// GetIAMConfig calls GetIAMConfigFunc. +func (mock *BackendMock) GetIAMConfig() ([]byte, error) { + if mock.GetIAMConfigFunc == nil { + panic("BackendMock.GetIAMConfigFunc: method is nil but Backend.GetIAMConfig was just called") + } + callInfo := struct { + }{} + mock.lockGetIAMConfig.Lock() + mock.calls.GetIAMConfig = append(mock.calls.GetIAMConfig, callInfo) + mock.lockGetIAMConfig.Unlock() + return mock.GetIAMConfigFunc() +} + +// GetIAMConfigCalls gets all the calls that were made to GetIAMConfig. +// Check the length with: +// +// len(mockedBackend.GetIAMConfigCalls()) +func (mock *BackendMock) GetIAMConfigCalls() []struct { +} { + var calls []struct { + } + mock.lockGetIAMConfig.RLock() + calls = mock.calls.GetIAMConfig + mock.lockGetIAMConfig.RUnlock() + return calls +} + +// GetObject calls GetObjectFunc. +func (mock *BackendMock) GetObject(bucket string, object string, startOffset int64, length int64, writer io.Writer, etag string) (*s3.GetObjectOutput, error) { + if mock.GetObjectFunc == nil { + panic("BackendMock.GetObjectFunc: method is nil but Backend.GetObject was just called") + } + callInfo := struct { + Bucket string + Object string + StartOffset int64 + Length int64 + Writer io.Writer + Etag string + }{ + Bucket: bucket, + Object: object, + StartOffset: startOffset, + Length: length, + Writer: writer, + Etag: etag, + } + mock.lockGetObject.Lock() + mock.calls.GetObject = append(mock.calls.GetObject, callInfo) + mock.lockGetObject.Unlock() + return mock.GetObjectFunc(bucket, object, startOffset, length, writer, etag) +} + +// GetObjectCalls gets all the calls that were made to GetObject. +// Check the length with: +// +// len(mockedBackend.GetObjectCalls()) +func (mock *BackendMock) GetObjectCalls() []struct { + Bucket string + Object string + StartOffset int64 + Length int64 + Writer io.Writer + Etag string +} { + var calls []struct { + Bucket string + Object string + StartOffset int64 + Length int64 + Writer io.Writer + Etag string + } + mock.lockGetObject.RLock() + calls = mock.calls.GetObject + mock.lockGetObject.RUnlock() + return calls +} + +// GetObjectAcl calls GetObjectAclFunc. +func (mock *BackendMock) GetObjectAcl(bucket string, object string) (*s3.GetObjectAclOutput, error) { + if mock.GetObjectAclFunc == nil { + panic("BackendMock.GetObjectAclFunc: method is nil but Backend.GetObjectAcl was just called") + } + callInfo := struct { + Bucket string + Object string + }{ + Bucket: bucket, + Object: object, + } + mock.lockGetObjectAcl.Lock() + mock.calls.GetObjectAcl = append(mock.calls.GetObjectAcl, callInfo) + mock.lockGetObjectAcl.Unlock() + return mock.GetObjectAclFunc(bucket, object) +} + +// GetObjectAclCalls gets all the calls that were made to GetObjectAcl. +// Check the length with: +// +// len(mockedBackend.GetObjectAclCalls()) +func (mock *BackendMock) GetObjectAclCalls() []struct { + Bucket string + Object string +} { + var calls []struct { + Bucket string + Object string + } + mock.lockGetObjectAcl.RLock() + calls = mock.calls.GetObjectAcl + mock.lockGetObjectAcl.RUnlock() + return calls +} + +// GetObjectAttributes calls GetObjectAttributesFunc. +func (mock *BackendMock) GetObjectAttributes(bucket string, object string, attributes []string) (*s3.GetObjectAttributesOutput, error) { + if mock.GetObjectAttributesFunc == nil { + panic("BackendMock.GetObjectAttributesFunc: method is nil but Backend.GetObjectAttributes was just called") + } + callInfo := struct { + Bucket string + Object string + Attributes []string + }{ + Bucket: bucket, + Object: object, + Attributes: attributes, + } + mock.lockGetObjectAttributes.Lock() + mock.calls.GetObjectAttributes = append(mock.calls.GetObjectAttributes, callInfo) + mock.lockGetObjectAttributes.Unlock() + return mock.GetObjectAttributesFunc(bucket, object, attributes) +} + +// GetObjectAttributesCalls gets all the calls that were made to GetObjectAttributes. +// Check the length with: +// +// len(mockedBackend.GetObjectAttributesCalls()) +func (mock *BackendMock) GetObjectAttributesCalls() []struct { + Bucket string + Object string + Attributes []string +} { + var calls []struct { + Bucket string + Object string + Attributes []string + } + mock.lockGetObjectAttributes.RLock() + calls = mock.calls.GetObjectAttributes + mock.lockGetObjectAttributes.RUnlock() + return calls +} + +// GetTags calls GetTagsFunc. +func (mock *BackendMock) GetTags(bucket string, object string) (map[string]string, error) { + if mock.GetTagsFunc == nil { + panic("BackendMock.GetTagsFunc: method is nil but Backend.GetTags was just called") + } + callInfo := struct { + Bucket string + Object string + }{ + Bucket: bucket, + Object: object, + } + mock.lockGetTags.Lock() + mock.calls.GetTags = append(mock.calls.GetTags, callInfo) + mock.lockGetTags.Unlock() + return mock.GetTagsFunc(bucket, object) +} + +// GetTagsCalls gets all the calls that were made to GetTags. +// Check the length with: +// +// len(mockedBackend.GetTagsCalls()) +func (mock *BackendMock) GetTagsCalls() []struct { + Bucket string + Object string +} { + var calls []struct { + Bucket string + Object string + } + mock.lockGetTags.RLock() + calls = mock.calls.GetTags + mock.lockGetTags.RUnlock() + return calls +} + +// HeadBucket calls HeadBucketFunc. +func (mock *BackendMock) HeadBucket(bucket string) (*s3.HeadBucketOutput, error) { + if mock.HeadBucketFunc == nil { + panic("BackendMock.HeadBucketFunc: method is nil but Backend.HeadBucket was just called") + } + callInfo := struct { + Bucket string + }{ + Bucket: bucket, + } + mock.lockHeadBucket.Lock() + mock.calls.HeadBucket = append(mock.calls.HeadBucket, callInfo) + mock.lockHeadBucket.Unlock() + return mock.HeadBucketFunc(bucket) +} + +// HeadBucketCalls gets all the calls that were made to HeadBucket. +// Check the length with: +// +// len(mockedBackend.HeadBucketCalls()) +func (mock *BackendMock) HeadBucketCalls() []struct { + Bucket string +} { + var calls []struct { + Bucket string + } + mock.lockHeadBucket.RLock() + calls = mock.calls.HeadBucket + mock.lockHeadBucket.RUnlock() + return calls +} + +// HeadObject calls HeadObjectFunc. +func (mock *BackendMock) HeadObject(bucket string, object string, etag string) (*s3.HeadObjectOutput, error) { + if mock.HeadObjectFunc == nil { + panic("BackendMock.HeadObjectFunc: method is nil but Backend.HeadObject was just called") + } + callInfo := struct { + Bucket string + Object string + Etag string + }{ + Bucket: bucket, + Object: object, + Etag: etag, + } + mock.lockHeadObject.Lock() + mock.calls.HeadObject = append(mock.calls.HeadObject, callInfo) + mock.lockHeadObject.Unlock() + return mock.HeadObjectFunc(bucket, object, etag) +} + +// HeadObjectCalls gets all the calls that were made to HeadObject. +// Check the length with: +// +// len(mockedBackend.HeadObjectCalls()) +func (mock *BackendMock) HeadObjectCalls() []struct { + Bucket string + Object string + Etag string +} { + var calls []struct { + Bucket string + Object string + Etag string + } + mock.lockHeadObject.RLock() + calls = mock.calls.HeadObject + mock.lockHeadObject.RUnlock() + return calls +} + +// IsTaggingSupported calls IsTaggingSupportedFunc. +func (mock *BackendMock) IsTaggingSupported() bool { + if mock.IsTaggingSupportedFunc == nil { + panic("BackendMock.IsTaggingSupportedFunc: method is nil but Backend.IsTaggingSupported was just called") + } + callInfo := struct { + }{} + mock.lockIsTaggingSupported.Lock() + mock.calls.IsTaggingSupported = append(mock.calls.IsTaggingSupported, callInfo) + mock.lockIsTaggingSupported.Unlock() + return mock.IsTaggingSupportedFunc() +} + +// IsTaggingSupportedCalls gets all the calls that were made to IsTaggingSupported. +// Check the length with: +// +// len(mockedBackend.IsTaggingSupportedCalls()) +func (mock *BackendMock) IsTaggingSupportedCalls() []struct { +} { + var calls []struct { + } + mock.lockIsTaggingSupported.RLock() + calls = mock.calls.IsTaggingSupported + mock.lockIsTaggingSupported.RUnlock() + return calls +} + +// ListBuckets calls ListBucketsFunc. +func (mock *BackendMock) ListBuckets() (*s3.ListBucketsOutput, error) { + if mock.ListBucketsFunc == nil { + panic("BackendMock.ListBucketsFunc: method is nil but Backend.ListBuckets was just called") + } + callInfo := struct { + }{} + mock.lockListBuckets.Lock() + mock.calls.ListBuckets = append(mock.calls.ListBuckets, callInfo) + mock.lockListBuckets.Unlock() + return mock.ListBucketsFunc() +} + +// ListBucketsCalls gets all the calls that were made to ListBuckets. +// Check the length with: +// +// len(mockedBackend.ListBucketsCalls()) +func (mock *BackendMock) ListBucketsCalls() []struct { +} { + var calls []struct { + } + mock.lockListBuckets.RLock() + calls = mock.calls.ListBuckets + mock.lockListBuckets.RUnlock() + return calls +} + +// ListMultipartUploads calls ListMultipartUploadsFunc. +func (mock *BackendMock) ListMultipartUploads(output *s3.ListMultipartUploadsInput) (*s3.ListMultipartUploadsOutput, error) { + if mock.ListMultipartUploadsFunc == nil { + panic("BackendMock.ListMultipartUploadsFunc: method is nil but Backend.ListMultipartUploads was just called") + } + callInfo := struct { + Output *s3.ListMultipartUploadsInput + }{ + Output: output, + } + mock.lockListMultipartUploads.Lock() + mock.calls.ListMultipartUploads = append(mock.calls.ListMultipartUploads, callInfo) + mock.lockListMultipartUploads.Unlock() + return mock.ListMultipartUploadsFunc(output) +} + +// ListMultipartUploadsCalls gets all the calls that were made to ListMultipartUploads. +// Check the length with: +// +// len(mockedBackend.ListMultipartUploadsCalls()) +func (mock *BackendMock) ListMultipartUploadsCalls() []struct { + Output *s3.ListMultipartUploadsInput +} { + var calls []struct { + Output *s3.ListMultipartUploadsInput + } + mock.lockListMultipartUploads.RLock() + calls = mock.calls.ListMultipartUploads + mock.lockListMultipartUploads.RUnlock() + return calls +} + +// ListObjectParts calls ListObjectPartsFunc. +func (mock *BackendMock) ListObjectParts(bucket string, object string, uploadID string, partNumberMarker int, maxParts int) (*s3.ListPartsOutput, error) { + if mock.ListObjectPartsFunc == nil { + panic("BackendMock.ListObjectPartsFunc: method is nil but Backend.ListObjectParts was just called") + } + callInfo := struct { + Bucket string + Object string + UploadID string + PartNumberMarker int + MaxParts int + }{ + Bucket: bucket, + Object: object, + UploadID: uploadID, + PartNumberMarker: partNumberMarker, + MaxParts: maxParts, + } + mock.lockListObjectParts.Lock() + mock.calls.ListObjectParts = append(mock.calls.ListObjectParts, callInfo) + mock.lockListObjectParts.Unlock() + return mock.ListObjectPartsFunc(bucket, object, uploadID, partNumberMarker, maxParts) +} + +// ListObjectPartsCalls gets all the calls that were made to ListObjectParts. +// Check the length with: +// +// len(mockedBackend.ListObjectPartsCalls()) +func (mock *BackendMock) ListObjectPartsCalls() []struct { + Bucket string + Object string + UploadID string + PartNumberMarker int + MaxParts int +} { + var calls []struct { + Bucket string + Object string + UploadID string + PartNumberMarker int + MaxParts int + } + mock.lockListObjectParts.RLock() + calls = mock.calls.ListObjectParts + mock.lockListObjectParts.RUnlock() + return calls +} + +// ListObjects calls ListObjectsFunc. +func (mock *BackendMock) ListObjects(bucket string, prefix string, marker string, delim string, maxkeys int) (*s3.ListBucketsOutput, error) { + if mock.ListObjectsFunc == nil { + panic("BackendMock.ListObjectsFunc: method is nil but Backend.ListObjects was just called") + } + callInfo := struct { + Bucket string + Prefix string + Marker string + Delim string + Maxkeys int + }{ + Bucket: bucket, + Prefix: prefix, + Marker: marker, + Delim: delim, + Maxkeys: maxkeys, + } + mock.lockListObjects.Lock() + mock.calls.ListObjects = append(mock.calls.ListObjects, callInfo) + mock.lockListObjects.Unlock() + return mock.ListObjectsFunc(bucket, prefix, marker, delim, maxkeys) +} + +// ListObjectsCalls gets all the calls that were made to ListObjects. +// Check the length with: +// +// len(mockedBackend.ListObjectsCalls()) +func (mock *BackendMock) ListObjectsCalls() []struct { + Bucket string + Prefix string + Marker string + Delim string + Maxkeys int +} { + var calls []struct { + Bucket string + Prefix string + Marker string + Delim string + Maxkeys int + } + mock.lockListObjects.RLock() + calls = mock.calls.ListObjects + mock.lockListObjects.RUnlock() + return calls +} + +// ListObjectsV2 calls ListObjectsV2Func. +func (mock *BackendMock) ListObjectsV2(bucket string, prefix string, marker string, delim string, maxkeys int) (*s3.ListBucketsOutput, error) { + if mock.ListObjectsV2Func == nil { + panic("BackendMock.ListObjectsV2Func: method is nil but Backend.ListObjectsV2 was just called") + } + callInfo := struct { + Bucket string + Prefix string + Marker string + Delim string + Maxkeys int + }{ + Bucket: bucket, + Prefix: prefix, + Marker: marker, + Delim: delim, + Maxkeys: maxkeys, + } + mock.lockListObjectsV2.Lock() + mock.calls.ListObjectsV2 = append(mock.calls.ListObjectsV2, callInfo) + mock.lockListObjectsV2.Unlock() + return mock.ListObjectsV2Func(bucket, prefix, marker, delim, maxkeys) +} + +// ListObjectsV2Calls gets all the calls that were made to ListObjectsV2. +// Check the length with: +// +// len(mockedBackend.ListObjectsV2Calls()) +func (mock *BackendMock) ListObjectsV2Calls() []struct { + Bucket string + Prefix string + Marker string + Delim string + Maxkeys int +} { + var calls []struct { + Bucket string + Prefix string + Marker string + Delim string + Maxkeys int + } + mock.lockListObjectsV2.RLock() + calls = mock.calls.ListObjectsV2 + mock.lockListObjectsV2.RUnlock() + return calls +} + +// PutBucket calls PutBucketFunc. +func (mock *BackendMock) PutBucket(bucket string) error { + if mock.PutBucketFunc == nil { + panic("BackendMock.PutBucketFunc: method is nil but Backend.PutBucket was just called") + } + callInfo := struct { + Bucket string + }{ + Bucket: bucket, + } + mock.lockPutBucket.Lock() + mock.calls.PutBucket = append(mock.calls.PutBucket, callInfo) + mock.lockPutBucket.Unlock() + return mock.PutBucketFunc(bucket) +} + +// PutBucketCalls gets all the calls that were made to PutBucket. +// Check the length with: +// +// len(mockedBackend.PutBucketCalls()) +func (mock *BackendMock) PutBucketCalls() []struct { + Bucket string +} { + var calls []struct { + Bucket string + } + mock.lockPutBucket.RLock() + calls = mock.calls.PutBucket + mock.lockPutBucket.RUnlock() + return calls +} + +// PutBucketAcl calls PutBucketAclFunc. +func (mock *BackendMock) PutBucketAcl(putBucketAclInput *s3.PutBucketAclInput) error { + if mock.PutBucketAclFunc == nil { + panic("BackendMock.PutBucketAclFunc: method is nil but Backend.PutBucketAcl was just called") + } + callInfo := struct { + PutBucketAclInput *s3.PutBucketAclInput + }{ + PutBucketAclInput: putBucketAclInput, + } + mock.lockPutBucketAcl.Lock() + mock.calls.PutBucketAcl = append(mock.calls.PutBucketAcl, callInfo) + mock.lockPutBucketAcl.Unlock() + return mock.PutBucketAclFunc(putBucketAclInput) +} + +// PutBucketAclCalls gets all the calls that were made to PutBucketAcl. +// Check the length with: +// +// len(mockedBackend.PutBucketAclCalls()) +func (mock *BackendMock) PutBucketAclCalls() []struct { + PutBucketAclInput *s3.PutBucketAclInput +} { + var calls []struct { + PutBucketAclInput *s3.PutBucketAclInput + } + mock.lockPutBucketAcl.RLock() + calls = mock.calls.PutBucketAcl + mock.lockPutBucketAcl.RUnlock() + return calls +} + +// PutObject calls PutObjectFunc. +func (mock *BackendMock) PutObject(bucket string, object string, r io.Reader) (string, error) { + if mock.PutObjectFunc == nil { + panic("BackendMock.PutObjectFunc: method is nil but Backend.PutObject was just called") + } + callInfo := struct { + Bucket string + Object string + R io.Reader + }{ + Bucket: bucket, + Object: object, + R: r, + } + mock.lockPutObject.Lock() + mock.calls.PutObject = append(mock.calls.PutObject, callInfo) + mock.lockPutObject.Unlock() + return mock.PutObjectFunc(bucket, object, r) +} + +// PutObjectCalls gets all the calls that were made to PutObject. +// Check the length with: +// +// len(mockedBackend.PutObjectCalls()) +func (mock *BackendMock) PutObjectCalls() []struct { + Bucket string + Object string + R io.Reader +} { + var calls []struct { + Bucket string + Object string + R io.Reader + } + mock.lockPutObject.RLock() + calls = mock.calls.PutObject + mock.lockPutObject.RUnlock() + return calls +} + +// PutObjectAcl calls PutObjectAclFunc. +func (mock *BackendMock) PutObjectAcl(putObjectAclInput *s3.PutObjectAclInput) error { + if mock.PutObjectAclFunc == nil { + panic("BackendMock.PutObjectAclFunc: method is nil but Backend.PutObjectAcl was just called") + } + callInfo := struct { + PutObjectAclInput *s3.PutObjectAclInput + }{ + PutObjectAclInput: putObjectAclInput, + } + mock.lockPutObjectAcl.Lock() + mock.calls.PutObjectAcl = append(mock.calls.PutObjectAcl, callInfo) + mock.lockPutObjectAcl.Unlock() + return mock.PutObjectAclFunc(putObjectAclInput) +} + +// PutObjectAclCalls gets all the calls that were made to PutObjectAcl. +// Check the length with: +// +// len(mockedBackend.PutObjectAclCalls()) +func (mock *BackendMock) PutObjectAclCalls() []struct { + PutObjectAclInput *s3.PutObjectAclInput +} { + var calls []struct { + PutObjectAclInput *s3.PutObjectAclInput + } + mock.lockPutObjectAcl.RLock() + calls = mock.calls.PutObjectAcl + mock.lockPutObjectAcl.RUnlock() + return calls +} + +// PutObjectPart calls PutObjectPartFunc. +func (mock *BackendMock) PutObjectPart(bucket string, object string, uploadID string, part int, r io.Reader) (string, error) { + if mock.PutObjectPartFunc == nil { + panic("BackendMock.PutObjectPartFunc: method is nil but Backend.PutObjectPart was just called") + } + callInfo := struct { + Bucket string + Object string + UploadID string + Part int + R io.Reader + }{ + Bucket: bucket, + Object: object, + UploadID: uploadID, + Part: part, + R: r, + } + mock.lockPutObjectPart.Lock() + mock.calls.PutObjectPart = append(mock.calls.PutObjectPart, callInfo) + mock.lockPutObjectPart.Unlock() + return mock.PutObjectPartFunc(bucket, object, uploadID, part, r) +} + +// PutObjectPartCalls gets all the calls that were made to PutObjectPart. +// Check the length with: +// +// len(mockedBackend.PutObjectPartCalls()) +func (mock *BackendMock) PutObjectPartCalls() []struct { + Bucket string + Object string + UploadID string + Part int + R io.Reader +} { + var calls []struct { + Bucket string + Object string + UploadID string + Part int + R io.Reader + } + mock.lockPutObjectPart.RLock() + calls = mock.calls.PutObjectPart + mock.lockPutObjectPart.RUnlock() + return calls +} + +// RemoveTags calls RemoveTagsFunc. +func (mock *BackendMock) RemoveTags(bucket string, object string) error { + if mock.RemoveTagsFunc == nil { + panic("BackendMock.RemoveTagsFunc: method is nil but Backend.RemoveTags was just called") + } + callInfo := struct { + Bucket string + Object string + }{ + Bucket: bucket, + Object: object, + } + mock.lockRemoveTags.Lock() + mock.calls.RemoveTags = append(mock.calls.RemoveTags, callInfo) + mock.lockRemoveTags.Unlock() + return mock.RemoveTagsFunc(bucket, object) +} + +// RemoveTagsCalls gets all the calls that were made to RemoveTags. +// Check the length with: +// +// len(mockedBackend.RemoveTagsCalls()) +func (mock *BackendMock) RemoveTagsCalls() []struct { + Bucket string + Object string +} { + var calls []struct { + Bucket string + Object string + } + mock.lockRemoveTags.RLock() + calls = mock.calls.RemoveTags + mock.lockRemoveTags.RUnlock() + return calls +} + +// RestoreObject calls RestoreObjectFunc. +func (mock *BackendMock) RestoreObject(bucket string, object string, restoreRequest *s3.RestoreObjectInput) error { + if mock.RestoreObjectFunc == nil { + panic("BackendMock.RestoreObjectFunc: method is nil but Backend.RestoreObject was just called") + } + callInfo := struct { + Bucket string + Object string + RestoreRequest *s3.RestoreObjectInput + }{ + Bucket: bucket, + Object: object, + RestoreRequest: restoreRequest, + } + mock.lockRestoreObject.Lock() + mock.calls.RestoreObject = append(mock.calls.RestoreObject, callInfo) + mock.lockRestoreObject.Unlock() + return mock.RestoreObjectFunc(bucket, object, restoreRequest) +} + +// RestoreObjectCalls gets all the calls that were made to RestoreObject. +// Check the length with: +// +// len(mockedBackend.RestoreObjectCalls()) +func (mock *BackendMock) RestoreObjectCalls() []struct { + Bucket string + Object string + RestoreRequest *s3.RestoreObjectInput +} { + var calls []struct { + Bucket string + Object string + RestoreRequest *s3.RestoreObjectInput + } + mock.lockRestoreObject.RLock() + calls = mock.calls.RestoreObject + mock.lockRestoreObject.RUnlock() + return calls +} + +// SetTags calls SetTagsFunc. +func (mock *BackendMock) SetTags(bucket string, object string, tags map[string]string) error { + if mock.SetTagsFunc == nil { + panic("BackendMock.SetTagsFunc: method is nil but Backend.SetTags was just called") + } + callInfo := struct { + Bucket string + Object string + Tags map[string]string + }{ + Bucket: bucket, + Object: object, + Tags: tags, + } + mock.lockSetTags.Lock() + mock.calls.SetTags = append(mock.calls.SetTags, callInfo) + mock.lockSetTags.Unlock() + return mock.SetTagsFunc(bucket, object, tags) +} + +// SetTagsCalls gets all the calls that were made to SetTags. +// Check the length with: +// +// len(mockedBackend.SetTagsCalls()) +func (mock *BackendMock) SetTagsCalls() []struct { + Bucket string + Object string + Tags map[string]string +} { + var calls []struct { + Bucket string + Object string + Tags map[string]string + } + mock.lockSetTags.RLock() + calls = mock.calls.SetTags + mock.lockSetTags.RUnlock() + return calls +} + +// Shutdown calls ShutdownFunc. +func (mock *BackendMock) Shutdown() { + if mock.ShutdownFunc == nil { + panic("BackendMock.ShutdownFunc: method is nil but Backend.Shutdown was just called") + } + callInfo := struct { + }{} + mock.lockShutdown.Lock() + mock.calls.Shutdown = append(mock.calls.Shutdown, callInfo) + mock.lockShutdown.Unlock() + mock.ShutdownFunc() +} + +// ShutdownCalls gets all the calls that were made to Shutdown. +// Check the length with: +// +// len(mockedBackend.ShutdownCalls()) +func (mock *BackendMock) ShutdownCalls() []struct { +} { + var calls []struct { + } + mock.lockShutdown.RLock() + calls = mock.calls.Shutdown + mock.lockShutdown.RUnlock() + return calls +} + +// String calls StringFunc. +func (mock *BackendMock) String() string { + if mock.StringFunc == nil { + panic("BackendMock.StringFunc: method is nil but Backend.String was just called") + } + callInfo := struct { + }{} + mock.lockString.Lock() + mock.calls.String = append(mock.calls.String, callInfo) + mock.lockString.Unlock() + return mock.StringFunc() +} + +// StringCalls gets all the calls that were made to String. +// Check the length with: +// +// len(mockedBackend.StringCalls()) +func (mock *BackendMock) StringCalls() []struct { +} { + var calls []struct { + } + mock.lockString.RLock() + calls = mock.calls.String + mock.lockString.RUnlock() + return calls +} + +// UploadPart calls UploadPartFunc. +func (mock *BackendMock) UploadPart(bucket string, object string, uploadId string, Body io.ReadSeeker) (*s3.UploadPartOutput, error) { + if mock.UploadPartFunc == nil { + panic("BackendMock.UploadPartFunc: method is nil but Backend.UploadPart was just called") + } + callInfo := struct { + Bucket string + Object string + UploadId string + Body io.ReadSeeker + }{ + Bucket: bucket, + Object: object, + UploadId: uploadId, + Body: Body, + } + mock.lockUploadPart.Lock() + mock.calls.UploadPart = append(mock.calls.UploadPart, callInfo) + mock.lockUploadPart.Unlock() + return mock.UploadPartFunc(bucket, object, uploadId, Body) +} + +// UploadPartCalls gets all the calls that were made to UploadPart. +// Check the length with: +// +// len(mockedBackend.UploadPartCalls()) +func (mock *BackendMock) UploadPartCalls() []struct { + Bucket string + Object string + UploadId string + Body io.ReadSeeker +} { + var calls []struct { + Bucket string + Object string + UploadId string + Body io.ReadSeeker + } + mock.lockUploadPart.RLock() + calls = mock.calls.UploadPart + mock.lockUploadPart.RUnlock() + return calls +} + +// UploadPartCopy calls UploadPartCopyFunc. +func (mock *BackendMock) UploadPartCopy(uploadPartCopyInput *s3.UploadPartCopyInput) (*s3.UploadPartCopyOutput, error) { + if mock.UploadPartCopyFunc == nil { + panic("BackendMock.UploadPartCopyFunc: method is nil but Backend.UploadPartCopy was just called") + } + callInfo := struct { + UploadPartCopyInput *s3.UploadPartCopyInput + }{ + UploadPartCopyInput: uploadPartCopyInput, + } + mock.lockUploadPartCopy.Lock() + mock.calls.UploadPartCopy = append(mock.calls.UploadPartCopy, callInfo) + mock.lockUploadPartCopy.Unlock() + return mock.UploadPartCopyFunc(uploadPartCopyInput) +} + +// UploadPartCopyCalls gets all the calls that were made to UploadPartCopy. +// Check the length with: +// +// len(mockedBackend.UploadPartCopyCalls()) +func (mock *BackendMock) UploadPartCopyCalls() []struct { + UploadPartCopyInput *s3.UploadPartCopyInput +} { + var calls []struct { + UploadPartCopyInput *s3.UploadPartCopyInput + } + mock.lockUploadPartCopy.RLock() + calls = mock.calls.UploadPartCopy + mock.lockUploadPartCopy.RUnlock() + return calls +} diff --git a/s3api/controllers/base_test.go b/s3api/controllers/base_test.go index 4c17951..50b58fe 100644 --- a/s3api/controllers/base_test.go +++ b/s3api/controllers/base_test.go @@ -4,9 +4,11 @@ import ( "reflect" "testing" + "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/gofiber/fiber/v2" "github.com/valyala/fasthttp" "github.com/versity/scoutgw/backend" + "github.com/versity/scoutgw/s3err" ) func TestNew(t *testing.T) { @@ -48,26 +50,52 @@ func TestS3ApiController_ListBuckets(t *testing.T) { app := fiber.New() tests := []struct { - name string - c S3ApiController - args args - wantErr bool + name string + c S3ApiController + args args + wantErr bool + statusCode int }{ { - name: "Returns successful response", + name: "List-bucket-not-implemented", c: S3ApiController{ be: backend.BackendUnsupported{}, }, args: args{ ctx: app.AcquireCtx(&fasthttp.RequestCtx{}), }, - wantErr: false, + wantErr: false, + statusCode: 501, + }, + { + name: "list-bucket-success", + c: S3ApiController{ + be: &BackendMock{ + ListBucketsFunc: func() (*s3.ListBucketsOutput, error) { + return &s3.ListBucketsOutput{}, nil + }, + }, + }, + args: args{ + ctx: app.AcquireCtx(&fasthttp.RequestCtx{}), + }, + wantErr: false, + statusCode: 200, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := tt.c.ListBuckets(tt.args.ctx); (err != nil) != tt.wantErr { + err := tt.c.ListBuckets(tt.args.ctx) + + if (err != nil) != tt.wantErr { t.Errorf("S3ApiController.ListBuckets() error = %v, wantErr %v", err, tt.wantErr) + return + } + + statusCode := tt.args.ctx.Response().StatusCode() + + if statusCode != tt.statusCode { + t.Errorf("S3ApiController.ListBuckets() code = %v, wantErr %v", statusCode, tt.wantErr) } }) } @@ -289,18 +317,66 @@ func Test_responce(t *testing.T) { resp any err error } + app := fiber.New() + ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) + tests := []struct { - name string - args args - wantErr bool + name string + args args + wantErr bool + statusCode int }{ - // TODO: Add test cases. + { + name: "Internal-server-error", + args: args{ + ctx: ctx, + resp: nil, + err: s3err.GetAPIError(16), + }, + wantErr: false, + statusCode: 500, + }, + { + name: "Error-not-implemented", + args: args{ + ctx: ctx, + resp: nil, + err: s3err.GetAPIError(50), + }, + wantErr: false, + statusCode: 501, + }, + { + name: "Invalid-request-body", + args: args{ + ctx: ctx, + resp: make(chan int), + err: nil, + }, + wantErr: true, + statusCode: 501, + }, + { + name: "Successful-response", + args: args{ + ctx: ctx, + resp: "Valid response", + err: nil, + }, + statusCode: 200, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if err := responce(tt.args.ctx, tt.args.resp, tt.args.err); (err != nil) != tt.wantErr { t.Errorf("responce() error = %v, wantErr %v", err, tt.wantErr) } + + statusCode := tt.args.ctx.Response().StatusCode() + + if statusCode != tt.statusCode { + t.Errorf("responce() code = %v, wantErr %v", statusCode, tt.wantErr) + } }) } }