草庐IT

integration-testing-mongodb-sprin

全部标签

unit-testing - 在 Golang 中测试接受不返回值的回调函数的方法

我正在尝试测试以下功能://SendRequestAsyncsendsrequestasynchronously,acceptscallback//func,whichitinvokes////Parameters://-`context`:somecontext//-`token`:sometoken//-`apiURL`:theURLtohit//-`callType`:thetypeofrequesttomake.Thisshouldbeoneof//theHTTPverbs(`"GET"`,`"POST"`,`"PUT"`,`"DELETE"`,...)//-`callBack

unit-testing - 如何编写When a function having the parameters of c *gin.Context 的测试用例

我正在用golang为我的项目编写Controller的测试用例。在Controller中有函数名称SaveProvider()有参数c*gin.Context我不知道如何将JSON传递给c*gin.Context这个参数以及我如何测试我在Controller中使用的函数谁能告诉我这段代码中的问题是什么。它也称为表驱动测试。packagecontrollersimport("bkapiv1/models""fmt""testing""github.com/gin-gonic/gin")funcTestSaveProvider(t*testing.T){typeargsstruct{c*

mongodb - 多条件获取 MongoDB 集合记录

我想获取具有多个条件的mongodb集合,但出现错误:panic:Failedtoparse:filter:[{visibility:{$eq:"4"}},{discontinued:{$ne:"1"}},{status:{$eq:"1"}}].'filter'fieldmustbeofBSONtypeObject.代码如下:packagemainimport("fmt""gopkg.in/mgo.v2/bson")funcGenerateFeed(headers,attributesinterface{},conditions[]interface{}){varoperations=

mongodb - 如何查找和比较官方 MongoDB Go 驱动程序上的日期?

我是mongodb-go-driver的新手,我被卡住了。我在结构中有一个日期,例如:typeEmailstruct{Datestring`json:"date"`}我的mongoDB上和映射到我的结构中的日期的值类似于“02/10/201811:55:20”。我想在我的数据库中找到日期在另一个日期之后的元素,我正在尝试这个,但响应始终为空。initDate,_:=time.Parse("02012006",initialDate)cursor,err:=emails.Find(context.Background(),bson.NewDocument(bson.EC.SubDocum

mongodb - 如何在 change stream watch api (mongo-go-driver) 中设置 batchSize?

我正在使用changestreamapt.BatchSize传递batchSize。但这不起作用发生此错误:BSONfield'$changeStream.batchSize'isanunknownfield示例API调用//collis*mongo.Collection//ctxiscontextcur,err:=coll.Watch(ctx,nil,changestreamopt.BatchSize(1000)) 最佳答案 这看起来像是当前mongo-go-driver(v0.0.16)中的错误,其中batchSize选项被传递

go - 用时间包的parse方法将mongodb字段值 "date"解析成golang

我已经created_date列作为字符串,它的值类似于2018-10-0415:42:19.000404667+0000UTCm=+103.387519062我从mongo得到的db列,现在我将其插入mysql表,当然是string类型。现在的问题是我无法解析它并格式化它,这里我尝试使用下面的代码来解析但无法得到解决方案。tm,err:=time.Parse("2006-02-01","2018-10-0415:42:19.000404667+0000UTCm=+103.387519062")iferr!=nil{fmt.Println(err)}它打印出一些错误,例如:parsin

mongodb - 将新的子文档附加到主结构中的数组

我的MongoDB数据库中有以下go结构:typeStationstruct{IDbson.ObjectId`bson:"_id"json:"id"`Namestring`bson:"name"json:"name"`Sensors[]Sensor`bson:"sensors"json:"sensors"`}typeSensorstruct{IDbson.ObjectId`bson:"_id"json:"id"`Typestring`bson:"type"json:"type"`Valuefloat64`bson:"value"json:"value"`}当我在端点localhost:

golang test spy 错误地比较相等性

我正在学习围棋并正在改编来自testdouble的Java生命游戏示例.然而,我编写的测试spy错误地比较了我的World结构的相等性——测试在它应该失败的时候通过了,因为output(world)没有被调用。我做错了什么?测试:packagegameoflifeimport("testing""github.com/google/go-cmp/cmp")funcTestZeroGenerations(t*testing.T){generatesSeedWorldStub:=GeneratesSeedWorldStub{}outputsWorldSpy:=OutputsWorldSpy

mongodb - 使用 Golang 将日期插入 Mongodb

我正在尝试创建一个GolangMongoDB连接器,它接收来自客户端的请求并将请求正文更新/插入到数据库中。请求正文的示例是:{"_id":{"$oid":},"DateCreated":{"$date":1460091636474},"DateModified":{"$date":1542241349721}}我目前使用的Mongo驱动程序和BSON库分别位于github.com/globalsign/mgo/和github.com/globalsign/mgo/bson。每当我尝试解码上述响应时,我都会收到一个错误:cannotparsedate:"{\r\n\"$date\":1

unit-testing - 如何在 Golang 中实现 stub ? stub 和模拟之间有什么区别?

关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭4年前。Improvethisquestion我在Golang的单元测试中使用模拟。但是在Golang的实现代码中如何区分stub和mock呢?