Skip to content

Instantly share code, notes, and snippets.

@csmith0651
Last active October 17, 2016 20:17
Show Gist options
  • Save csmith0651/f674268eb807f201459803d7822f38d0 to your computer and use it in GitHub Desktop.
Save csmith0651/f674268eb807f201459803d7822f38d0 to your computer and use it in GitHub Desktop.
example of registering a mock call on the mock object.
Context("ReadPersonFromS3 -- using mock", func() {
bucket := "testbucket"
key := "persondata.txt"
objectInput := &s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
}
goodObjectOutput := &s3.GetObjectOutput{
Body: S3Fetcher.NewMockBody([]byte(goodJson)),
}
BeforeEach(func() {
mockFetcher = mock_S3Fetcher.NewMockS3Fetcher(ctrl)
})
Context("reads data from S3", func() {
var testCall *gomock.Call
BeforeEach(func() {
testCall = mockFetcher.EXPECT().GetObject(objectInput).Return(goodObjectOutput, nil).AnyTimes()
})
It("and succeeds", func() {
Expect(ReadPersonFromS3(mockFetcher)).To(HaveLen(2))
testCall.Times(1)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment