drevls8138 2018-06-30 21:21
浏览 16

模拟带有供应商进口的界面

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)