草庐IT

user_passes_test

全部标签

go - 构建时在 golang 中找不到包 "github.com/user../../"

我正在尝试从github源代码构建一个项目。我发现一些源代码导入了如下所示的包:import("os""github.com/bivas/rivi/commands""github.com/mitchellh/cli")但是在构建项目时每次都会报错:user-MacBook-Pro:riviuser$gobuildrivi.gorivi.go:6:2:cannotfindpackage"github.com/bivas/rivi/commands"inanyof:/usr/local/Cellar/go/1.7.5/libexec/src/github.com/bivas/rivi/c

testing - 我应该使用哪种方法来测试 golang 中的 func main()?

我在main.go中有一个函数main()可以完成这项工作,所有其他函数都在它下面(我没有在这里包括它们)。因此,当我为main中包含的所有funcs编写测试时,我可以测试它们。但是代码覆盖率很低,因为它表明我没有覆盖main函数中的代码。我知道测试库中有一个TestMain函数可以完成这项工作,但我就是不知道如何让它工作,以便测试涵盖funcmain()。下面是我的main()函数,它没有被测试覆盖...funcmain(){c,err:=getConfig()iferr!=nil{log.Fatal(err)}slideshows,err:=getSlideshows(c)ifer

unit-testing - 如何为一小时后函数返回时间编写单元测试

我有以下函数,它在当前时间添加给定的小时数并在中返回新时间funcgetExpiryTime(hourint)*string{constlayout="2006-01-02T15:04:05Z"expiryTime:=time.Now().Local().Add(time.Hour*time.Duration(hour))returnaws.String(expiryTime.Format(layout))}为此功能编写单元测试的最佳方法是什么? 最佳答案 您可以尝试模拟时间提供程序并在您的模拟中设置time.Now()函数以返回您

unit-testing - 去单元测试无法加载文件

1、gotestconfig_test.go,总是文件,error:openconf/config.yml:Thesystemcannotfindthepathspecified2、源码ok3、gotestfile如何在不同目录下成功 最佳答案 测试期间您的工作目录不同。您可能需要动态计算配置目录路径的解决方法,例如:http://www.kaihag.com/external-assets-working-directories-and-go/ 关于unit-testing-去单元测试

unit-testing - 错误 : suite. go:61: test paniced: reflect: Call with too few input arguments

我正在golang中设置单元测试。但是现在我在运行gotest-v时遇到错误。我想解决这个错误并使测试成功。article├client├api│├main.go│├contoroller││├contoroller.go││└contoroller_test.go│├service││├service.go││└service_test.go│├dao││├dao.go││└dao_test.go│├s3││├s3.go││└s3_test.go│├go.mod│├go.sum│└Dockerfile├nginx└docker-compose.yml现在我正在为service.go设

Golang 项目 Travis CI Build 失败,错误为 `Makefile:15: recipe for target ' test' failed`

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。这个问题似乎与helpcenter中定义的范围内的编程无关。.关闭3年前。Improvethisquestion我已经为我的Github项目设置了travisbuildCaptain.travis.yml的内容是:language:gogo:-1.12.xscript:makeenv:-GO111MODULE=onGOPROXY=https://proxy.golang.org我的Makefile的内容是:#GoparametersBINARY_FOLDER=./binGOCMD=goGOBUILD=

unit-testing - 如何比较两个作为结构但作为接口(interface)返回的值

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭3年前。Improvethisquestion我真的是Go编程的新手,被困在这里。我有一个函数A,它从3个不同的值a、b、c创建一个结构。funcA()interface{}{s:=new(struct{a,b,cint})//fillthevaluesinsreturns}现在当我测试这个函数时,我如何将返回的接口(interface)与一些

user-interface - 从一组代码同时打开 2 个相同的窗口

我正在使用以下代码创建并显示一个窗口,其中包含GUI组件作为标签、条目和按钮://modifiedfrom:https://github.com/andlabs/ui/wiki/Getting-Startedpackagemainimport("github.com/andlabs/ui")funcmakewinfn(){varname=ui.NewEntry()varbutton=ui.NewButton("Greet")vargreeting=ui.NewLabel("")box:=ui.NewVerticalBox()box.Append(ui.NewLabel("Enteryo

unit-testing - 如何断言 Go 测试中的错误类型?

我有一个如下定义的错误类型typeRetryableErrorstruct{msgstring}func(a*RetryableError)Error()string{returna.msg}在单元测试中,如果返回的错误是RetryableError类型,Go的断言方式是什么? 最佳答案 使用类型断言:err:=someFunc()ifretryable,ok:=err.(RetryableError);ok{//useretryable}您的RetryableError不是错误,但*RetryableError是。更正:func(

unit-testing - httptest.NewRequest 与 http.NewRequest : which one to use in tests and why?

Golang有这两个相似的库http和httptest并且它们都有NewRequest函数。如果http.NewRequest能做到这一切,为什么我们还需要httptest.NewRequest?如果我需要为我的测试创建多部分/多形式请求,我需要使用哪一个? 最佳答案 如文档中所示,httptest.NewRequest“返回一个新的传入服务器请求,适合传递给http.Handler进行测试”,而http.NewRequest“返回适合与Client.Do或Transport.RoundTrip一起使用的请求。”因此,如果您在单元测