-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain_test.go
43 lines (36 loc) · 1.12 KB
/
main_test.go
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
package main
import (
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/jaytaylor/mockery-example/mocks"
"github.com/stretchr/testify/mock"
)
func TestS3Mock(t *testing.T) {
mockS3 := &mocks.S3API{}
mockResultFn := func(input *s3.ListObjectsInput) *s3.ListObjectsOutput {
output := &s3.ListObjectsOutput{}
output.SetCommonPrefixes([]*s3.CommonPrefix{
&s3.CommonPrefix{
Prefix: aws.String("2017-01-01"),
},
})
return output
}
// NB: .Return(...) must return the same signature as the method being mocked.
// In this case it's (*s3.ListObjectsOutput, error).
mockS3.On("ListObjects", mock.MatchedBy(func(input *s3.ListObjectsInput) bool {
return input.Delimiter != nil && *input.Delimiter == "/" && input.Prefix == nil
})).Return(mockResultFn, nil)
listingInput := &s3.ListObjectsInput{
Bucket: aws.String("foo"),
Delimiter: aws.String("/"),
}
listingOutput, err := mockS3.ListObjects(listingInput)
if err != nil {
t.Fatalf("Error listing keys: %s", err)
}
for _, x := range listingOutput.CommonPrefixes {
t.Logf("common prefix: %+v", *x)
}
}