草庐IT

test_field

全部标签

unit-testing - 如何在 golang 中编写关于插入、获取、删除和更新数据的测试用例

我必须编写插入、获取、删除和更新数据的测试用例。在互联网上搜索时,我找到了一个代码并且它可以工作,但我不知道它是如何工作的。我的代码在下面给出,任何人都可以用简单的方式告诉我我将如何理解代码。packagemodelsimport("testing""gopkg.in/mgo.v2/bson""fmt")funcTestAddBlog(t*testing.T){typeargsstruct{queryinterface{}}tests:=[]struct{namestringargsargswantbool}{{"first",args{bson.M{"_id":4,"title":"

unit-testing - 在 Go-kit 中为 make 处理函数编写单元测试

我的问题特定于Go-kit以及如何在其中组织代码。我正在尝试为以下功能编写单元测试:funcMakeHandler(svcService,loggerkitlog.Logger)http.Handler{orderHandler:=kithttptransport.NewServer(makeOrderEndpoint(svc),decodeRequest,encodeResponse,)r:=mux.NewRouter()r.Handle("/api/v1/order/",orderHandler).Methods("GET")returnr编写适当的单元测试的正确方法是什么?我见过

unit-testing - 如何定义模拟方法被调用零次

我正在尝试测试以下方法://AuthenticationMiddlewareMiddlewarewhichhandlesalloftheauthentication.funcAuthenticationMiddleware(contextcontext.ContextIntf,wweb.ResponseWriter,r*web.Request,nextweb.NextMiddlewareFunc){//Checkifurlisonethatdoesn'tneedauthorization.Ifnotthansendthemtotheloginpage.for_,url:=rangeAu

unit-testing - 如何重写gocov命令去工具覆盖?

我有以下命令:${GOPATH}/bin/gocovtest./...2>test|${GOPATH}/bin/gocovreport如果我使用gotoolcover,这个命令会是什么样子? 最佳答案 自go1.10gotoolcoverage支持递归包绕过gotest./...-coverprofile=coverage.out 关于unit-testing-如何重写gocov命令去工具覆盖?,我们在StackOverflow上找到一个类似的问题: http

unit-testing - 以 http 作为包装函数的依赖项的单元测试

我有以下函数,在@poy的帮助下,我能够为它创建模拟以便对其进行单元测试。现在的问题是我有包装函数也需要测试这是原始函数,已经过测试funchttpReq(cc[]string,methodstring,urlstring)([]byte,error){httpClient:=http.Client{}req,err:=http.NewRequest(method,url,nil)iferr!=nil{returnnil,errors.Wrap(err,"failedtoexecutehttprequest")}//Herewearepassinguserandpasswordreq.

xml - 在 Golang 中编码 XML : field is empty (APPEND doesn't work? )

我正在学习用Go创建XML。这是我的代码:typeRequeststruct{XMLNamexml.Name`xml:"request"`Actionstring`xml:"action,attr"`...Point[]point`xml:"point,omitempty"`}typepointstruct{geostring`xml:"point"`radiusint`xml:"radius,attr"`}funcmain(){v:=&Request{Action:"get-objects"}v.Point=append(v.Point,point{geo:"55.703038,37

unit-testing - 如何在 ReverseProxy 中测试 header ?

我正在尝试对以下代码进行单元测试:func(h*Handler)Forward(whttp.ResponseWriter,r*http.Request){url,err:=url.Parse("http://test.com")iferr!=nil{return}reverseProxy:=&httputil.ReverseProxy{Director:func(r*http.Request){r.URL.Host=url.Hostr.URL.Path="/"r.URL.Scheme=url.Schemer.Host=url.Hostr.Header.Set("X-Forwarded-

go - 如何在运行 'go test' 时排除或跳过特定目录

这个问题在这里已经有了答案:Runningtestsandskippingsomepackages(1个回答)关闭3年前。gotest$(golist./...|grep-v/vendor/)-coverprofile.testCoverage.txt我正在使用上面的命令来测试文件,但是我想从测试中排除1个名为“Store”的文件夹。怎么做到的?

go - 如何通过struct field Name取值

typemcatstruct{IDint}typecatstruct{NamestringMmcat}funcgetValue(pathstring,mcatcat){//throuthstructpathgetthevalue}funcmain(){mycat:=cat{"cat",mcat{1}}id:=getvalue("/M/ID",mycat)}我可以通过反射获取基于字段名称的值来做到这一点吗? 最佳答案 你可以用Value.FieldByName()做你想做的事功能。只需覆盖可能使用strings.Split()分割的路

采空区 : type mismatch: no fields matched compiling decoder - Golang

我在两个不同的流上使用PubSub,我们从一个流接收消息,运行一些逻辑,如果它符合特定条件,我们将它发布到第二个流。第二个流也在goroutine中接收。现在,我有两个主要函数HandleMessage和HandleRetry,其中前者来自第一个流,第二个用于第二个流。HandleMessage的相关代码如下:ifc.handler.ShouldProcess(tx){err:=c.handler.Process(tx)iferr!=nil{c.log.WithError(err).WithField("tx_hash",tx.TxHash.String()).Error("faile