英文:
Terratest utility pkg for func reuse
问题
伙计们,有没有可能在terratest测试包中创建一个utils.go,以便在所有_test.go文件中使用执行某些常见验证例程的函数。
我尝试创建utils/utils.go
,并在_test.go文件中导入为"../tests/utils"
。这样可以像go test sample_test.go -v
或go 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论