From 6c4fbb7738cd9b2ad9776b50e5cabb29a55233f0 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 4 Mar 2019 20:09:34 +0100 Subject: [PATCH] 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: https://github.com/golang/go/blob/e73f4894949c4ced611881329ff8f37805152585/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 --- e2e/plugin/trust_test.go | 2 +- scripts/test/e2e/run | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e/plugin/trust_test.go b/e2e/plugin/trust_test.go index 8dc3cad87aca..36a602de8e28 100644 --- a/e2e/plugin/trust_test.go +++ b/e2e/plugin/trust_test.go @@ -106,7 +106,7 @@ func ensureBasicPluginBin() (string, error) { } installPath := filepath.Join(os.Getenv("GOPATH"), "bin", name) 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 { return "", errors.Wrapf(err, "error building basic plugin bin: %s", string(out)) } diff --git a/scripts/test/e2e/run b/scripts/test/e2e/run index bdff2ce3e34e..846e29d327e8 100755 --- a/scripts/test/e2e/run +++ b/scripts/test/e2e/run @@ -69,6 +69,7 @@ function runtests { TEST_SKIP_PLUGIN_TESTS="${SKIP_PLUGIN_TESTS-}" \ GOPATH="$GOPATH" \ 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" \ "$(which gotestsum)" -- ./e2e/... ${TESTFLAGS-} }