Fix up the docker-env integration test.
parent
5c52d6f184
commit
0334d223d1
|
@ -36,7 +36,7 @@ func TestClusterEnv(t *testing.T) {
|
||||||
|
|
||||||
dockerEnvVars := minikubeRunner.RunCommand("docker-env", true)
|
dockerEnvVars := minikubeRunner.RunCommand("docker-env", true)
|
||||||
if err := minikubeRunner.SetEnvFromEnvCmdOutput(dockerEnvVars); err != nil {
|
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")
|
path, err := exec.LookPath("docker")
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -65,17 +66,16 @@ func (m *MinikubeRunner) EnsureRunning() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MinikubeRunner) SetEnvFromEnvCmdOutput(dockerEnvVars string) error {
|
func (m *MinikubeRunner) SetEnvFromEnvCmdOutput(dockerEnvVars string) error {
|
||||||
lines := strings.Split(dockerEnvVars, "\n")
|
re := regexp.MustCompile("export (.+?)=(.+?)\n")
|
||||||
var envKey, envVal string
|
matches := re.FindAllStringSubmatch(dockerEnvVars, -1)
|
||||||
seenEnvVar := false
|
seenEnvVar := false
|
||||||
for _, line := range lines {
|
for _, m := range matches {
|
||||||
if _, err := fmt.Sscanf(line, "export %s=%s", envKey, envVal); err != nil {
|
|
||||||
seenEnvVar = true
|
seenEnvVar = true
|
||||||
os.Setenv(envKey, envVal)
|
key, val := m[1], m[2]
|
||||||
|
os.Setenv(key, val)
|
||||||
}
|
}
|
||||||
}
|
if !seenEnvVar {
|
||||||
if seenEnvVar == false {
|
return fmt.Errorf("Error: No environment variables were found in docker-env command output: %s", dockerEnvVars)
|
||||||
return fmt.Errorf("Error: No environment variables were found in docker-env command output: ", dockerEnvVars)
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue