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 <ahmetalpbalkan@gmail.com>
| ... | ... |
@@ -862,7 +862,8 @@ func TestRunEnvironmentErase(t *testing.T) {
|
| 862 | 862 |
// not set in our local env that they're removed (if present) in |
| 863 | 863 |
// the container |
| 864 | 864 |
cmd := exec.Command(dockerBinary, "run", "-e", "FOO", "-e", "HOSTNAME", "busybox", "env") |
| 865 |
- cmd.Env = []string{}
|
|
| 865 |
+ cmd.Env = appendDockerHostEnv([]string{})
|
|
| 866 |
+ |
|
| 866 | 867 |
out, _, err := runCommandWithOutput(cmd) |
| 867 | 868 |
if err != nil {
|
| 868 | 869 |
t.Fatal(err, out) |
| ... | ... |
@@ -900,7 +901,8 @@ func TestRunEnvironmentOverride(t *testing.T) {
|
| 900 | 900 |
// Test to make sure that when we use -e on env vars that are |
| 901 | 901 |
// already in the env that we're overriding them |
| 902 | 902 |
cmd := exec.Command(dockerBinary, "run", "-e", "HOSTNAME", "-e", "HOME=/root2", "busybox", "env") |
| 903 |
- cmd.Env = []string{"HOSTNAME=bar"}
|
|
| 903 |
+ cmd.Env = appendDockerHostEnv([]string{"HOSTNAME=bar"})
|
|
| 904 |
+ |
|
| 904 | 905 |
out, _, err := runCommandWithOutput(cmd) |
| 905 | 906 |
if err != nil {
|
| 906 | 907 |
t.Fatal(err, out) |
| ... | ... |
@@ -893,3 +893,13 @@ func setupRegistry(t *testing.T) func() {
|
| 893 | 893 |
|
| 894 | 894 |
return func() { reg.Close() }
|
| 895 | 895 |
} |
| 896 |
+ |
|
| 897 |
+// appendDockerHostEnv adds given env slice DOCKER_HOST value if set in the |
|
| 898 |
+// environment. Useful when environment is cleared but we want to preserve DOCKER_HOST |
|
| 899 |
+// to execute tests against a remote daemon. |
|
| 900 |
+func appendDockerHostEnv(env []string) []string {
|
|
| 901 |
+ if dockerHost := os.Getenv("DOCKER_HOST"); dockerHost != "" {
|
|
| 902 |
+ env = append(env, fmt.Sprintf("DOCKER_HOST=%s", dockerHost))
|
|
| 903 |
+ } |
|
| 904 |
+ return env |
|
| 905 |
+} |