草庐IT

redis-test

全部标签

testing - Go gRPC 服务器使集成测试失败

我最近又开始玩go,我现在的任务是实现一个服务(将运行在k8s上),它应该充当gRPC服务器。根据要求,目前,为了满足k8s上的readinessProbe,我需要为我的服务实现一个健康检查端点,并且应该对其进行测试:我所做的是:funcmain(){server:=startHTTPServer()deferserver.Close()c:=make(chanos.Signal,1)signal.Notify(c,os.Interrupt,syscall.SIGTERM,syscall.SIGINT)我按照thisarticle这样测试的:funcTestMain(m*testing

unit-testing - 数据库连接get的单元测试策略

被测代码中有一个方法,它只是尝试获取数据库连接,如果无法连接则返回错误。它,以及涉及的结构体定义如下:typeDatabaseContextstruct{ContextDatabaseDatabaseSt}////GetInfoReturnsthecontext.//func(c*DatabaseContext)GetInfo()*Context{//return&c.Context//}//GetDBGetsthedatabaseconnectionfromtheconnectionstring.func(c*DatabaseContext)GetDB()(*sql.DB,*erro

unit-testing - 获取数据库连接的连接字符串

我正在尝试测试这个功能://OpenConnectionopensaconnectiontoaMySQLdatabaseby`connStr`//orreturnserror.If`connStr`isempty,errorisreturned.////Parameters://-`connStr`:theURLofthedatabasetoconnectto//-`interpolateParams`:shouldweinterpolateparameters?////Returns://-pointertothedatabaseconnection//-anyerrorsthath

unit-testing - 在辅助函数中包装 httptest 方法

在我的处理程序测试中,我多次使用header中带有身份验证token的测试请求服务模式。为了对此进行抽象,并为自己节省大量行数,我编写了以下函数:funcserveTestReq(payloadstring,routestring,methodstring,handlerfuncfunc(whttp.ResponseWriter,r*http.Request),tokenstring){body:=strings.NewReader(payload)req,err:=http.NewRequest(method,route,body)Expect(err).NotTo(HaveOccu

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

Redis数据结构之——hash

写在前面以下内容是基于Redis6.2.6版本整理总结一、Redis数据结构hash的编码格式Redis中hash数据类型使用了两种编码格式:ziplist(压缩列表)、hashtable(哈希表)在redis.conf配置文件中,有以下两个参数,意思为:当节点数量小于512并且字符串的长度小于等于64时,会使用ziplist编码。hash-max-ziplist-entries512hash-max-ziplist-value64二、压缩链表(ziplist)ziplist我们整理在下一篇文章。三、哈希表(hashtable)Redis中的字典(dict)使用哈希表作为的底层实现,一个哈希表

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.