草庐IT

gcloud-sql-test

全部标签

go - golang gorm lib执行sql文件的最佳解决方案

也许有人有更简单的代码来通过gormlib执行sql文件?//CARRIERSIMPORTerr:=DB.Session.Model(model.Carriers{}).Count(&carriers).Erroriferr!=nil{panic(err)}elseifcarriers==0{path,err:=filepath.Abs("./dumps/carriers.sql")iferr!=nil{panic(err)}file,err:=ioutil.ReadFile(path)iferr!=nil{panic(err)}DB.Session.Model(model.Carri

go - 调用通过 interface{} 传入的 sql.NullFloat64 上的方法抛出错误

我有一个看起来像这样的简单函数:funcconvertToRealNum(numberinterface{})interface{}{switchv:=number.(type){default:log.Fatal("unexpectedtype%T",v)casesql.NullFloat64:newNumber:=number.Float64casesql.NullInt64:newNumber:=number.Int64}returnnewNumber}number是NullFloat64或NullInt64。如果number是NullFloat64类型,我对其调用number.

go test 错过了执行路径上的覆盖

考虑这样的文件结构:api--|_routes.go|_handler.goimpl--|_impl.go|_impl_test.go“impl”文件包含RESTAPI的内部实现,其处理程序和路由分别位于“handler.go”和“route.go”文件中。就打包而言,“api”文件夹下的所有内容都在“api”包中。“impl.go”中的代码在“impl”包中,“impl_test”包中的代码在“impl_test”包中。api-------|_routes|_handlerfunctionsimpl-------|_implfunctionsimpl_test--|_testfunc

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

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

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

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我该如何解决这个问题?谢谢。

sql - 如何将 "and"运算符用于列表的所有元素?

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭4年前。Improvethisquestion我有不同标签的书(犯罪、奇幻、戏剧等)。那是我的sql代码:query:=`SELECTgotoboox.books.id,gotoboox.books.titleFROMgotoboox.booksLEFTJOINgotoboox.books_tags

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