配置
- go1.15.2 达尔文/amd64
- macOS Catalina v10.15.7
.zshrc
文件
export GOPATH=$HOME/go
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
我正在尝试做的事情
我是 Go 新手,正在尝试使用 Terratest 为 Packer 构建编写测试。
尝试运行时,go test my_test.go
我不断收到错误消息,提示我需要安装丢失的软件包。
../../../../../go/src/github.com/gruntwork-io/terratest/modules/aws/sqs.go:10:2:找不到包“github.com/google /uuid”在以下任何一个中:
/usr/local/opt/go/libexec/src/github.com/google/uuid(来自 $GOROOT)/Users/username/go/src/github.com/google/uuid(来自$GOPATH)。
FAIL 命令行参数 [设置失败]
FAIL
谷歌搜索我发现go get -u ./...
从我的测试文件所在的目录运行应该安装这些包
问题
当我运行时,go get -u ./...
我收到以下错误:
包_/Users/username/github.com/my-org/my-repo/packer/tests:无法识别的导入路径“_/Users/username/github.com/my-org/my-repo/packer/tests”:导入路径不以主机名开头
对于其他上下文,这是我正在使用的目录结构:
~
github.com/my-org/my-repo/
packer/
tests/
my_test.go
这是我使用这个 terratest 示例作为参考创建的测试文件:
package test
import (
"testing"
"github.com/gruntwork-io/terratest/modules/packer"
"github.com/stretchr/testify/assert"
terratest_aws "github.com/gruntwork-io/terratest/modules/aws"
)
func TestMyAmiBuild( t *testing.T) {
awsRegion := "us-east-1"
packerOptions := &packer.Options{
// Path to the Packer template under test
Template: "../template/template.json",
// Variables to pass to Packer build
Vars: map[string]string{
"ami_name": "my-ami"
},
// Only build the AWS AMI
Only: "amazon-ebs",
}
// Build the Packer template
amiID := packer.BuildArtifact(t, packerOptions)
// Clean up the AMI after we're done
defer terratest_aws.DeleteAmiAndAllSnapshots(t, awsRegion, amiID)
// Check if AMI is private
amiIsPublic := terratest_aws.GetAmiPubliclyAccessible(t, awsRegion, amiID)
assert.False(t, amiIsPublic)
}