Configuration
- go1.15.2 darwin/amd64
- macOS Catalina v10.15.7
.zshrc
file
export GOPATH=$HOME/go
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
What I'm trying to do
I'm new to Go, and trying to use Terratest to write a test for a Packer build.
When trying to run go test my_test.go
I keep getting errors saying I need to install missing packages.
../../../../../go/src/github.com/gruntwork-io/terratest/modules/aws/sqs.go:10:2: cannot find package "github.com/google/uuid" in any of:
/usr/local/opt/go/libexec/src/github.com/google/uuid (from $GOROOT) /Users/username/go/src/github.com/google/uuid (from $GOPATH).
FAIL command-line-arguments [setup failed]
FAIL
Googling around I found that running go get -u ./...
from the directory where my test file is should install these packages
Problem
When I run go get -u ./...
I get the following error:
package _/Users/username/github.com/my-org/my-repo/packer/tests: unrecognized import path "_/Users/username/github.com/my-org/my-repo/packer/tests": import path does not begin with hostname
For additional context, this is the directory structure I'm using:
~
github.com/my-org/my-repo/
packer/
tests/
my_test.go
And here is the test file, which I've created using this terratest example as a reference:
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)
}