I've implemented a wrapper for the Docker ApiClient like so
type DockerClient struct {
cli client.APIClient
}
I've also defined my own interface for interacting with Docker like so
type Dockerer interface {
Init() error
CreateContainer(ctx context.Context, imageName string) (string, error)
RunCommand(ctx context.Context, containerId string, command string) (string, int, error)
StopContainer(ctx context.Context, containerId string) error
}
DockerClient implements the functions in the Dockerer interface like so:
func (d *DockerClient) Init() error {
//...
}
func (d *DockerClient) CreateContainer(ctx context.Context, imageName string) (string, error) {
//...
}
func (d *DockerClient) RunCommand(ctx context.Context, containerId string, command string) (string, int, error) {
//...
}
func (d *DockerClient) StopContainer(ctx context.Context, containerId string) error {
//...
}
This has made it easy to test the components of my code that need to interface with Docker because I can generate a mock for my Dockerer interface and dependency inject that mock.
However, now I'd like to write tests for the actual implementation of the DockerClient wrapper. It seems like no mocks are provided for ApiClient by the docker package. Is there a canonical pattern for writing tests when the package I need to use doesn't provide mocks? Is there a way to get mockery to generate mocks for library interfaces?