From a2e08329a341845454899c53bd2e1c83817e3a13 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Wed, 15 May 2024 18:05:03 -0400 Subject: [PATCH] packer_test: fix shasum file name for tests When manually installing a plugin to the plugin directory, we compute a SHA256SUM file from the plugin binary, and install it alongside it so we can test the loading process for Packer. In the introduction of the function, we added a check that if we were running on Windows, we'd remove the extension of the sumfile's name before writing it. This is actually not necessary (and breaks the loading logic) as Packer looks for the name of the plugin with extension, followed by _SHA256SUM in order to compare the effective digest of the file to the one written to this file. Since this prevents the tests that use this function from succeeding in a Windows environment, we remove this extra step. --- packer_test/loading_test.go | 9 +-------- packer_test/plugin_test.go | 6 +----- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/packer_test/loading_test.go b/packer_test/loading_test.go index 5effa662b..59126a053 100644 --- a/packer_test/loading_test.go +++ b/packer_test/loading_test.go @@ -5,8 +5,6 @@ import ( "fmt" "os" "path/filepath" - "runtime" - "strings" ) func (ts *PackerTestSuite) TestLoadingOrder() { @@ -119,14 +117,9 @@ func (ts *PackerTestSuite) TestLoadWithSHAMismatches() { defer cleanup() pluginDestName := ExpectedInstalledName("1.0.10") - noExtDest := pluginDestName - if runtime.GOOS == "windows" { - noExtDest = strings.Replace(pluginDestName, ".exe", "", 1) - } - CopyFile(ts.T(), filepath.Join(pluginDir, "github.com", "hashicorp", "tester", pluginDestName), plugin) WriteFile(ts.T(), - filepath.Join(pluginDir, "github.com", "hashicorp", "tester", fmt.Sprintf("%s_SHA256SUM", noExtDest)), + filepath.Join(pluginDir, "github.com", "hashicorp", "tester", fmt.Sprintf("%s_SHA256SUM", pluginDestName)), fmt.Sprintf("%x", sha256.New().Sum([]byte("Not the plugin's contents for sure.")))) ts.PackerCommand().UsePluginDir(pluginDir). diff --git a/packer_test/plugin_test.go b/packer_test/plugin_test.go index f3376f874..b3be0339b 100644 --- a/packer_test/plugin_test.go +++ b/packer_test/plugin_test.go @@ -328,10 +328,6 @@ func ManualPluginInstall(t *testing.T, dest, srcPlugin, versionStr string) { CopyFile(t, destPath, srcPlugin) - shaPath := destPath - if runtime.GOOS == "windows" { - shaPath = strings.Replace(destPath, ".exe", "", 1) - } - shaPath = fmt.Sprintf("%s_SHA256SUM", shaPath) + shaPath := fmt.Sprintf("%s_SHA256SUM", destPath) WriteFile(t, shaPath, SHA256Sum(t, destPath)) }