e2e: allow tests to set environment variables for command runs

This commit is contained in:
Martin Atkins 2017-09-19 11:31:18 -07:00
parent cb6d4e5f20
commit 0abedd8877
1 changed files with 9 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import (
type binary struct { type binary struct {
binPath string binPath string
workDir string workDir string
env []string
} }
// NewBinary prepares a temporary directory containing the files from the // NewBinary prepares a temporary directory containing the files from the
@ -93,6 +94,12 @@ func NewBinary(binaryPath, workingDir string) *binary {
} }
} }
// AddEnv appends an entry to the environment variable table passed to any
// commands subsequently run.
func (b *binary) AddEnv(entry string) {
b.env = append(b.env, entry)
}
// Cmd returns an exec.Cmd pre-configured to run the generated Terraform // Cmd returns an exec.Cmd pre-configured to run the generated Terraform
// binary with the given arguments in the temporary working directory. // binary with the given arguments in the temporary working directory.
// //
@ -108,6 +115,8 @@ func (b *binary) Cmd(args ...string) *exec.Cmd {
// end-to-end testing of our Checkpoint interactions.) // end-to-end testing of our Checkpoint interactions.)
cmd.Env = append(cmd.Env, "CHECKPOINT_DISABLE=1") cmd.Env = append(cmd.Env, "CHECKPOINT_DISABLE=1")
cmd.Env = append(cmd.Env, b.env...)
return cmd return cmd
} }