diff --git a/test/commands_test.go b/test/commands_test.go index 0f54384be..56d2d3345 100644 --- a/test/commands_test.go +++ b/test/commands_test.go @@ -15,6 +15,7 @@ type packerCommand struct { env map[string]string stderr *strings.Builder stdout *strings.Builder + workdir string err error } @@ -42,6 +43,12 @@ func (pc *packerCommand) NoVerbose() *packerCommand { return pc } +// SetWD changes the directory Packer is invoked from +func (pc *packerCommand) SetWD(dir string) *packerCommand { + pc.workdir = dir + return pc +} + // UsePluginDir sets the plugin directory in the environment to `dir` func (pc *packerCommand) UsePluginDir(dir string) *packerCommand { return pc.AddEnv("PACKER_PLUGIN_PATH", dir) @@ -76,6 +83,10 @@ func (pc *packerCommand) doRun() { cmd.Stdout = pc.stdout cmd.Stderr = pc.stderr + if pc.workdir != "" { + cmd.Dir = pc.workdir + } + pc.err = cmd.Run() }