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.
pull/13032/head
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent 7e0b27adaa
commit 901f31ad82

@ -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)

Loading…
Cancel
Save