Skip to content

Commit 4075413

Browse files
author
Aaron Schlesinger
committed
feat(pkg/gitreceive/storage/interfaces.go): add godoc and fakes for unit testing
1 parent d1f28e3 commit 4075413

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

pkg/gitreceive/storage/interfaces.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,41 @@ import (
66
s3 "github.com/minio/minio-go"
77
)
88

9+
// 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
910
type BucketCreator interface {
1011
MakeBucket(bucketName string, acl s3.BucketACL, location string) error
1112
}
1213

14+
// FakeBucketCreator is a mock function that can be swapped in for an BucketCreator, so you can unit test your code
15+
type FakeBucketCreator func(string, s3.BucketACL, string) error
16+
17+
// PutObject is the interface definition
18+
func (f FakeBucketCreator) MakeBucket(name string, acl s3.BucketACL, location string) error {
19+
return f(name, acl, location)
20+
}
21+
22+
// 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
1323
type ObjectStatter interface {
1424
StatObject(bucketName, objectKey string) (s3.ObjectInfo, error)
1525
}
1626

27+
// FakeObjectStatter is a mock function that can be swapped in for an ObjectStatter, so you can unit test your code
28+
type FakeObjectStatter func(string, string) (s3.ObjectInfo, error)
29+
30+
// PutObject is the interface definition
31+
func (f FakeObjectStatter) StatObject(bucketName, objectKey string) (s3.ObjectInfo, error) {
32+
return f(bucketName, objectKey)
33+
}
34+
35+
// 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
1736
type ObjectPutter interface {
1837
PutObject(bucketName, objectKey string, reader io.Reader, contentType string) (int64, error)
1938
}
39+
40+
// FakeObjectPutter is a mock function that can be swapped in for an ObjectPutter, so you can unit test your code
41+
type FakeObjectPutter func(bucketName, objectKey string, reader io.Reader, contentType string) (int64, error)
42+
43+
// PutObject is the interface definition
44+
func (f FakeObjectPutter) PutObject(bucketName, objectKey string, reader io.Reader, contentType string) (int64, error) {
45+
return f(bucketName, objectKey, reader, contentType)
46+
}

0 commit comments

Comments
 (0)