草庐IT

out_unit

全部标签

elasticsearch - go + elastigo panic : runtime error: index out of range

我正在用elasticsearch测试golang我正在使用图书馆:https://github.com/mattbaird/elastigo我的问题是当我运行时:gorunelastigo_postal_code2.go编译器显示如下:panic:runtimeerror:indexoutofrangegoroutine1[running]:panic(0x893ce0,0xc82000a150)/opt/go/src/runtime/panic.go:464+0x3ffmain.main()/home/hector/go/elastigo_postal_code2.go:80+0x

json - Golang map : How to strip out empty fields automatically

给定以下结构...packagemodelsimport("time""gopkg.in/mgo.v2/bson""github.com/fatih/structs")typeUserstruct{Idbson.ObjectId`json:"id,omitempty"bson:"_id,omitempty"`Namestring`json:"name,omitempty"bson:"name,omitempty"`BirthDatetime.Time`json:"birth_date,omitempty"bson:"birth_date,omitempty"`}...我通过像这样解析H

unit-testing - 如何在 Go 中将测试标记为不确定?

这个问题在这里已经有了答案:HowToWritePendingTestsInGo(1个回答)关闭6年前。在Go中编写测试时,如何将测试标记为不确定,即存在,但既不成功也不失败,例如因为它还没有实现?我有Node.js背景,例如在Mocha(Node.js的测试运行器)中,您可以定义一个没有实现的测试,然后Mocha将此测试标记为pending。你如何用Go做到这一点?(如果有任何区别,我在gotest之上使用gocheck。)

unit-testing - 使用 Gorilla MUX 对 App Engine 进行单元测试

我想为GoogleAppEngine中的处理程序编写测试,这些处理程序使用Gorillamux从请求URL读取变量。我从documentation了解到您可以创建一个虚假的上下文并请求用于测试。我在测试中直接调用处理程序,但处理程序没有按预期看到路径参数。funcTestRouter(t*testing.T){inst,_:=aetest.NewInstance(nil)//ignoringerrorforbrevitydeferinst.Close()//triedaddingthislinebecausethetestwouldnotworkwithorwithoutithttpt

unit-testing - 在 GoLang 的 sqlmock 中出错

我正在为GoLang应用程序编写测试用例,我正在使用sqlmock模拟SQL查询,但在执行gotest时出现以下错误Params:[调用查询,不是预期的,下一个预期是:ExpectedBegin=>expectingdatabasetransactionBegin]对此有什么想法吗? 最佳答案 sqlmock期望有一个开始,但却得到了其他东西。在此处显示功能并进行测试以获取更多信息。 关于unit-testing-在GoLang的sqlmock中出错,我们在StackOverflow上找

unit-testing - 在 go api 调用中测试

我想为我的api编写测试用例,例如:数据库查询失败、代码错误、响应错误等。所以我在Controller文件夹中创建了一个名为controller_test.go的文件。这是我的代码:packagecontrollersimport("net/http""testing""net/http/httptest")func(imcImessageSoundController)TestHealthCheckHandler(t*testing.T){req,err:=http.NewRequest("GET","sound/imessage_sound",nil)iferr!=nil{t.Fa

unit-testing - 如何在向 API 发送 http 请求时进行模拟

我已经使用go-gin在Go中实现了一个ReSTAPI,我正在尝试测试一个如下所示的处理函数funceditNameHandler(c*gin.Context){//makeaReSTcalltoanotherservercallToAnotherServer()c.Status(200)}我想模拟callToAnotherServer方法,以便我的测试用例根本不调用第3方服务器。我的测试用例看起来像funcTestSeriveIdStatusRestorePatch(t*testing.T){//Requestbodysend:=strings.NewReader(`{"name":

unit-testing - 我如何对文本将出现在屏幕中央进行单元测试?

这是一个小脚本。packagebashutilimport("fmt""github.com/nsf/termbox-go")funcCenter(sstring){iferr:=termbox.Init();err!=nil{panic(err)}w,_:=termbox.Size()termbox.Close()fmt.Printf(fmt.Sprintf("%%-%ds",w/2),fmt.Sprintf(fmt.Sprintf("%%%ds",w/2+len(s)/2),s),)}我可以对其进行单元测试吗?我怎样才能测试它?我认为测试一个片段这么少是胡说八道。但是,...如果我

postgresql - getsockopt : connection timed out

我将我的项目从pythontornado重写为go(使用iris框架)。基本功能测试正常。我在高并发下测试的时候,app总是停一会,然后报错:(dialtcp192.168.1.229:6543:getsockopt:connectiontimedout)6543端口是与pgbouncer一起使用的postgresql端口...pgbouncer和postgresl进程运行正常。另外,我发现memcache连接有时会超时(memcache进程还在工作)。这是否因为连接太多而发生?或者有些连接不是准时关门?我怎样才能避免这个问题? 最佳答案

unit-testing - 如何在 Golang 中正确模拟具有成员函数的结构?

我有两个结构:FunctionalityClient和TestClient,它们都实现了Interface。我有一个Interface类型的全局变量Client。我将实际客户端或模拟客户端分配给Client,具体取决于它是测试还是正常运行。Interface有一个方法Request我想在测试中模拟它。也就是说,我想:记录传递给函数的参数是什么从函数返回一些任意定义的返回值所以结构看起来像这样:typeTestClientstruct{recordedArgs[]interface{}returnValues[]interface{}}func(c*TestClient)Request(