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.
pull/13032/head
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent 50ef9ce990
commit 1e7f29f7c7

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

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

Loading…
Cancel
Save