2017-05-08 23:07:07 +02:00
|
|
|
package s3manager_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2017-05-25 18:33:44 +02:00
|
|
|
. "github.com/mastertinner/s3manager"
|
2017-05-08 23:07:07 +02:00
|
|
|
minio "github.com/minio/minio-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
// s3Mock is a mocked S3 client.
|
|
|
|
type s3Mock struct {
|
|
|
|
Buckets []minio.BucketInfo
|
|
|
|
Objects []minio.ObjectInfo
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
|
|
|
// CopyObject mocks minio.Client.CopyObject.
|
2017-07-31 10:57:22 +02:00
|
|
|
func (s *s3Mock) CopyObject(minio.DestinationInfo, minio.SourceInfo) error {
|
2017-05-08 23:07:07 +02:00
|
|
|
return s.Err
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetObject mocks minio.Client.GetObject.
|
2017-12-05 23:30:28 +01:00
|
|
|
func (s *s3Mock) GetObject(bucketName string, objectName string, opts minio.GetObjectOptions) (*minio.Object, error) {
|
2017-05-08 23:07:07 +02:00
|
|
|
if s.Err != nil {
|
|
|
|
return nil, s.Err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &minio.Object{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListBuckets mocks minio.Client.ListBuckets.
|
|
|
|
func (s *s3Mock) ListBuckets() ([]minio.BucketInfo, error) {
|
|
|
|
return s.Buckets, s.Err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if bucket exists
|
|
|
|
found := false
|
|
|
|
for _, b := range s.Buckets {
|
|
|
|
if b.Name == name {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
s.Objects = append(s.Objects, minio.ObjectInfo{
|
2017-05-25 18:33:44 +02:00
|
|
|
Err: ErrBucketDoesNotExist,
|
2017-05-08 23:07:07 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
objCh := make(chan minio.ObjectInfo, len(s.Objects))
|
|
|
|
defer close(objCh)
|
|
|
|
|
|
|
|
for _, obj := range s.Objects {
|
|
|
|
objCh <- obj
|
|
|
|
}
|
|
|
|
|
|
|
|
return objCh
|
|
|
|
}
|
|
|
|
|
|
|
|
// MakeBucket mocks minio.Client.MakeBucket.
|
|
|
|
func (s *s3Mock) MakeBucket(string, string) error {
|
|
|
|
return s.Err
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutObject mocks minio.Client.PutObject.
|
2017-12-05 23:30:28 +01:00
|
|
|
func (s *s3Mock) PutObject(string, string, io.Reader, int64, minio.PutObjectOptions) (int64, error) {
|
2017-05-08 23:07:07 +02:00
|
|
|
return 0, s.Err
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveBucket mocks minio.Client.RemoveBucket.
|
|
|
|
func (s *s3Mock) RemoveBucket(string) error {
|
|
|
|
return s.Err
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveObject mocks minio.Client.RemoveObject.
|
|
|
|
func (s *s3Mock) RemoveObject(string, string) error {
|
|
|
|
return s.Err
|
|
|
|
}
|