From 6ecdd3ca164eb0174ffd9fc24e60063a83f677b0 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 7 Dec 2020 15:06:46 -0800 Subject: [PATCH] small tweaks --- Makefile | 2 +- .../acctest/provisioneracc/provisioners.go | 35 +++++-------------- .../test-fixtures/amazon-ebs/amazon-ebs.txt | 12 +++++-- packer-plugin-sdk/acctest/testing.go | 1 - 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 8f80a2474..87f0829d9 100644 --- a/Makefile +++ b/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 diff --git a/packer-plugin-sdk/acctest/provisioneracc/provisioners.go b/packer-plugin-sdk/acctest/provisioneracc/provisioners.go index 66733bcec..3fea78db2 100644 --- a/packer-plugin-sdk/acctest/provisioneracc/provisioners.go +++ b/packer-plugin-sdk/acctest/provisioneracc/provisioners.go @@ -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 { diff --git a/packer-plugin-sdk/acctest/provisioneracc/test-fixtures/amazon-ebs/amazon-ebs.txt b/packer-plugin-sdk/acctest/provisioneracc/test-fixtures/amazon-ebs/amazon-ebs.txt index 1245cf9e5..fd0af177c 100644 --- a/packer-plugin-sdk/acctest/provisioneracc/test-fixtures/amazon-ebs/amazon-ebs.txt +++ b/packer-plugin-sdk/acctest/provisioneracc/test-fixtures/amazon-ebs/amazon-ebs.txt @@ -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" diff --git a/packer-plugin-sdk/acctest/testing.go b/packer-plugin-sdk/acctest/testing.go index d28b5f2dd..acdd0bf51 100644 --- a/packer-plugin-sdk/acctest/testing.go +++ b/packer-plugin-sdk/acctest/testing.go @@ -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,