From d18689dff71ccbc3b955a4416ae04077356fd5c9 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Sat, 7 Mar 2015 01:03:44 -0800 Subject: [PATCH] integ-cli: also preserve SystemRoot env var Windows CI fails to dial remote test host over tcp in the test cases where we clear environment variables during `exec(dockerBinary, ...)` in the absence of `SystemRoot` environment variable (typically points to `c:\windows`). This fixes tests: - `TestRunEnvironmentErase` - `TestRunEnvironmentOverride` Signed-off-by: Ahmet Alp Balkan --- integration-cli/docker_cli_proxy_test.go | 2 +- integration-cli/docker_cli_run_test.go | 4 ++-- integration-cli/docker_utils.go | 23 +++++++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/integration-cli/docker_cli_proxy_test.go b/integration-cli/docker_cli_proxy_test.go index 98129bdae8..8c41fa9818 100644 --- a/integration-cli/docker_cli_proxy_test.go +++ b/integration-cli/docker_cli_proxy_test.go @@ -9,7 +9,7 @@ import ( func TestCliProxyDisableProxyUnixSock(t *testing.T) { cmd := exec.Command(dockerBinary, "info") - cmd.Env = appendDockerHostEnv([]string{"HTTP_PROXY=http://127.0.0.1:9999"}) + cmd.Env = appendBaseEnv([]string{"HTTP_PROXY=http://127.0.0.1:9999"}) if out, _, err := runCommandWithOutput(cmd); err != nil { t.Fatal(err, out) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 11520d29e5..9869abe745 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -869,7 +869,7 @@ func TestRunEnvironmentErase(t *testing.T) { defer deleteAllContainers() cmd := exec.Command(dockerBinary, "run", "-e", "FOO", "-e", "HOSTNAME", "busybox", "env") - cmd.Env = appendDockerHostEnv([]string{}) + cmd.Env = appendBaseEnv([]string{}) out, _, err := runCommandWithOutput(cmd) if err != nil { @@ -908,7 +908,7 @@ func TestRunEnvironmentOverride(t *testing.T) { defer deleteAllContainers() cmd := exec.Command(dockerBinary, "run", "-e", "HOSTNAME", "-e", "HOME=/root2", "busybox", "env") - cmd.Env = appendDockerHostEnv([]string{"HOSTNAME=bar"}) + cmd.Env = appendBaseEnv([]string{"HOSTNAME=bar"}) out, _, err := runCommandWithOutput(cmd) if err != nil { diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 228c45a6ad..d4c930ee1c 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -919,12 +919,23 @@ func setupRegistry(t *testing.T) func() { return func() { reg.Close() } } -// appendDockerHostEnv adds given env slice DOCKER_HOST value if set in the -// environment. Useful when environment is cleared but we want to preserve DOCKER_HOST -// to execute tests against a remote daemon. -func appendDockerHostEnv(env []string) []string { - if dockerHost := os.Getenv("DOCKER_HOST"); dockerHost != "" { - env = append(env, fmt.Sprintf("DOCKER_HOST=%s", dockerHost)) +// appendBaseEnv appends the minimum set of environment variables to exec the +// docker cli binary for testing with correct configuration to the given env +// list. +func appendBaseEnv(env []string) []string { + preserveList := []string{ + // preserve remote test host + "DOCKER_HOST", + + // windows: requires preserving SystemRoot, otherwise dial tcp fails + // with "GetAddrInfoW: A non-recoverable error occurred during a database lookup." + "SystemRoot", + } + + for _, key := range preserveList { + if val := os.Getenv(key); val != "" { + env = append(env, fmt.Sprintf("%s=%s", key, val)) + } } return env }