From 759ec6951fd2bdc3d05ba61334962eeca9c767bd Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Fri, 26 May 2023 17:16:45 -0400 Subject: [PATCH] Update test cases On Windows the exec.LookPath just checks that a file ends with the appropriate extension so this fails the test because the mock file is executed when it shouldn't be. In the realworld, this is an error but for files that don't have a proper extension Packer should ignore them. For Unix there is no extension so it is valid to check if the file is executable. --- packer/plugin_discover_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packer/plugin_discover_test.go b/packer/plugin_discover_test.go index e2b99b031d1..76b580ad9d7 100644 --- a/packer/plugin_discover_test.go +++ b/packer/plugin_discover_test.go @@ -157,9 +157,23 @@ func TestDiscoverDatasource(t *testing.T) { func TestDiscover_NonExecutableMultiComponentPlugins(t *testing.T) { pluginNames := []string{"packer-plugin-partyparrot", "packer-plugin-happycloud", "packer-plugin-long-name-component"} // Create a temporary directory to store plugins in - dir, _, cleanUpFunc, err := generateFakePlugins("custom_plugin_dir", pluginNames) + dir, err := os.MkdirTemp("", "custom_plugin_dir") if err != nil { - t.Fatalf("Error creating fake custom plugins: %s", err) + t.Fatalf("failed to create temporary test directory: %v", err) + } + + cleanUpFunc := func() { + os.RemoveAll(dir) + } + + plugins := make([]string, len(pluginNames)) + for i, plugin := range pluginNames { + plug := filepath.Join(dir, plugin) + plugins[i] = plug + _, err := os.Create(plug) + if err != nil { + t.Fatalf("failed to create fake plugins for testing: %v", err) + } } defer cleanUpFunc()