2016-04-29 23:18:49 +00:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
/*
|
2016-05-01 15:49:51 +00:00
|
|
|
Copyright 2016 The Kubernetes Authors All rights reserved.
|
2016-05-02 17:37:01 +00:00
|
|
|
|
2016-04-29 23:18:49 +00:00
|
|
|
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
|
2016-05-02 17:37:01 +00:00
|
|
|
|
2016-04-29 23:18:49 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2016-05-02 17:37:01 +00:00
|
|
|
|
2016-04-29 23:18:49 +00:00
|
|
|
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 (
|
|
|
|
"flag"
|
2016-05-04 21:31:32 +00:00
|
|
|
"os"
|
2016-04-29 23:18:49 +00:00
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-05-05 13:47:36 +00:00
|
|
|
var binaryPath = flag.String("binary", "../../out/minikube", "path to minikube binary")
|
2016-04-29 23:18:49 +00:00
|
|
|
|
|
|
|
func runCommand(t *testing.T, command string, checkError bool) string {
|
|
|
|
path, _ := filepath.Abs(*binaryPath)
|
|
|
|
cmd := exec.Command(path, command)
|
|
|
|
stdout, err := cmd.Output()
|
|
|
|
|
|
|
|
if checkError && err != nil {
|
2016-05-04 21:31:32 +00:00
|
|
|
t.Fatalf("Error running command: %s %s. Output: %s", command, err, stdout)
|
2016-04-29 23:18:49 +00:00
|
|
|
}
|
|
|
|
return string(stdout)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStartStop(t *testing.T) {
|
|
|
|
|
|
|
|
getStatus := func() string {
|
|
|
|
status := runCommand(t, "status", true)
|
|
|
|
return strings.Trim(status, "\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
checkStatus := func(desired string) {
|
|
|
|
s := getStatus()
|
|
|
|
if s != desired {
|
|
|
|
t.Fatalf("Machine is in the wrong state: %s, expected %s", s, desired)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
runCommand(t, "delete", false)
|
|
|
|
checkStatus("Does Not Exist")
|
|
|
|
|
|
|
|
runCommand(t, "start", true)
|
|
|
|
checkStatus("Running")
|
|
|
|
|
|
|
|
runCommand(t, "stop", true)
|
|
|
|
checkStatus("Stopped")
|
|
|
|
|
|
|
|
runCommand(t, "start", true)
|
|
|
|
checkStatus("Running")
|
|
|
|
|
|
|
|
runCommand(t, "delete", true)
|
|
|
|
checkStatus("Does Not Exist")
|
|
|
|
}
|
2016-05-04 21:31:32 +00:00
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
flag.Parse()
|
|
|
|
os.Exit(m.Run())
|
|
|
|
}
|