I'm using the Docker API and pass the Client
to a function like this:
func DoStuffToDocker(ctx context.Context, c *client.Client, ID string) {
c.ContainerInspect(ctx, ID)
// do stuff
}
I create an interface that defines the functions I use so that I can pass a mock in my tests:
type dockerClient interface {
ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
}
... and then change the signature of my function to accept the interface instead of the client.
My problem is that the compiler complains that the client doesn't implement the interface. From what I can tell the reason is that the implementation of ContainerInspect
uses the golang.org/x/net/context
context which the API has vendored (so the import is actually github.com/docker/docker/vendor/golang.org/x/net/context
).
How can I create the interface so that the client implements it?