Added env command integration test
parent
c993bf8cca
commit
5b67cb5c14
|
@ -0,0 +1,42 @@
|
|||
// +build integration
|
||||
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"k8s.io/minikube/test/integration/util"
|
||||
"os/exec"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestClusterEnv(t *testing.T) {
|
||||
minikubeRunner := util.MinikubeRunner{BinaryPath: *binaryPath, T: t}
|
||||
minikubeRunner.RunCommand("start", true)
|
||||
minikubeRunner.CheckStatus("Running")
|
||||
|
||||
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)
|
||||
}
|
||||
path, err := exec.LookPath("docker")
|
||||
cmd := exec.Command(path, "ps")
|
||||
stdout, err := cmd.Output()
|
||||
if err != nil {
|
||||
t.Fatalf("Error running command: %s. Output: %s", "docker ps", err, stdout)
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ import (
|
|||
"k8s.io/minikube/test/integration/util"
|
||||
)
|
||||
|
||||
func TestCluster(t *testing.T) {
|
||||
func TestClusterStatus(t *testing.T) {
|
||||
minikubeRunner := util.MinikubeRunner{BinaryPath: *binaryPath, T: t}
|
||||
minikubeRunner.RunCommand("start", true)
|
||||
minikubeRunner.CheckStatus("Running")
|
||||
|
|
|
@ -21,6 +21,8 @@ package util
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -43,6 +45,22 @@ func (m *MinikubeRunner) RunCommand(command string, checkError bool) string {
|
|||
return string(stdout)
|
||||
}
|
||||
|
||||
func (m *MinikubeRunner) SetEnvFromEnvCmdOutput(dockerEnvVars string) error {
|
||||
lines := strings.Split(dockerEnvVars, "\n")
|
||||
var envKey, envVal string
|
||||
seenEnvVar := false
|
||||
for _, line := range lines {
|
||||
if _, err := fmt.Sscanf(line, "export %s=%s", envKey, envVal); err != nil {
|
||||
seenEnvVar = true
|
||||
os.Setenv(envKey, envVal)
|
||||
}
|
||||
}
|
||||
if seenEnvVar == false {
|
||||
return fmt.Errorf("Error: No environment variables were found in docker-env command output: ", dockerEnvVars)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MinikubeRunner) GetStatus() string {
|
||||
status := m.RunCommand("status", true)
|
||||
return strings.Trim(status, "\n")
|
||||
|
|
Loading…
Reference in New Issue