From 779638f8888bfe2cca188a0b9e92f9aeefbc0ebc Mon Sep 17 00:00:00 2001 From: Roman Orlov Date: Tue, 10 Oct 2017 07:52:12 +0300 Subject: [PATCH] Fix issue in cm (#84) Excluding Windows variables breaking Docker container startup (related to #81) * Add tests for validEnviron * fixes #81 --- selenoid/docker.go | 13 ++++++++++++- selenoid/docker_test.go | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/selenoid/docker.go b/selenoid/docker.go index 9cdfc24..f81595f 100644 --- a/selenoid/docker.go +++ b/selenoid/docker.go @@ -518,8 +518,19 @@ func (c *DockerConfigurator) StartUI() error { return c.startContainer(selenoidUIContainerName, image, selenoidUIContainerPort, []string{}, links, cmd, overrideEnv) } +func validateEnviron(envs []string) []string { + validEnv := []string{} + for _, e := range envs { + k := strings.Split(e, "=") + if len(k[0]) != 0 { + validEnv = append(validEnv, e) + } + } + return validEnv +} + func (c *DockerConfigurator) startContainer(name string, image *types.ImageSummary, forwardedPort int, volumes []string, links []string, cmd []string, envOverride []string) error { - env := os.Environ() + env := validateEnviron(os.Environ()) env = append(env, fmt.Sprintf("TZ=%s", time.Local)) if len(envOverride) > 0 { env = envOverride diff --git a/selenoid/docker_test.go b/selenoid/docker_test.go index 6a476a6..08f9590 100644 --- a/selenoid/docker_test.go +++ b/selenoid/docker_test.go @@ -394,3 +394,8 @@ func TestPostProcessPath(t *testing.T) { AssertThat(t, postProcessPath("1"), EqualTo{"1"}) AssertThat(t, postProcessPath(""), EqualTo{""}) } + +func TestValidEnviron(t *testing.T) { + AssertThat(t, validateEnviron([]string{"=::=::"}), EqualTo{[]string{}}) + AssertThat(t, validateEnviron([]string{"HOMEDRIVE=C:", "DOCKER_HOST=192.168.0.1" , "=::=::"}), EqualTo{[]string{"HOMEDRIVE=C:", "DOCKER_HOST=192.168.0.1"}}) + }