小编Win*_*ito的帖子

如何模拟 net.Interface

我正在尝试在 Go 中模拟 net.Interface,我使用 net.Interfaces() 并且我想要一个固定的回报。但 net.Interface 不是一个接口,所以我不能用 gomock 来模拟它。

\n

也许我的测试方式是错误的。

\n

这是我要测试的方法:

\n
const InterfaceWlan = "wlan0"\nconst InterfaceEthernet = "eth0"\n\nvar netInterfaces = net.Interfaces\n\nfunc GetIpAddress() (net.IP, error) {\n    // On r\xc3\xa9cup\xc3\xa8re la liste des interfaces\n    ifaces, err := netInterfaces()\n    if err != nil {\n        return nil, err\n    }\n\n    // On parcours la liste des interfaces\n    for _, i := range ifaces {\n        // Seul l\'interface Wlan0 ou Eth0 nous int\xc3\xa9resse\n        if i.Name == InterfaceWlan || i.Name == InterfaceEthernet {\n …
Run Code Online (Sandbox Code Playgroud)

interface mocking go gomock

1
推荐指数
1
解决办法
1700
查看次数

标签 统计

go ×1

gomock ×1

interface ×1

mocking ×1