-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinterfaces.go
More file actions
81 lines (67 loc) · 2.89 KB
/
interfaces.go
File metadata and controls
81 lines (67 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package storage
import (
"io"
s3 "github.com/minio/minio-go"
)
// BucketCreator is a *(github.com/minio/minio-go).Client compatible interface, restricted to just the MakeBucket function. You can use it in your code for easier unit testing without any external dependencies
type BucketCreator interface {
MakeBucket(bucketName string, acl s3.BucketACL, location string) error
}
type FakeMakeBucketCall struct {
BucketName string
ACL s3.BucketACL
Location string
}
// FakeBucketCreator is a mock function that can be swapped in for an BucketCreator, so you can unit test your code
type FakeBucketCreator struct {
Fn func(string, s3.BucketACL, string) error
Calls []FakeMakeBucketCall
}
// PutObject is the interface definition
func (f *FakeBucketCreator) MakeBucket(name string, acl s3.BucketACL, location string) error {
f.Calls = append(f.Calls, FakeMakeBucketCall{BucketName: name, ACL: acl, Location: location})
return f.Fn(name, acl, location)
}
// ObjectStatter is a *(github.com/minio/minio-go).Client compatible interface, restricted to just the StatObject function. You can use it in your code for easier unit testing without any external dependencies
type ObjectStatter interface {
StatObject(bucketName, objectKey string) (s3.ObjectInfo, error)
}
type FakeStatObjectCall struct {
BucketName string
ObjectKey string
}
// FakeObjectStatter is a mock function that can be swapped in for an ObjectStatter, so you can unit test your code
type FakeObjectStatter struct {
Fn func(string, string) (s3.ObjectInfo, error)
Calls []FakeStatObjectCall
}
// PutObject is the interface definition
func (f *FakeObjectStatter) StatObject(bucketName, objectKey string) (s3.ObjectInfo, error) {
f.Calls = append(f.Calls, FakeStatObjectCall{BucketName: bucketName, ObjectKey: objectKey})
return f.Fn(bucketName, objectKey)
}
// ObjectPutter is a *(github.com/minio/minio-go).Client compatible interface, restricted to just the PutObject function. You can use it in your code for easier unit testing without any external dependencies
type ObjectPutter interface {
PutObject(bucketName, objectKey string, reader io.Reader, contentType string) (int64, error)
}
type FakePutObjectCall struct {
BucketName string
ObjectKey string
Reader io.Reader
ContentType string
}
// FakeObjectPutter is a mock function that can be swapped in for an ObjectPutter, so you can unit test your code
type FakeObjectPutter struct {
Fn func(bucketName, objectKey string, reader io.Reader, contentType string) (int64, error)
Calls []FakePutObjectCall
}
// PutObject is the interface definition
func (f *FakeObjectPutter) PutObject(bucketName, objectKey string, reader io.Reader, contentType string) (int64, error) {
f.Calls = append(f.Calls, FakePutObjectCall{
BucketName: bucketName,
ObjectKey: objectKey,
Reader: reader,
ContentType: contentType,
})
return f.Fn(bucketName, objectKey, reader, contentType)
}