如何在单元测试 Golang 中模拟 netconf 会话

如何在单元测试 golang 中模拟 netconf 会话

问题内容

我正在使用 juniper 的 netconf 包(“github.com/juniper/go-netconf/netconf”)在我的代码中建立 netconf 会话。

我想知道如何在单元测试中模拟 netconf 会话。

我的方法是:

func testmyfunction(t *testing.t) { getsshconnection = mockgetsshconnection got := myfunction() want := 123 if !reflect.deepequal(got, want) { t.errorf("error expectation not met, want %v, got %v", want, got) } }登录后复制