Merge pull request #305 from dlorenc/env

Fix up the docker-env integration test.
pull/306/head
dlorenc 2016-07-09 12:35:56 -07:00 committed by GitHub
commit b18739dc14
2 changed files with 10 additions and 10 deletions

View File

@ -36,7 +36,7 @@ func TestClusterEnv(t *testing.T) {
dockerEnvVars := minikubeRunner.RunCommand("docker-env", true)
if err := minikubeRunner.SetEnvFromEnvCmdOutput(dockerEnvVars); err != nil {
t.Fatalf("Error: No environment variables were found in docker-env command output: ", dockerEnvVars)
t.Fatalf("Error parsing output: %s", err)
}
path, err := exec.LookPath("docker")

View File

@ -26,6 +26,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"testing"
"time"
@ -67,17 +68,16 @@ func (m *MinikubeRunner) EnsureRunning() {
}
func (m *MinikubeRunner) SetEnvFromEnvCmdOutput(dockerEnvVars string) error {
lines := strings.Split(dockerEnvVars, "\n")
var envKey, envVal string
re := regexp.MustCompile("export (.+?)=(.+?)\n")
matches := re.FindAllStringSubmatch(dockerEnvVars, -1)
seenEnvVar := false
for _, line := range lines {
if _, err := fmt.Sscanf(line, "export %s=%s", envKey, envVal); err != nil {
seenEnvVar = true
os.Setenv(envKey, envVal)
}
for _, m := range matches {
seenEnvVar = true
key, val := m[1], m[2]
os.Setenv(key, val)
}
if seenEnvVar == false {
return fmt.Errorf("Error: No environment variables were found in docker-env command output: ", dockerEnvVars)
if !seenEnvVar {
return fmt.Errorf("Error: No environment variables were found in docker-env command output: %s", dockerEnvVars)
}
return nil
}