Mocking for testing go code

If you’re testing go code and have a huge API you have to mock, you have two options:
make your dummy struct with embedded interface and implement only methods you need, or
use your own interface that has only methods you need (and change your code to use that).

For instance, I had amazon’s s3 API, which is about 100 methods long, and I only needed two of them (for instance).

So, I declare my own interface and have couple of structs, see code below:

If you want to generate mocks, you can use these two libraries:
mockery
minimock

Similar Posts

    None Found

LEAVE A COMMENT