test: add SetWD function to packerCommand

For some tests we may need Packer to run in another directory than the
one we're invoking the tests from, so we add a new function to the
packerCommand structure to change that.
pull/13032/head
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent f48f4e786b
commit 8f7efe0d57

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

Loading…
Cancel
Save