packer_test: set TMP envvar for commands

Windows relies on the `TMP` (or alternatives) being set in the
environment in order to be able to create temporary directories and
files.

If this is not set, the `os.TempDir` function defaults on the windows
installation root directory (typically C:\Windows), leading to
permission errors when running Packer in the context of a test, as we're
installing plugins in a temporary directory.

To avoid this problem, we get the current setting from the test's
invocation environment, and forward it to the subcommand we execute for
our tests.
pull/13032/head
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent f77da46b3f
commit 2a414af35f

@ -2,6 +2,7 @@ package packer_test
import (
"fmt"
"os"
"os/exec"
"strings"
"sync"
@ -29,6 +30,16 @@ func (ts *PackerTestSuite) PackerCommand() *packerCommand {
packerPath: ts.packerPath,
env: map[string]string{
"PACKER_LOG": "1",
// Required for Windows, otherwise since we overwrite all
// the envvars for the test and Go relies on that envvar
// being set in order to return another path than
// C:\Windows by default
//
// If we don't have it, Packer immediately errors upon
// invocation as the temporary logfile that we write in
// case of Panic will fail to be created (unless tests
// are running as Administrator, but please don't).
"TMP": os.TempDir(),
},
stderr: stderr,
stdout: stdout,

Loading…
Cancel
Save