diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/acctest/testing.go b/acctest/testing.go similarity index 100% rename from vendor/github.com/hashicorp/packer-plugin-sdk/acctest/testing.go rename to acctest/testing.go diff --git a/acctest/testing_test.go b/acctest/testing_test.go new file mode 100644 index 000000000..ca2240470 --- /dev/null +++ b/acctest/testing_test.go @@ -0,0 +1,72 @@ +package acctest + +import ( + "os" + "testing" +) + +func init() { + testTesting = true + + if err := os.Setenv(TestEnvVar, "1"); err != nil { + panic(err) + } +} + +func TestTest_noEnv(t *testing.T) { + // Unset the variable + if err := os.Setenv(TestEnvVar, ""); err != nil { + t.Fatalf("err: %s", err) + } + defer os.Setenv(TestEnvVar, "1") + + mt := new(mockT) + Test(mt, TestCase{}) + + if !mt.SkipCalled { + t.Fatal("skip not called") + } +} + +func TestTest_preCheck(t *testing.T) { + called := false + + mt := new(mockT) + Test(mt, TestCase{ + PreCheck: func() { called = true }, + }) + + if !called { + t.Fatal("precheck should be called") + } +} + +// mockT implements TestT for testing +type mockT struct { + ErrorCalled bool + ErrorArgs []interface{} + FatalCalled bool + FatalArgs []interface{} + SkipCalled bool + SkipArgs []interface{} + + f bool +} + +func (t *mockT) Error(args ...interface{}) { + t.ErrorCalled = true + t.ErrorArgs = args + t.f = true +} + +func (t *mockT) Fatal(args ...interface{}) { + t.FatalCalled = true + t.FatalArgs = args + t.f = true +} + +func (t *mockT) Skip(args ...interface{}) { + t.SkipCalled = true + t.SkipArgs = args + t.f = true +} diff --git a/builder/alicloud/ecs/builder_acc_test.go b/builder/alicloud/ecs/builder_acc_test.go index cbc25e0e7..f4cf7ef78 100644 --- a/builder/alicloud/ecs/builder_acc_test.go +++ b/builder/alicloud/ecs/builder_acc_test.go @@ -8,8 +8,8 @@ import ( "testing" "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + builderT "github.com/hashicorp/packer/acctest" ) const defaultTestRegion = "cn-beijing" diff --git a/builder/azure/arm/builder_acc_test.go b/builder/azure/arm/builder_acc_test.go index 046dcb356..d9a48117a 100644 --- a/builder/azure/arm/builder_acc_test.go +++ b/builder/azure/arm/builder_acc_test.go @@ -30,8 +30,8 @@ import ( "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure/auth" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + builderT "github.com/hashicorp/packer/acctest" ) const DeviceLoginAcceptanceTest = "DEVICELOGIN_TEST" diff --git a/builder/azure/dtl/builder_acc_test.go b/builder/azure/dtl/builder_acc_test.go index 99a8b1b36..bbea241f4 100644 --- a/builder/azure/dtl/builder_acc_test.go +++ b/builder/azure/dtl/builder_acc_test.go @@ -28,7 +28,7 @@ package dtl import ( "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + builderT "github.com/hashicorp/packer/acctest" ) const DeviceLoginAcceptanceTest = "DEVICELOGIN_TEST" diff --git a/builder/digitalocean/builder_acc_test.go b/builder/digitalocean/builder_acc_test.go index bd0982caf..6c6358afc 100644 --- a/builder/digitalocean/builder_acc_test.go +++ b/builder/digitalocean/builder_acc_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/digitalocean/godo" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + builderT "github.com/hashicorp/packer/acctest" "golang.org/x/oauth2" ) diff --git a/builder/file/builder_test.go b/builder/file/builder_test.go index bfccfbed2..ea8669240 100644 --- a/builder/file/builder_test.go +++ b/builder/file/builder_test.go @@ -5,8 +5,8 @@ import ( "io/ioutil" "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + builderT "github.com/hashicorp/packer/acctest" ) func TestBuilder_implBuilder(t *testing.T) { diff --git a/builder/hcloud/builder_acc_test.go b/builder/hcloud/builder_acc_test.go index a6121da5b..d9900944a 100644 --- a/builder/hcloud/builder_acc_test.go +++ b/builder/hcloud/builder_acc_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + builderT "github.com/hashicorp/packer/acctest" ) func TestBuilderAcc_basic(t *testing.T) { diff --git a/builder/hyperone/builder_acc_test.go b/builder/hyperone/builder_acc_test.go index 90c0bb1cd..8a31c96f6 100644 --- a/builder/hyperone/builder_acc_test.go +++ b/builder/hyperone/builder_acc_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + builderT "github.com/hashicorp/packer/acctest" ) func TestBuilderAcc_basic(t *testing.T) { diff --git a/builder/linode/builder_acc_test.go b/builder/linode/builder_acc_test.go index 211035de0..74acf48e9 100644 --- a/builder/linode/builder_acc_test.go +++ b/builder/linode/builder_acc_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + builderT "github.com/hashicorp/packer/acctest" ) func TestBuilderAcc_basic(t *testing.T) { diff --git a/builder/oneandone/builder_acc_test.go b/builder/oneandone/builder_acc_test.go index 0c3967ad6..38a924454 100644 --- a/builder/oneandone/builder_acc_test.go +++ b/builder/oneandone/builder_acc_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + builderT "github.com/hashicorp/packer/acctest" ) func TestBuilderAcc_basic(t *testing.T) { diff --git a/builder/osc/bsu/builder_acc_test.go b/builder/osc/bsu/builder_acc_test.go index 04646e9b4..757c90a8d 100644 --- a/builder/osc/bsu/builder_acc_test.go +++ b/builder/osc/bsu/builder_acc_test.go @@ -4,7 +4,7 @@ package bsu import ( "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + builderT "github.com/hashicorp/packer/acctest" ) func TestBuilderAcc_basic(t *testing.T) { diff --git a/builder/osc/bsusurrogate/builder_acc_test.go b/builder/osc/bsusurrogate/builder_acc_test.go index b39f8c38d..38146d760 100644 --- a/builder/osc/bsusurrogate/builder_acc_test.go +++ b/builder/osc/bsusurrogate/builder_acc_test.go @@ -3,7 +3,7 @@ package bsusurrogate import ( "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + builderT "github.com/hashicorp/packer/acctest" ) func TestBuilderAcc_basic(t *testing.T) { diff --git a/builder/osc/bsuvolume/builder_acc_test.go b/builder/osc/bsuvolume/builder_acc_test.go index f2fcab1a5..e896ad0df 100644 --- a/builder/osc/bsuvolume/builder_acc_test.go +++ b/builder/osc/bsuvolume/builder_acc_test.go @@ -4,7 +4,7 @@ package bsuvolume import ( "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + builderT "github.com/hashicorp/packer/acctest" ) func TestBuilderAcc_basic(t *testing.T) { diff --git a/builder/profitbricks/builder_acc_test.go b/builder/profitbricks/builder_acc_test.go index efeada06d..9419a2a5c 100644 --- a/builder/profitbricks/builder_acc_test.go +++ b/builder/profitbricks/builder_acc_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + builderT "github.com/hashicorp/packer/acctest" ) func TestBuilderAcc_basic(t *testing.T) { diff --git a/builder/ucloud/uhost/builder_acc_test.go b/builder/ucloud/uhost/builder_acc_test.go index c8f3d48cd..1c5485200 100644 --- a/builder/ucloud/uhost/builder_acc_test.go +++ b/builder/ucloud/uhost/builder_acc_test.go @@ -6,10 +6,9 @@ import ( "testing" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + builderT "github.com/hashicorp/packer/acctest" ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/stretchr/testify/assert" - - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" ) func TestBuilderAcc_validateRegion(t *testing.T) { diff --git a/builder/virtualbox/iso/builder_acc_test.go b/builder/virtualbox/iso/builder_acc_test.go index a9047d31d..61c163d58 100644 --- a/builder/virtualbox/iso/builder_acc_test.go +++ b/builder/virtualbox/iso/builder_acc_test.go @@ -5,7 +5,7 @@ import ( "path/filepath" "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + builderT "github.com/hashicorp/packer/acctest" ) func TestBuilderAcc_basic(t *testing.T) { diff --git a/builder/vmware/iso/builder_acc_test.go b/builder/vmware/iso/builder_acc_test.go index a9047d31d..2f0047223 100644 --- a/builder/vmware/iso/builder_acc_test.go +++ b/builder/vmware/iso/builder_acc_test.go @@ -1,11 +1,14 @@ package iso import ( + "fmt" "io/ioutil" + "os/exec" "path/filepath" "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + "github.com/hashicorp/packer-plugin-sdk/acctest" + "github.com/hashicorp/packer-plugin-sdk/acctest/testutils" ) func TestBuilderAcc_basic(t *testing.T) { @@ -15,8 +18,25 @@ func TestBuilderAcc_basic(t *testing.T) { t.Fatalf("failed to load template file %s", templatePath) } - builderT.Test(t, builderT.TestCase{ - Builder: &Builder{}, + testCase := &acctest.PluginTestCase{ + Name: "vmware-iso_builder_basic_test", + Setup: func() error { + return nil + }, + Teardown: func() error { + testutils.CleanupFiles("output-vmware-iso", "packer_cache") + return nil + }, Template: string(bytes), - }) + Type: "vmware-iso", + Check: func(buildCommand *exec.Cmd, logfile string) error { + if buildCommand.ProcessState != nil { + if buildCommand.ProcessState.ExitCode() != 0 { + return fmt.Errorf("Bad exit code. Logfile: %s", logfile) + } + } + return nil + }, + } + acctest.TestPlugin(t, testCase) } diff --git a/builder/vmware/iso/step_create_vmx_test.go b/builder/vmware/iso/step_create_vmx_test.go index e91f70135..9af6f06ea 100644 --- a/builder/vmware/iso/step_create_vmx_test.go +++ b/builder/vmware/iso/step_create_vmx_test.go @@ -11,9 +11,9 @@ import ( "strings" "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" "github.com/hashicorp/packer-plugin-sdk/tmp" + builderT "github.com/hashicorp/packer/acctest" ) const vmxTestTemplate string = `{"builders":[{%s}],"provisioners":[{%s}]}` diff --git a/builder/vmware/iso/testdata/minimal.json b/builder/vmware/iso/testdata/minimal.json index cb460523c..d27047c3a 100644 --- a/builder/vmware/iso/testdata/minimal.json +++ b/builder/vmware/iso/testdata/minimal.json @@ -1,7 +1,7 @@ { "builders": [ { - "type": "test", + "type": "vmware-iso", "boot_command": [ "", "", diff --git a/builder/vsphere/clone/builder_acc_test.go b/builder/vsphere/clone/builder_acc_test.go index 6797da495..f39610644 100644 --- a/builder/vsphere/clone/builder_acc_test.go +++ b/builder/vsphere/clone/builder_acc_test.go @@ -4,8 +4,8 @@ import ( "os" "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + builderT "github.com/hashicorp/packer/acctest" "github.com/hashicorp/packer/builder/vsphere/common" commonT "github.com/hashicorp/packer/builder/vsphere/common/testing" "github.com/vmware/govmomi/vim25/types" diff --git a/builder/vsphere/iso/builder_acc_test.go b/builder/vsphere/iso/builder_acc_test.go index 180ace74c..63dc6b520 100644 --- a/builder/vsphere/iso/builder_acc_test.go +++ b/builder/vsphere/iso/builder_acc_test.go @@ -6,8 +6,8 @@ import ( "os" "testing" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + builderT "github.com/hashicorp/packer/acctest" commonT "github.com/hashicorp/packer/builder/vsphere/common/testing" "github.com/vmware/govmomi/vim25/types" ) diff --git a/builder/yandex/builder_acc_test.go b/builder/yandex/builder_acc_test.go index 99af96663..bcf7d523b 100644 --- a/builder/yandex/builder_acc_test.go +++ b/builder/yandex/builder_acc_test.go @@ -7,7 +7,7 @@ import ( "github.com/go-resty/resty/v2" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" + builderT "github.com/hashicorp/packer/acctest" ) const InstanceMetadataAddr = "169.254.169.254" diff --git a/go.mod b/go.mod index 95d3a71bc..42f9d9c05 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/hashicorp/hcl/v2 v2.9.1 github.com/hashicorp/packer-plugin-amazon v0.0.1 github.com/hashicorp/packer-plugin-docker v0.0.7 - github.com/hashicorp/packer-plugin-sdk v0.1.2 + github.com/hashicorp/packer-plugin-sdk v0.1.3-0.20210407090040-d1eff9fe99e8 github.com/hashicorp/vault/api v1.0.4 github.com/hetznercloud/hcloud-go v1.15.1 github.com/hyperonecom/h1-client-go v0.0.0-20191203060043-b46280e4c4a4 diff --git a/go.sum b/go.sum index 8b0a06580..49bf46a4c 100644 --- a/go.sum +++ b/go.sum @@ -445,6 +445,8 @@ github.com/hashicorp/packer-plugin-sdk v0.1.0/go.mod h1:CFsC20uZjtER/EnTn/CSMKD0 github.com/hashicorp/packer-plugin-sdk v0.1.1/go.mod h1:1d3nqB9LUsXMQaNUiL67Q+WYEtjsVcLNTX8ikVlpBrc= github.com/hashicorp/packer-plugin-sdk v0.1.2 h1:R/WKJw6BDwvjbcKeC3mZs+wSmdFHE8iK+qz+QnArPQk= github.com/hashicorp/packer-plugin-sdk v0.1.2/go.mod h1:KRjczE1/c9NV5Re+PXt3myJsVTI/FxEHpZjRjOH0Fug= +github.com/hashicorp/packer-plugin-sdk v0.1.3-0.20210407090040-d1eff9fe99e8 h1:pkB+Y15/ck/NRUBFF9DrdPYQwmnHsEvnNwmgMfl/8hA= +github.com/hashicorp/packer-plugin-sdk v0.1.3-0.20210407090040-d1eff9fe99e8/go.mod h1:xePpgQgQYv/bamiypx3hH9ukidxDdcN8q0R0wLi8IEQ= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hashicorp/serf v0.9.2 h1:yJoyfZXo4Pk2p/M/viW+YLibBFiIbKoP79gu7kDAFP0= github.com/hashicorp/serf v0.9.2/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= diff --git a/provisioner/ansible-local/provisioner_test.go b/provisioner/ansible-local/provisioner_test.go index 1dde309d2..0cf4555a7 100644 --- a/provisioner/ansible-local/provisioner_test.go +++ b/provisioner/ansible-local/provisioner_test.go @@ -12,8 +12,8 @@ import ( "os/exec" "github.com/hashicorp/packer-plugin-docker/builder/docker" - builderT "github.com/hashicorp/packer-plugin-sdk/acctest" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + builderT "github.com/hashicorp/packer/acctest" "github.com/hashicorp/packer/provisioner/file" ) diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/acctest/datasources.go b/vendor/github.com/hashicorp/packer-plugin-sdk/acctest/datasources.go deleted file mode 100644 index 20c3a4837..000000000 --- a/vendor/github.com/hashicorp/packer-plugin-sdk/acctest/datasources.go +++ /dev/null @@ -1,112 +0,0 @@ -package acctest - -import ( - "bytes" - "fmt" - "log" - "os" - "os/exec" - "path/filepath" - "testing" -) - -// DatasourceTestCase is a single set of tests to run for a data source. -// A DatasourceTestCase should generally map 1:1 to each test method for your -// acceptance tests. -// Requirements: -// - The plugin to be tested must be previously installed so that Packer can discover it. -// - Packer must be installed -type DatasourceTestCase struct { - // Check is called after this step is executed in order to test that - // the step executed successfully. If this is not set, then the next - // step will be called - Check func(*exec.Cmd, string) error - // Name is the name of the test case. Be simple but unique and descriptive. - Name string - // Setup, if non-nil, will be called once before the test case - // runs. This can be used for some setup like setting environment - // variables, or for validation prior to the - // test running. For example, you can use this to make sure certain - // binaries are installed, or text fixtures are in place. - Setup func() error - // Teardown will be called before the test case is over regardless - // of if the test succeeded or failed. This should return an error - // in the case that the test can't guarantee all resources were - // properly cleaned up. - Teardown TestTeardownFunc - // Template is the testing HCL2 template to use. - Template string - // Type is the type of data source. - Type string -} - -//nolint:errcheck -func TestDatasource(t *testing.T, testCase *DatasourceTestCase) { - if os.Getenv(TestEnvVar) == "" { - t.Skip(fmt.Sprintf( - "Acceptance tests skipped unless env '%s' set", - TestEnvVar)) - return - } - - if testCase.Setup != nil { - err := testCase.Setup() - if err != nil { - t.Fatalf("test %s setup failed: %s", testCase.Name, err) - } - } - - logfile := fmt.Sprintf("packer_log_%s.txt", testCase.Name) - templatePath := fmt.Sprintf("./%s.pkr.hcl", testCase.Name) - - // Write config hcl2 template - out := bytes.NewBuffer(nil) - fmt.Fprintf(out, testCase.Template) - outputFile, err := os.Create(templatePath) - if err != nil { - t.Fatalf("bad: failed to create template file: %s", err.Error()) - } - _, err = outputFile.Write(out.Bytes()) - if err != nil { - t.Fatalf("bad: failed to write template file: %s", err.Error()) - } - outputFile.Sync() - - // Make sure packer is installed: - packerbin, err := exec.LookPath("packer") - if err != nil { - t.Fatalf("Couldn't find packer binary installed on system: %s", err.Error()) - } - // Run build - buildCommand := exec.Command(packerbin, "build", "--machine-readable", templatePath) - buildCommand.Env = append(buildCommand.Env, os.Environ()...) - buildCommand.Env = append(buildCommand.Env, "PACKER_LOG=1", - fmt.Sprintf("PACKER_LOG_PATH=%s", logfile)) - buildCommand.Run() - - // Check for test custom pass/fail before we clean up - var checkErr error - if testCase.Check != nil { - checkErr = testCase.Check(buildCommand, logfile) - } - // Clean up anything created in data source run - if testCase.Teardown != nil { - cleanErr := testCase.Teardown() - if cleanErr != nil { - log.Printf("bad: failed to clean up test-created resources: %s", cleanErr.Error()) - } - } - - // Fail test if check failed. - if checkErr != nil { - cwd, _ := os.Getwd() - t.Fatalf(fmt.Sprintf("Error running data source acceptance"+ - " tests: %s\nLogs can be found at %s\nand the "+ - "acceptance test template can be found at %s", - checkErr.Error(), filepath.Join(cwd, logfile), - filepath.Join(cwd, templatePath))) - } else { - os.Remove(templatePath) - os.Remove(logfile) - } -} diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/acctest/pluginacc.go b/vendor/github.com/hashicorp/packer-plugin-sdk/acctest/pluginacc.go index 85eae43ea..94e2377f8 100644 --- a/vendor/github.com/hashicorp/packer-plugin-sdk/acctest/pluginacc.go +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/acctest/pluginacc.go @@ -11,6 +11,9 @@ import ( "testing" ) +// TestEnvVar must be set to a non-empty value for acceptance tests to run. +const TestEnvVar = "PACKER_ACC" + // PluginTestCase is a single set of tests to run for a plugin. // A PluginTestCase should generally map 1:1 to each test method for your // acceptance tests. @@ -41,6 +44,9 @@ type PluginTestCase struct { Type string } +// TestTeardownFunc is the callback used for Teardown in TestCase. +type TestTeardownFunc func() error + //nolint:errcheck func TestPlugin(t *testing.T, testCase *PluginTestCase) { if os.Getenv(TestEnvVar) == "" { diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/version/version.go b/vendor/github.com/hashicorp/packer-plugin-sdk/version/version.go index a88582177..36e0282fa 100644 --- a/vendor/github.com/hashicorp/packer-plugin-sdk/version/version.go +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/version/version.go @@ -13,12 +13,12 @@ import ( var GitCommit string // Package version helps plugin creators set and track the sdk version using -var Version = "0.1.2" +var Version = "0.1.3" // A pre-release marker for the version. If this is "" (empty string) // then it means that it is a final release. Otherwise, this is a pre-release // such as "dev" (in development), "beta", "rc1", etc. -var VersionPrerelease = "" +var VersionPrerelease = "dev" // SDKVersion is used by the plugin set to allow Packer to recognize // what version of the sdk the plugin is. diff --git a/vendor/modules.txt b/vendor/modules.txt index a8fb7056e..341bddb9b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -511,7 +511,7 @@ github.com/hashicorp/packer-plugin-docker/post-processor/docker-import github.com/hashicorp/packer-plugin-docker/post-processor/docker-push github.com/hashicorp/packer-plugin-docker/post-processor/docker-save github.com/hashicorp/packer-plugin-docker/post-processor/docker-tag -# github.com/hashicorp/packer-plugin-sdk v0.1.2 +# github.com/hashicorp/packer-plugin-sdk v0.1.3-0.20210407090040-d1eff9fe99e8 ## explicit github.com/hashicorp/packer-plugin-sdk/acctest github.com/hashicorp/packer-plugin-sdk/acctest/provisioneracc