草庐IT

run_test

全部标签

go - 卡夫卡 : client has run out of available brokers

更新:原来我在Docker中的端口有问题。不确定为什么会解决此现象。我相信我遇到了一个奇怪的错误。我正在使用Sarama库并能够成功创建消费者。funcmain(){config=sarama.NewConfig()config.ClientID="go-kafka-consumer"config.Consumer.Return.Errors=true//Createnewconsumermaster,err:=sarama.NewConsumer("localhost:9092",config)iferr!=nil{panic(err)}deferfunc(){iferr:=mast

unit-testing - 如何在go中测试数据库错误?

我在go中实现了一个由leveldb(https://github.com/syndtr/goleveldb)支持的存储器。我是新来的,我想弄清楚我如何获得下面代码中perr!=nil条件的测试覆盖率。我可以测试自己的错误,但我不知道如何可靠地让leveldb的Put方法返回错误。模拟一个数据库只是为了获得一些边缘案例的测试覆盖率,这似乎是一项没有多少返回的大量工作。mockleveldb是我唯一真正的选择吗?如果是的话,推荐的go模拟框架是什么?如果还有另一种方式,它是什么?iferr==leveldb.ErrNotFound{store.Lock()perr:=store.ldb.

testing - 为不同包上的所有测试运行单个 Golang httptest 服务器

我的项目文件夹是这样的。它是一个大型API,我仅将文件分开用于组织用途。$treesrc/后端/src/backend/├──cats│  ├──cat_test.go│  ├──handler.go│  ├──routes.go│  └──tools.go├──cmd│  ├──populate.go│  ├──root.go│  └──runserver.go├──iot│  └──device│    ├──all.go│    ├──all_test.go│    ├──router.go│    ├──types.go│    └──update.go├──main.go├─

docker - 什么是 docker run -it 标志?

我正在用docker做一些复杂的事情,但结果我不知道-it标志是什么意思。最近我遇到了一些dockerrun命令的例子,这让我有点困惑。dockerrun-itdubuntu:xenial/bin/bash我的问题是,如果容器在实例化期间运行bin/bash,那么在这里写-it标志有什么意义在文档中我们有一个例子dockerrun--nametest-itdebian有解释The-itinstructsDockertoallocateapseudo-TTYconnectedtothecontainer’sstdin;creatinganinteractivebashshellinthe

docker - 什么是 docker run -it 标志?

我正在用docker做一些复杂的事情,但结果我不知道-it标志是什么意思。最近我遇到了一些dockerrun命令的例子,这让我有点困惑。dockerrun-itdubuntu:xenial/bin/bash我的问题是,如果容器在实例化期间运行bin/bash,那么在这里写-it标志有什么意义在文档中我们有一个例子dockerrun--nametest-itdebian有解释The-itinstructsDockertoallocateapseudo-TTYconnectedtothecontainer’sstdin;creatinganinteractivebashshellinthe

testing - 如何在 Golang 中解码 reflect.Value

我得到了这个测试func(t*DeviceTests)CreatePublicDevice(){registerRegularDevice:=tester.TableTest{Method:"POST",Path:"/iot/devices",Status:http.StatusOK,Name:"CreatePublicDevice",Description:"registerRegularDevicehastoreturn200",Body:PublicDevice,}resp:=registerRegularDevice.DoubleSpin(t.Test)log.Println(

testing - 旨在使用 Docker 的客户端 API 测试方法的接口(interface)上出现错误类型错误

我正在重构我编写的程序,以便我可以正确地为它编写测试。我想测试的第一个方法是使用Docker'sclientAPI的方法。查看某个镜像是否存在于Docker主机上。为了能够测试此方法,我创建了一个与client.ImageList的signature匹配的接口(interface):typeImageListerinterface{ImageList(ctxcontext.Context,optionstypes.ImageListOptions)([]types.ImageSummary,error)}我还更改了测试方法以将ImageLister作为参数,这样我就可以传入特定于我的测

testing - Gogland 测试配置始终使用 ./执行

无论我如何设置我的构建配置来运行我的测试,go测试工具总是以./...运行例如运行:gotest-v-cover./...-run./svs 最佳答案 根据您需要运行的内容,您可以选择不同的配置类型。对于图片中的那个,选择了RunKindDirectory,这意味着IDE将在您指向的目录中运行测试,并且由于工作目录位于同一目录中,它将运行./...这就是它的意思。对于RunKindPackage,它将只运行指定的包而不会运行其他包,因此没有/...附加到它。对于运行类型文件,它将在单个文件中运行测试。您添加的模式./svc告诉go工

testing - 测试中的标志导致其他测试无法运行

我有一个测试文件,我只想在设置位标志时运行。我遵循了golang'stestingdocs中的简单示例:packagemypkgvarmyFlagSet=flag.Bool("myflag",false,"")funcTestMain(m*testing.M){flag.Parse()if*myFlagSet{os.Exit(m.Run())}}如果我运行gotest./mypkg-myflag它会按预期运行。但是,当我运行gotest./...-myflag时,所有其他包测试都失败了:flagprovidedbutnotdefined:-myflag我希望能够运行所有测试,而不必担心

unit-testing - 测试在 Golang 中加载 JSON 配置文件的方法

在Golang在测试项目中,有一种方法可以将JSON配置文件加载到变量中。它的代码是这样的://LoadtheJSONconfigfilefuncLoad(configFilestring,outputObjinterface{})*errors.ErrorSt{varerrerror//ReadtheconfigfilejsonBytes,err:=ioutil.ReadFile(configFile)iferr!=nil{fmt.Println(err.Error())returnerrors.File().AddDetails(err.Error())}//Parsethecon