Daily Archives: 07.02.2021
Mocking for unit-tests and e2e-tests in golang
Some patterns to test your golang app. Mocking an interface 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 …