Closed plastikfan closed 8 months ago
The following command generated a mock for VIperConfig (run from the repo root dir):
mockgen -destination src/assistant/mocks/mock-global-viper-config.go -package mocks -source src/assistant/configuration/global-config.go -mock_names ViperConfig=MockViperConfig
Since we want mocks to be used externally, we generate the mocks inside a mocks
package, not mocks_test
.
A new task co-gen-vc has been added and a go generate statement added to global-config.go
Need to start using mocking, in this case so we can mock out viper config. Using uber mock.
The first to know, is how to make a mock; here is the documented example (as described in mock_test.go):
Repository=MockSensorRepository,Endpoint=MockSensorEndpoint
, whereRepository
is the interface name andMockSensorRepository
is the desired mock name-source=foo.go
But actually, this doesnt clearly explain how to mock a foreign interface. I found this: codecentric.de gomock-tutorial, which may be a bit clearer, in particular:
where:
github.com/sgreben/testing-with-gomock/doer
is the import path andDoer
is the symbol to be mocked