Add acc test validation to avoid running with unit tests

This commit is contained in:
Moss 2020-03-13 17:50:05 +01:00
parent 3f49b7c66e
commit 5a8c628880
3 changed files with 23 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package testshelper
import (
"bytes"
"fmt"
"os"
"testing"
@ -65,3 +66,22 @@ func FatalCommand(t *testing.T, m command.Meta) {
out.String(),
err.String())
}
const TestEnvVar = "PACKER_ACC"
func AccTestPreValidate(t *testing.T) {
// We only run acceptance tests if an env var is set because they're
// slow and generally require some outside configuration.
if os.Getenv(TestEnvVar) == "" {
t.Skip(fmt.Sprintf(
"Acceptance tests skipped unless env '%s' set",
TestEnvVar))
return
}
// We require verbose mode so that the user knows what is going on.
if !testing.Verbose() {
t.Fatal("Acceptance tests must be run with the -v flag on tests")
return
}
}

View File

@ -11,6 +11,8 @@ import (
)
func TestBuildShellProvisionerWithBuildVariablesSharing(t *testing.T) {
testshelper.AccTestPreValidate(t)
UUID, _ := uuid.GenerateUUID()
os.Setenv("PACKER_RUN_UUID", UUID)
c := &command.BuildCommand{

View File

@ -7,6 +7,7 @@
"region": "us-east-1",
"ssh_username": "ubuntu",
"source_ami": "ami-0568456c",
"force_deregister" : true,
"tags": {
"packer-test": "true"
}