草庐IT

integration-testing-mongodb-sprin

全部标签

mongodb - 如何使用权重在 mgo 中定义 mongodb 文本索引

我正在尝试创建具有权重的文本索引,但我无法通过阅读API文档弄清楚如何做。如何在mgo中建立如下索引。db.products.createIndex({"primaryCategoryIndexes":"text","secondaryCategoryIndexes":"text","brandIndex":"text","primaryTitleIndexes":"text","secondaryTitleIndexes":"text","indexCycleId":"text"},{"weights":{"primaryCategoryIndexes":10,"secondaryC

testing - Golang 测试,相同的包,未定义的函数

我很新,正在尝试为go编写一个测试文件。当我运行测试时,我有两个问题:1.我必须运行“gotest-cover”,然后我才能看到这个:#command-line-arguments./client_test.go:59:undefined:InitFAILcommand-line-arguments[buildfailed]我的问题是为什么我不能只运行:去测试(如果我这样做,我会看到这个:exitstatus1FAILcommand-line-arguments0.008s我的第二个问题是包中有两个文件(一个大项目中的一个包),一个file1和一个file1的test.go文件。为什么

testing - 如何去测试多个包

在我的项目中,有数百个包。所以我跑的地方:$(foreachi,$(TEST_PKGS),gotest$(i)-test.short-v)大约需要一个小时。如果我运行:gotest$(TEST_PKGS),它将消耗大量内存。如何处理这个问题? 最佳答案 您可以使用./...测试当前目录和所有子目录中的所有包。来自文档:Tomakecommonpatternsmoreconvenient,therearetwospecialcases.First,/...attheendofthepatterncanmatchanemptystrin

unit-testing - 如何模拟getClient?

关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭4年前。Improvethisquestion我有一个功能:funcHTTPGet(urlstring)(*http.Response,error){resp,err:=getClient().Get(url)returnresp,err}getClient函数是:vardefaultClient*http.ClientfuncgetClient()*http.Client{ifdefaultClient==nil{defaultClient

MongoDB bson.M 查询

我正在尝试使用野牛查询MongoDB中带有两个字段的所有JSON数据,但结果为空。{"allowedList":[{"List":[{"allow":{"ss":1,},"Information":[{"Id":"Id1"}]}]}]}我能够在命令行使用MongoDB过滤所有内容db.slicedb.find({"allowedList.List.allow.ss":1,"allowedList.List.Information.nsiId":"Id-Id21"})butusingquery:=bson.M{"allowedList.List.allow":bson.M{"ss":ss

unit-testing - 在 Go 单元测试中使用两个不同的模拟

我正在学习使用gomock的mockgen实用程序第一次在Go中使用mock进行单元测试。我的单元测试工作正常,除了其中一个。被测方法有两个依赖项:一个依赖于数据库,另一个依赖于它调用restapi的外部服务。数据库的模拟(mockRepo)工作正常,因为被测方法正确调用模拟而不是实际的repo代码。然而,rest客户端的mock继续调用实际的rest客户端而不是mock代码。我不知道为什么。有人可以解释原因并帮助修复吗?这是我的单元测试:funcTestService_CreateWorkspace(t*testing.T){ts:=NewTestService(t)deferts.

mongodb - 如何使用 Golang 从 Mongo GridFS 下载文件?

我正在尝试编写一个具有基本文件上传、下载功能的RestAPI。我能够很好地完成上传部分,但我很难从gridfs下载文件。有什么建议吗? 最佳答案 更新:我想我知道怎么做了。我很好奇是否有人有任何其他建议:这是我现在的样子:funcDownloadRecord(whttp.ResponseWriter,filenamestring)error{if!fileExists(filename){returnerrors.New("Filedoesn'texist.Nothingtodownload")}session:=sqlconnec

go - vendor 问题 : found packages text (doc. 去)和转换(examples_test.go)在我的 vendor

这个问题在这里已经有了答案:Error"can'tloadpackage:packagemy_prog:foundpackagesmy_progandmain"(3个答案)关闭4年前。我遇到了一些问题:enterimagedescriptionhere..\vendor\github.com\spf13\afero\util.go:28:2:在D:\golang\src\services\vendor中找到包文本(doc.go)和转换(examples_test.go)\golang.org\x\text\transform我该如何解决这个问题?谢谢。

GoSonar : how to generate go test -json > report. json

如何生成gotest-json>report.jsonGo语言版本:Go1.10.3SonarQube属性:sonar.go.tests.reportPaths=report.json官方Sonar文档->https://docs.sonarqube.org/display/PLUG/Unit+Tests+Results+Import生成文件.PHONY:testtest:@$(foreachpackage,$(packages),\gotest-coverprofile$(package)/cover.out-covermode=count$(package);).PHONY:cov

unit-testing - 如何测试以确保函数被调用?

我想做单元测试。为了简单起见,我只想确保调用“JWTCheck”。我该怎么做?这是我实现JWTCheck的文件:typeJWTCheckerstruct{SubjectPrefixstring}func(j*JWTChecker)JWTCheck(nexthttp.Handler)http.Handler{//Dosomething}这是我实现路由器的地方:import("net/http""github.com/gorilla/mux")//Routerreturnsapreconfiguredrouterforapplicationfunc(a*Adapter)Router()ht