diff --git a/test/loading_test.go b/test/loading_test.go index c12f019d2..258d8b5f5 100644 --- a/test/loading_test.go +++ b/test/loading_test.go @@ -1,20 +1,14 @@ package test import ( - "os" "testing" ) func (ts *PackerTestSuite) TestLoadingOrder() { t := ts.T() - pluginDir := ts.MakePluginDir(t, "1.0.9", "1.0.10") - defer func() { - err := os.RemoveAll(pluginDir) - if err != nil { - t.Logf("failed to remove temporary plugin directory %q: %s. This may need manual intervention.", pluginDir, err) - } - }() + pluginDir, cleanup := ts.MakePluginDir(t, "1.0.9", "1.0.10") + defer cleanup() for _, command := range []string{"build", "validate"} { tests := []struct { diff --git a/test/plugin_test.go b/test/plugin_test.go index 67af25c26..53d5193a6 100644 --- a/test/plugin_test.go +++ b/test/plugin_test.go @@ -2,6 +2,7 @@ package test import ( "fmt" + "io" "os" "os/exec" "path/filepath" @@ -160,7 +161,7 @@ func currentDir() (string, error) { // packer will be able to use that directory for running its functions. // // Deletion of the directory is the caller's responsibility. -func (ts *PackerTestSuite) MakePluginDir(t *testing.T, pluginVersions ...string) (pluginTempDir string) { +func (ts *PackerTestSuite) MakePluginDir(t *testing.T, pluginVersions ...string) (pluginTempDir string, cleanup func()) { var err error defer func() { @@ -188,5 +189,10 @@ func (ts *PackerTestSuite) MakePluginDir(t *testing.T, pluginVersions ...string) } } - return pluginTempDir + return pluginTempDir, func() { + err := os.RemoveAll(pluginTempDir) + if err != nil { + t.Logf("failed to remove temporary plugin directory %q: %s. This may need manual intervention.", pluginTempDir, err) + } + } }