Terratest是一个用于功能重用的实用程序包。

huangapple go评论67阅读模式
英文:

Terratest utility pkg for func reuse

问题

伙计们,有没有可能在terratest测试包中创建一个utils.go,以便在所有_test.go文件中使用执行某些常见验证例程的函数。

我尝试创建utils/utils.go,并在_test.go文件中导入为"../tests/utils"。这样可以像go test sample_test.go -vgo test another_sample_test.go -v这样运行单个测试,并且可以正常工作。

但是当我尝试go test -v时,它会报错无法引用本地包。

我只是一个terratest和go语言的初学者。非常感谢任何帮助。谢谢。

英文:

Folks is there a possibility to create utils.go amongst *_test.go in the terratest test package to utilize a func that performs certain common validation routines across all _test.go.

I tried creating utils/utils.go and within the *_test.go imported as "../tests/utils". This way able to run individual test like go test sample_test.go -v or go test another_sample_test.go -v and it yields.

But when I try go test -v it complains cannot reference a local package.

Am just a beginner to terratest and go lang in general. Any leads is greatly appreciated. Thanks.

答案1

得分: 0

Go包通常必须使用完全限定路径进行导入。在您的项目中,包的完全限定路径取决于您在go.mod文件中声明的module路径。

如果您是Go的新手,How to Write Go Code 是一个很好的起点。

英文:

Go packages must in general be imported by fully-qualified paths. The fully-qualified path for a package within your project depends on what module path you declare in your go.mod file.

If you're new to Go, How to Write Go Code is a good place to start.

huangapple
  • 本文由 发表于 2021年9月23日 05:12:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/69291333.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定