Originally it's Mockery-example
Example case for mockery issue #128 filed with the golang tool "mockery".
But right now, I added more complex examples
- Mock
- Remove duplicated vscode plugin on mac
use go mod vendor
to download code
warning
- s3 is a struct, so
mockgen --build_flags=--mod=mod github.com/aws/aws-sdk-go/service/s3 S3
is wrong
mockgen --build_flags=--mod=mod github.com/aws/aws-sdk-go/service/s3/s3iface S3API > mocks/second_mocks.go
What if I want mockery api for mocking and generation ??
- add
_ "github.com/aws/aws-sdk-go/service/s3/s3iface/interface.go"
- go mod vendor
- run below, but mocks/S3API.go will be overwritten !!!
mockery --dir vendor/github.com/aws/aws-sdk-go/service/s3/s3iface --name S3API
run go mod vendor
to pull code
mockgen --build_flags=--mod=mod vendor/github.com/aws/aws-sdk-go/service/s3 S3
import _ "github.com/golang/mock/mockgen/model"
Better try method 3 !
mockgen vendor/github.com/aws/aws-sdk-go/service/s3 S3
prog.go:14:2: use of vendored package not allowed
prog.go:12:2: no required module provides package github.com/golang/mock/mockgen/model: go.mod file not found in current directory or any parent directory; see 'go help modules'
prog.go:14:2: vendor/github.com/aws/aws-sdk-go/service/s3 must be imported as github.com/aws/aws-sdk-go/service/s3
2022/01/21 17:54:17 Loading input failed: exit status 1
run test with coverage. shows main.go 0% covered, but mocks folder has 33%!!!
Why on earth we calculate coverage stats on that bits !!
-
Why gomock or mockery not generate from struct as extra feature, as in case of s3 struct.
-
gcp sdk Has more good pratices
-
more gcp shows fake data has been set in google style.
But, this blog points out:
Google engineer prefer hand-code fake rather reflection mock
Andrew Gerrand mentions gomock, a mocking library, and reluctantly says
[mocking libraries like gomock] are fine,
but I find that on balance the hand-written fakes tend be easier to reason about
and clearer to see what's going on, but I'm not an enterprise go programmer
so maybe people do need that so I don't know, but that's my advice.
-
uber/kraken Manually create s3 interface. But their Makefile mockgen heaps of stuff !!
-
aws-go Lots of http code
-
counterfeiter demo by mario Probably interesting