diff --git a/helper/tests/core.go b/helper/tests/core.go index 91ccef4de..f48d92a75 100644 --- a/helper/tests/core.go +++ b/helper/tests/core.go @@ -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 + } +} diff --git a/provisioner/shell/provisioner_acc_test.go b/provisioner/shell/provisioner_acc_test.go index ee25a7a67..889eaa56f 100644 --- a/provisioner/shell/provisioner_acc_test.go +++ b/provisioner/shell/provisioner_acc_test.go @@ -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{ diff --git a/provisioner/shell/test-fixtures/shell-provisioner.json b/provisioner/shell/test-fixtures/shell-provisioner.json index df3604670..63ef3b0bb 100644 --- a/provisioner/shell/test-fixtures/shell-provisioner.json +++ b/provisioner/shell/test-fixtures/shell-provisioner.json @@ -7,6 +7,7 @@ "region": "us-east-1", "ssh_username": "ubuntu", "source_ami": "ami-0568456c", + "force_deregister" : true, "tags": { "packer-test": "true" }