From 901f31ad823593b1e9301a5368bd93c17df904fa Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Wed, 15 May 2024 16:16:55 -0400 Subject: [PATCH] packer_test: fix ExpectedName to not clean version The ExpectedInstalledName function used to compute the expected name of a plugin binary for a given version, based on the invoker's environment, used to cleanup the version string passed in parameter of the function, which could be problematic. Besides the logic applied would produce some invalid binary names as the prerelease plugin would not have a `-` separator, so the resulting plugin would be ignored, and we couldn't test metadata rejection with this logic. This commit therefore changes how the function works: the version string is still parsed to account for manipulation errors, but the string is left as-is for the final binary name. --- packer_test/plugin_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packer_test/plugin_test.go b/packer_test/plugin_test.go index 5ba3f1e9b..80ba4e2c8 100644 --- a/packer_test/plugin_test.go +++ b/packer_test/plugin_test.go @@ -86,16 +86,17 @@ func BinaryName(version *version.Version) string { // ExpectedInstalledName is the expected full name of the plugin once installed. func ExpectedInstalledName(versionStr string) string { - v := version.Must(version.NewSemver(versionStr)) + version.Must(version.NewVersion(versionStr)) + + versionStr = strings.ReplaceAll(versionStr, "v", "") ext := "" if runtime.GOOS == "windows" { ext = ".exe" } - return fmt.Sprintf("packer-plugin-tester_v%s%s_x%s.%s_%s_%s%s", - v.Core().String(), - v.Prerelease(), + return fmt.Sprintf("packer-plugin-tester_v%s_x%s.%s_%s_%s%s", + versionStr, plugin.APIVersionMajor, plugin.APIVersionMinor, runtime.GOOS, runtime.GOARCH, ext)