From 1e7f29f7c71e6141cba9b551a6db37041a58bf02 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 3 May 2024 15:23:30 -0400 Subject: [PATCH] test: add method for setting plugin path for cmd When running a PackerCommand for acceptance tests, we generally run the test on a temporary plugin directory, populated by test plugins. Setting that temporary directory means we need to set the environment variable, which while it could be easier with a constant for the name for example, isn't too straightforward. Therefore for those tests we add a new function for PackerCommand so that it automatically sets that envvar for the current command. --- test/commands_test.go | 5 +++++ test/loading_test.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/commands_test.go b/test/commands_test.go index 003d26a23..d35dcafc0 100644 --- a/test/commands_test.go +++ b/test/commands_test.go @@ -33,6 +33,11 @@ func (ts *PackerTestSuite) PackerCommand() *packerCommand { } } +// UsePluginDir sets the plugin directory in the environment to `dir` +func (pc *packerCommand) UsePluginDir(dir string) *packerCommand { + return pc.AddEnv("PACKER_PLUGIN_PATH", dir) +} + func (pc *packerCommand) SetArgs(args ...string) *packerCommand { pc.args = args return pc diff --git a/test/loading_test.go b/test/loading_test.go index e31decb2c..19381e7bc 100644 --- a/test/loading_test.go +++ b/test/loading_test.go @@ -37,7 +37,7 @@ func (ts *PackerTestSuite) TestLoadingOrder() { t.Run(tt.name, func(t *testing.T) { ts.PackerCommand(). SetArgs(command, tt.templatePath). - AddEnv("PACKER_PLUGIN_PATH", pluginDir). + UsePluginDir(pluginDir). Assert(t, MustSucceed{}, Grep{ streams: BothStreams, expect: tt.grepStr,