From 4f377fbe9f30ea44be5e10a0c7b9bc3c6eb421b1 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Thu, 12 Feb 2015 11:20:48 -0800 Subject: [PATCH] docker_cli_run_test: Preserve DOCKER_TEST_HOST in env-clearing tests For Windows, we run integration-cli with DOCKER_TEST_HOST env var b/c daemon is on some remote machine. This keeps the DOCKER_HOST set by bash scripts in the env. Signed-off-by: Ahmet Alp Balkan --- integration-cli/docker_cli_run_test.go | 6 ++++-- integration-cli/docker_utils.go | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 0c144cdc9c..38df35ef62 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -862,7 +862,8 @@ func TestRunEnvironmentErase(t *testing.T) { // not set in our local env that they're removed (if present) in // the container cmd := exec.Command(dockerBinary, "run", "-e", "FOO", "-e", "HOSTNAME", "busybox", "env") - cmd.Env = []string{} + cmd.Env = appendDockerHostEnv([]string{}) + out, _, err := runCommandWithOutput(cmd) if err != nil { t.Fatal(err, out) @@ -900,7 +901,8 @@ func TestRunEnvironmentOverride(t *testing.T) { // Test to make sure that when we use -e on env vars that are // already in the env that we're overriding them cmd := exec.Command(dockerBinary, "run", "-e", "HOSTNAME", "-e", "HOME=/root2", "busybox", "env") - cmd.Env = []string{"HOSTNAME=bar"} + cmd.Env = appendDockerHostEnv([]string{"HOSTNAME=bar"}) + out, _, err := runCommandWithOutput(cmd) if err != nil { t.Fatal(err, out) diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 35a97feca7..59fc300074 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -893,3 +893,13 @@ 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)) + } + return env +}