tests/provisioners: Add TestProvsionerPreCheck function
This function can be used to check if a Provisioner has been marked for testing within the ACC_TEST_PROVISIONERS environment variable. While testing I found that the shell acceptance test were also running when trying to run powershell tests. Before change ``` ⇶ ACC_TEST_BUILDERS=amazon-ebs ACC_TEST_PROVISIONERS=powershell go test -v ./provisioner/shell/... -timeout=1h === RUN TestShellProvisioner/testing_amazon-ebs_builder_against_shell_provisioner 2020/04/06 15:18:12 ui: amazon-ebs: output will be in this color. 2020/04/06 15:18:12 ui: 2020/04/06 15:18:12 Build debug mode: false 2020/04/06 15:18:12 Force build: false 2020/04/06 15:18:12 On error: 2020/04/06 15:18:12 Preparing build: amazon-ebs 2020/04/06 15:18:12 Waiting on builds to complete... 2020/04/06 15:18:12 Starting build run: amazon-ebs 2020/04/06 15:18:12 Running builder: amazon-ebs ``` After changes ``` ⇶ ACC_TEST_BUILDERS=amazon-ebs ACC_TEST_PROVISIONERS=powershell go test -v ./provisioner/shell/... -timeout=1h --- SKIP: TestShellProvisioner (0.00s) provisioners.go:88: Provisioner "shell" not defined in ACC_TEST_PROVISIONERS ```
This commit is contained in:
parent
185deeeb38
commit
360f81b030
|
@ -3,13 +3,14 @@ package acc
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/hashicorp/packer/helper/tests"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
testshelper "github.com/hashicorp/packer/helper/tests"
|
||||
|
||||
amazonEBS "github.com/hashicorp/packer/builder/amazon/ebs/acceptance"
|
||||
virtualboxISO "github.com/hashicorp/packer/builder/virtualbox/iso/acceptance"
|
||||
"github.com/hashicorp/packer/command"
|
||||
|
@ -68,6 +69,26 @@ func TestProvisionersAgainstBuilders(provisionerAcc ProvisionerAcceptance, t *te
|
|||
}
|
||||
}
|
||||
|
||||
// TestProvisionersPreCheck checks if the Provisioner with name is set in ACC_TEST_PROVISIONERS environment variable
|
||||
func TestProvisionersPreCheck(name string, t *testing.T) {
|
||||
p := os.Getenv("ACC_TEST_PROVISIONERS")
|
||||
|
||||
if p == "all" {
|
||||
return
|
||||
}
|
||||
|
||||
provisioners := strings.Split(p, ",")
|
||||
for _, provisioner := range provisioners {
|
||||
if provisioner == name {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("Provisioner %q not defined in ACC_TEST_PROVISIONERS", name)
|
||||
t.Skip(msg)
|
||||
|
||||
}
|
||||
|
||||
func checkBuilders(t *testing.T) []string {
|
||||
b := os.Getenv("ACC_TEST_BUILDERS")
|
||||
// validate if we want to run provisioners acc tests
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/provisioner/powershell"
|
||||
|
@ -17,21 +16,17 @@ import (
|
|||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
const TestProvisionerName = "powershell"
|
||||
|
||||
func TestPowershellProvisioner_Inline(t *testing.T) {
|
||||
p := os.Getenv("ACC_TEST_PROVISIONERS")
|
||||
if p != "all" && !strings.Contains(p, "powershell") {
|
||||
t.Skip()
|
||||
}
|
||||
acc.TestProvisionersPreCheck(TestProvisionerName, t)
|
||||
|
||||
testProvisioner := PowershellProvisionerAccTest{"powershell-inline-provisioner.txt"}
|
||||
acc.TestProvisionersAgainstBuilders(&testProvisioner, t)
|
||||
}
|
||||
|
||||
func TestPowershellProvisioner_Script(t *testing.T) {
|
||||
p := os.Getenv("ACC_TEST_PROVISIONERS")
|
||||
if p != "all" && !strings.Contains(p, "powershell") {
|
||||
t.Skip()
|
||||
}
|
||||
acc.TestProvisionersPreCheck(TestProvisionerName, t)
|
||||
|
||||
testProvisioner := PowershellProvisionerAccTest{"powershell-script-provisioner.txt"}
|
||||
acc.TestProvisionersAgainstBuilders(&testProvisioner, t)
|
||||
|
@ -42,7 +37,7 @@ type PowershellProvisionerAccTest struct {
|
|||
}
|
||||
|
||||
func (s *PowershellProvisionerAccTest) GetName() string {
|
||||
return "powershell"
|
||||
return TestProvisionerName
|
||||
}
|
||||
|
||||
func (s *PowershellProvisionerAccTest) GetConfig() (string, error) {
|
||||
|
@ -59,7 +54,7 @@ func (s *PowershellProvisionerAccTest) GetConfig() (string, error) {
|
|||
|
||||
func (s *PowershellProvisionerAccTest) GetProvisionerStore() packer.MapOfProvisioner {
|
||||
return packer.MapOfProvisioner{
|
||||
"powershell": func() (packer.Provisioner, error) { return &powershell.Provisioner{}, nil },
|
||||
TestProvisionerName: func() (packer.Provisioner, error) { return &powershell.Provisioner{}, nil },
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/helper/tests/acc"
|
||||
|
@ -21,10 +20,7 @@ import (
|
|||
)
|
||||
|
||||
func TestShellProvisioner(t *testing.T) {
|
||||
p := os.Getenv("ACC_TEST_PROVISIONERS")
|
||||
if p != "all" && !strings.Contains(p, "shell") {
|
||||
t.Skip()
|
||||
}
|
||||
acc.TestProvisionersPreCheck("shell", t)
|
||||
acc.TestProvisionersAgainstBuilders(new(ShellProvisionerAccTest), t)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue