Fix up the docker-env integration test.

pull/305/head
Dan Lorenc 2016-07-09 11:05:14 -07:00
parent 5c52d6f184
commit 0334d223d1
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"
@ -65,17 +66,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
}