Fix: plugin-tests discarding current environment

By default, exec uses the environment of the current process, however,
if `exec.Env` is not `nil`, the environment is discarded:

e73f489494/src/os/exec/exec.go (L57-L60)

> If Env is nil, the new process uses the current process's environment.

When adding a new environment variable, prepend the current environment,
to make sure it is not discarded.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-03-04 20:09:34 +01:00
parent 8ddde26af6
commit 6c4fbb7738
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 2 additions and 1 deletions

View File

@ -106,7 +106,7 @@ func ensureBasicPluginBin() (string, error) {
} }
installPath := filepath.Join(os.Getenv("GOPATH"), "bin", name) installPath := filepath.Join(os.Getenv("GOPATH"), "bin", name)
cmd := exec.Command(goBin, "build", "-o", installPath, "./basic") cmd := exec.Command(goBin, "build", "-o", installPath, "./basic")
cmd.Env = append(cmd.Env, "CGO_ENABLED=0") cmd.Env = append(os.Environ(), "CGO_ENABLED=0")
if out, err := cmd.CombinedOutput(); err != nil { if out, err := cmd.CombinedOutput(); err != nil {
return "", errors.Wrapf(err, "error building basic plugin bin: %s", string(out)) return "", errors.Wrapf(err, "error building basic plugin bin: %s", string(out))
} }

View File

@ -69,6 +69,7 @@ function runtests {
TEST_SKIP_PLUGIN_TESTS="${SKIP_PLUGIN_TESTS-}" \ TEST_SKIP_PLUGIN_TESTS="${SKIP_PLUGIN_TESTS-}" \
GOPATH="$GOPATH" \ GOPATH="$GOPATH" \
PATH="$PWD/build/:/usr/bin:/usr/local/bin:/usr/local/go/bin" \ PATH="$PWD/build/:/usr/bin:/usr/local/bin:/usr/local/go/bin" \
HOME="$HOME" \
DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS="$PWD/build/plugins-linux-amd64" \ DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS="$PWD/build/plugins-linux-amd64" \
"$(which gotestsum)" -- ./e2e/... ${TESTFLAGS-} "$(which gotestsum)" -- ./e2e/... ${TESTFLAGS-}
} }