草庐IT

test-network

全部标签

unit-testing - Golang 接口(interface)和模拟

由于外部库不公开接口(interface)(因此不可模拟)而只公开纯函数,因此我很难用Go编写单元测试。甚至像Googledon't这样的大公司,所以我想知道我的方法是否足够好。库提供interface而不是只有功能的包以便让用户模拟它们不是很好的做法吗?到目前为止,我提出的解决方案是用接口(interface)的实现来包装这些包,但这看起来工作量太大。我举个例子。我的函数看起来像这样funcAnyFunction()error{sess:=session.Get("blabla")//logicinhere...}其中session是一个导入的包,它返回一个struct。我无法模拟包

testing - 如何在 Go 中使用 gomock 模拟函数?

我是Go的新手,正在做一些简单的小项目+养成测试习惯来学习......但是我在使用mock设置测试时遇到了问题。具体在设置模拟对象sample/sample.gopackagesampleimport("fmt""net/http")funcGetResponse(path,employeeIDstring)string{url:=fmt.Sprintf("http://example.com/%s/%s",path,employeeID)//madesomerequesthere//thenconvertresp.Bodytostringandsaveittovaluereturnv

testing - 如何在 Go 中使用 gomock 模拟函数?

我是Go的新手,正在做一些简单的小项目+养成测试习惯来学习......但是我在使用mock设置测试时遇到了问题。具体在设置模拟对象sample/sample.gopackagesampleimport("fmt""net/http")funcGetResponse(path,employeeIDstring)string{url:=fmt.Sprintf("http://example.com/%s/%s",path,employeeID)//madesomerequesthere//thenconvertresp.Bodytostringandsaveittovaluereturnv

networking - 我可以编写 go 库以供其他语言使用吗?

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭8年前。Improvethisquestion我正在编写相对较小但不简单的网络库,它至少会在C、java、python、ruby和C#中使用。有没有一种方法可以像C中那样将go绑定(bind)到其他语言?如果没有还有其他办法吗?

networking - 我可以编写 go 库以供其他语言使用吗?

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭8年前。Improvethisquestion我正在编写相对较小但不简单的网络库,它至少会在C、java、python、ruby和C#中使用。有没有一种方法可以像C中那样将go绑定(bind)到其他语言?如果没有还有其他办法吗?

unit-testing - 如何使用 Go 为 App Engine 指定模板路径以进行单元测试?

我在AppEngine上使用带有Go的内置模板包。我有一个处理程序可以将模板呈现给输出。templates:=[]string{"templates/head.html","templates/footer.html"}funcpageIndex(whttp.ResponseWriter,r*http.Request){tpls:=append([]string{"templates/index.html"},templates...)tpl:=template.Must(template.ParseFiles(tpls...))err:=tpl.ExecuteTemplate(w,"

unit-testing - 如何使用 Go 为 App Engine 指定模板路径以进行单元测试?

我在AppEngine上使用带有Go的内置模板包。我有一个处理程序可以将模板呈现给输出。templates:=[]string{"templates/head.html","templates/footer.html"}funcpageIndex(whttp.ResponseWriter,r*http.Request){tpls:=append([]string{"templates/index.html"},templates...)tpl:=template.Must(template.ParseFiles(tpls...))err:=tpl.ExecuteTemplate(w,"

networking - golang中获取SSID/其他网络信息

如何在golang中获取SSID等网络信息?例如我当前连接的网络。 最佳答案 似乎没有本地Go命令可以执行此操作。您可以改为从您的Go代码中执行系统特定的工具并检查它们的输出。例子是https://github.com/yelinaung/wifi-name(Linux和OSX)或Listofavailablewirelessnetworkswithgolang(underLinux)或https://github.com/skycoin/skycoin/tree/master/src/aether/wifi(Linux)这对于Ja

networking - golang中获取SSID/其他网络信息

如何在golang中获取SSID等网络信息?例如我当前连接的网络。 最佳答案 似乎没有本地Go命令可以执行此操作。您可以改为从您的Go代码中执行系统特定的工具并检查它们的输出。例子是https://github.com/yelinaung/wifi-name(Linux和OSX)或Listofavailablewirelessnetworkswithgolang(underLinux)或https://github.com/skycoin/skycoin/tree/master/src/aether/wifi(Linux)这对于Ja

networking - UDPConn Close 到底做了什么?

如果UDP是无连接协议(protocol),那么为什么UDPConn有一个Close方法?文档说“关闭关闭连接”,但UDP是无连接的。在UDPConn对象上调用Close是一种好习惯吗?有什么好处吗?http://golang.org/pkg/net/#UDPConn.Close 最佳答案 好问题,看udpconn.Close的代码http://golang.org/src/pkg/net/net.go?s=3725:3753#L124func(c*conn)Close()error{if!c.ok(){returnsyscall.