From 50ef9ce99049d154b93aa47d40957dea8c84f9da Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 3 May 2024 12:00:43 -0400 Subject: [PATCH] test: simplify plugin build function The NewPluginBuildConfig function was essentially a shortcut to `version.Must(version.NewSemver(v))', which is superfluous at this point, we can directly pass the version string to BuildSimplePlugin and let that function do the creation/check. --- test/plugin_test.go | 16 +++++++--------- test/suite_test.go | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/test/plugin_test.go b/test/plugin_test.go index 2d1e91af3..778941a0e 100644 --- a/test/plugin_test.go +++ b/test/plugin_test.go @@ -53,10 +53,6 @@ func PluginBinaryDir() string { return tempPluginBinaryPath.path } -func NewPluginBuildConfig(versionStr string) *version.Version { - return version.Must(version.NewVersion(versionStr)) -} - // LDFlags compiles the ldflags for the plugin to compile based on the information provided. func LDFlags(version *version.Version) string { pluginPackage := "github.com/hashicorp/packer-plugin-tester" @@ -99,8 +95,10 @@ func BinaryName(version *version.Version) string { // // The path to the plugin is returned, it won't be removed automatically // though, deletion is the caller's responsibility. -func BuildSimplePlugin(version *version.Version, t *testing.T) { - t.Logf("Building plugin in version %v", version) +func BuildSimplePlugin(versionString string, t *testing.T) { + v := version.Must(version.NewSemver(versionString)) + + t.Logf("Building plugin in version %v", v) testDir, err := currentDir() if err != nil { @@ -108,15 +106,15 @@ func BuildSimplePlugin(version *version.Version, t *testing.T) { } miniPluginDir := filepath.Join(testDir, "mini_plugin") - outBin := filepath.Join(PluginBinaryDir(), BinaryName(version)) + outBin := filepath.Join(PluginBinaryDir(), BinaryName(v)) - compileCommand := exec.Command("go", "build", "-C", miniPluginDir, "-o", outBin, "-ldflags", LDFlags(version), ".") + compileCommand := exec.Command("go", "build", "-C", miniPluginDir, "-o", outBin, "-ldflags", LDFlags(v), ".") logs, err := compileCommand.CombinedOutput() if err != nil { t.Fatalf("failed to compile plugin binary: %s\ncompiler logs: %s", err, logs) } - StorePluginVersion(version.String(), outBin) + StorePluginVersion(v.String(), outBin) } // currentDir returns the directory in which the current file is located. diff --git a/test/suite_test.go b/test/suite_test.go index 1d1c96f59..939534d12 100644 --- a/test/suite_test.go +++ b/test/suite_test.go @@ -25,7 +25,7 @@ type PackerTestSuite struct { func buildPluginVersion(waitgroup *sync.WaitGroup, versionString string, t *testing.T) { waitgroup.Add(1) go func() { - BuildSimplePlugin(NewPluginBuildConfig(versionString), t) + BuildSimplePlugin(versionString, t) waitgroup.Done() }() }