small tweaks
This commit is contained in:
parent
76177b50ce
commit
6ecdd3ca16
2
Makefile
2
Makefile
|
@ -141,7 +141,7 @@ test: mode-check vet ## Run unit tests
|
|||
|
||||
# acctest runs provisioners acceptance tests
|
||||
provisioners-acctest: #install-build-deps generate
|
||||
ACC_TEST_BUILDERS=$(ACC_TEST_BUILDERS) ACC_TEST_PROVISIONERS=$(ACC_TEST_PROVISIONERS) go test ./provisioner/... -timeout=1h
|
||||
ACC_TEST_BUILDERS=$(ACC_TEST_BUILDERS) go test $(TEST) $(TESTARGS) -timeout=1h
|
||||
|
||||
# testacc runs acceptance tests
|
||||
testacc: # install-build-deps generate ## Run acceptance tests
|
||||
|
|
|
@ -163,10 +163,10 @@ func LoadBuilderFragment(templateFragmentPath string) (string, error) {
|
|||
}
|
||||
|
||||
func RunProvisionerAccTest(testCase *ProvisionerTestCase, t *testing.T) {
|
||||
TestProvisionersPreCheck(testCase.Type, t)
|
||||
TestProvisionersAgainstBuilders(testCase, t)
|
||||
}
|
||||
|
||||
//nolint:errcheck
|
||||
func TestProvisionersAgainstBuilders(testCase *ProvisionerTestCase, t *testing.T) {
|
||||
// retrieve user-desired builders.
|
||||
builderTypes := checkBuilders(t)
|
||||
|
@ -207,7 +207,6 @@ func TestProvisionersAgainstBuilders(testCase *ProvisionerTestCase, t *testing.T
|
|||
logfile := fmt.Sprintf("packer_log_%s_%s.txt", builderType, testCase.Type)
|
||||
|
||||
// Run build
|
||||
// TODO: stream logs _and_ store in a logfile.
|
||||
buildCommand := exec.Command("packer", "build", "--machine-readable", templatePath)
|
||||
buildCommand.Env = append(buildCommand.Env, os.Environ()...)
|
||||
buildCommand.Env = append(buildCommand.Env, "PACKER_LOG=1",
|
||||
|
@ -220,10 +219,6 @@ func TestProvisionersAgainstBuilders(testCase *ProvisionerTestCase, t *testing.T
|
|||
checkErr = testCase.Check(buildCommand, logfile)
|
||||
}
|
||||
|
||||
// preemptive cleanup
|
||||
defer os.Remove(templatePath)
|
||||
defer os.Remove(logfile)
|
||||
|
||||
// Cleanup stuff created by builder.
|
||||
cleanErr := buildFixture.Teardown()
|
||||
if cleanErr != nil {
|
||||
|
@ -239,33 +234,19 @@ func TestProvisionersAgainstBuilders(testCase *ProvisionerTestCase, t *testing.T
|
|||
|
||||
// Fail test if check failed.
|
||||
if checkErr != nil {
|
||||
t.Fatalf(checkErr.Error())
|
||||
t.Fatalf(fmt.Sprint("Error running provisioner acceptance"+
|
||||
" tests: %s\nLogs can be found at %s and the "+
|
||||
"acceptance test template can be found at %s",
|
||||
checkErr.Error(), logfile, templatePath))
|
||||
} else {
|
||||
os.Remove(templatePath)
|
||||
os.Remove(logfile)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
}
|
||||
|
||||
// checkBuilders retrieves all of the builders that the user has requested to
|
||||
// run acceptance tests against.
|
||||
func checkBuilders(t *testing.T) []string {
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-acc-test",
|
||||
"instance_type": "m1.small",
|
||||
"instance_type": "t2.micro",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ubuntu",
|
||||
"source_ami": "ami-0568456c",
|
||||
"source_ami_filter": {
|
||||
"filters": {
|
||||
"virtualization-type": "hvm",
|
||||
"name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
|
||||
"root-device-type": "ebs"
|
||||
},
|
||||
"owners": ["099720109477"],
|
||||
"most_recent": true
|
||||
},
|
||||
"force_deregister" : true,
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
|
|
|
@ -175,7 +175,6 @@ func Test(t TestT, c TestCase) {
|
|||
// Run it! We use a temporary directory for caching and discard
|
||||
// any UI output. We discard since it shows up in logs anyways.
|
||||
log.Printf("[DEBUG] Running 'test' build")
|
||||
// ui := packersdk.TestUi(t)
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: os.Stdin,
|
||||
Writer: ioutil.Discard,
|
||||
|
|
Loading…
Reference in New Issue