首页 > 解决方案 > Go get all dependencies 返回 Terratest 无法识别的导入路径

问题描述

配置

.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)
}

标签: goterratest

解决方案


推荐阅读