get profile names automaticly from test names
parent
d8d140f495
commit
dabd0c41d4
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
package integration
|
||||
|
||||
// this file name has to start with a so it be run before all other tests
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -26,7 +26,7 @@ import (
|
|||
// TestDownloadOnly downloads ISOs also tests the --download-only option
|
||||
// Note this test runs before all tests (because of file name) and caches images for them
|
||||
func TestDownloadOnly(t *testing.T) {
|
||||
p := t.Name()
|
||||
p := profile(t)
|
||||
if isTestNoneDriver() {
|
||||
t.Skip()
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
)
|
||||
|
||||
func TestContainerd(t *testing.T) {
|
||||
p := t.Name()
|
||||
p := profile(t)
|
||||
if isTestNoneDriver() {
|
||||
p = "minikube"
|
||||
} else {
|
||||
|
@ -49,7 +49,7 @@ func TestContainerd(t *testing.T) {
|
|||
}
|
||||
|
||||
func testGvisor(t *testing.T) {
|
||||
p := "TestContainerd"
|
||||
p := profile(t)
|
||||
mk := NewMinikubeRunner(t, p, "--wait=false")
|
||||
mk.RunCommand("addons enable gvisor", true)
|
||||
|
||||
|
@ -82,7 +82,7 @@ func testGvisor(t *testing.T) {
|
|||
}
|
||||
|
||||
func testGvisorRestart(t *testing.T) {
|
||||
p := "TestContainerd"
|
||||
p := profile(t)
|
||||
mk := NewMinikubeRunner(t, p, "--wait=false")
|
||||
mk.EnsureRunning()
|
||||
mk.RunCommand("addons enable gvisor", true)
|
||||
|
|
|
@ -28,7 +28,7 @@ import (
|
|||
)
|
||||
|
||||
func TestDocker(t *testing.T) {
|
||||
p := t.Name()
|
||||
p := profile(t)
|
||||
if isTestNoneDriver() {
|
||||
p = "minikube"
|
||||
} else {
|
||||
|
|
|
@ -53,3 +53,13 @@ func NewMinikubeRunner(t *testing.T, profile string, extraStartArgs ...string) u
|
|||
func isTestNoneDriver() bool {
|
||||
return strings.Contains(*startArgs, "--vm-driver=none")
|
||||
}
|
||||
|
||||
// profile chooses a profile name based on the test name
|
||||
// for i.e, TestFunctional/SSH returns TestFunctional
|
||||
func profile(t *testing.T) string {
|
||||
p := profile(t)
|
||||
if strings.Contains(p, "/") {
|
||||
p = strings.Split(p, "/")[0]
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
)
|
||||
|
||||
func TestISO(t *testing.T) {
|
||||
p := t.Name()
|
||||
p := profile(t)
|
||||
if isTestNoneDriver() {
|
||||
p = "minikube"
|
||||
} else {
|
||||
|
@ -45,7 +45,7 @@ func TestISO(t *testing.T) {
|
|||
}
|
||||
|
||||
func testMountPermissions(t *testing.T) {
|
||||
p := "TestISO"
|
||||
p := profile(t)
|
||||
mk := NewMinikubeRunner(t, p, "--wait=false")
|
||||
// test mount permissions
|
||||
mountPoints := []string{"/Users", "/hosthome"}
|
||||
|
@ -68,7 +68,7 @@ func testMountPermissions(t *testing.T) {
|
|||
}
|
||||
|
||||
func testPackages(t *testing.T) {
|
||||
p := "TestISO"
|
||||
p := profile(t)
|
||||
mk := NewMinikubeRunner(t, p, "--wait=false")
|
||||
|
||||
packages := []string{
|
||||
|
@ -91,7 +91,7 @@ func testPackages(t *testing.T) {
|
|||
}
|
||||
|
||||
func testPersistence(t *testing.T) {
|
||||
p := "TestISO"
|
||||
p := profile(t)
|
||||
mk := NewMinikubeRunner(t, p, "--wait=false")
|
||||
|
||||
for _, dir := range []string{
|
||||
|
|
|
@ -28,7 +28,7 @@ import (
|
|||
)
|
||||
|
||||
func TestPersistence(t *testing.T) {
|
||||
p := t.Name() // profile name
|
||||
p := profile(t) // profile name
|
||||
if isTestNoneDriver() {
|
||||
p = "minikube"
|
||||
} else {
|
||||
|
|
|
@ -72,7 +72,7 @@ func TestProxy(t *testing.T) {
|
|||
}
|
||||
|
||||
// making sure there is no running minikube to avoid https://github.com/kubernetes/minikube/issues/4132
|
||||
p := t.Name()
|
||||
p := profile(t)
|
||||
mk := NewMinikubeRunner(t, p)
|
||||
|
||||
// Clean up after setting up proxy
|
||||
|
@ -100,7 +100,7 @@ func TestProxy(t *testing.T) {
|
|||
|
||||
// testProxyWarning checks user is warned correctly about the proxy related env vars
|
||||
func testProxyWarning(t *testing.T) {
|
||||
p := "TestProxy"
|
||||
p := profile(t)
|
||||
mk := NewMinikubeRunner(t, p)
|
||||
stdout, stderr, err := mk.StartWithStds(15 * time.Minute)
|
||||
if err != nil {
|
||||
|
@ -120,7 +120,7 @@ func testProxyWarning(t *testing.T) {
|
|||
|
||||
// testProxyDashboard checks if dashboard URL is accessible if proxy is set
|
||||
func testProxyDashboard(t *testing.T) {
|
||||
p := "TestProxy" // profile name
|
||||
p := profile(t) // profile name
|
||||
if isTestNoneDriver() {
|
||||
p = "minikube"
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import (
|
|||
)
|
||||
|
||||
func TestStartStop(t *testing.T) {
|
||||
p := "TestStartStop" // profile name
|
||||
p := profile(t) // profile name
|
||||
if isTestNoneDriver() {
|
||||
p = "minikube"
|
||||
} else {
|
||||
|
|
|
@ -60,7 +60,12 @@ func (m *MinikubeRunner) Remove(f assets.CopyableFile) error {
|
|||
}
|
||||
|
||||
// teeRun runs a command, streaming stdout, stderr to console
|
||||
func (m *MinikubeRunner) teeRun(cmd *exec.Cmd) (string, string, error) {
|
||||
func (m *MinikubeRunner) teeRun(cmd *exec.Cmd, wait ...bool) (string, string, error) {
|
||||
w := true
|
||||
if wait != nil {
|
||||
w = wait[0]
|
||||
}
|
||||
|
||||
errPipe, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
|
@ -73,29 +78,33 @@ func (m *MinikubeRunner) teeRun(cmd *exec.Cmd) (string, string, error) {
|
|||
if err := cmd.Start(); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
var outB bytes.Buffer
|
||||
var errB bytes.Buffer
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
if err := commonutil.TeePrefix(commonutil.ErrPrefix, errPipe, &errB, Logf); err != nil {
|
||||
m.T.Logf("tee: %v", err)
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
go func() {
|
||||
if err := commonutil.TeePrefix(commonutil.OutPrefix, outPipe, &outB, Logf); err != nil {
|
||||
m.T.Logf("tee: %v", err)
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
err = cmd.Wait()
|
||||
wg.Wait()
|
||||
return outB.String(), errB.String(), err
|
||||
if w {
|
||||
var outB bytes.Buffer
|
||||
var errB bytes.Buffer
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
if err := commonutil.TeePrefix(commonutil.ErrPrefix, errPipe, &errB, Logf); err != nil {
|
||||
m.T.Logf("tee: %v", err)
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
go func() {
|
||||
if err := commonutil.TeePrefix(commonutil.OutPrefix, outPipe, &outB, Logf); err != nil {
|
||||
m.T.Logf("tee: %v", err)
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
err = cmd.Wait()
|
||||
wg.Wait()
|
||||
return outB.String(), errB.String(), err
|
||||
|
||||
}
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
// RunCommand executes a command, optionally checking for error
|
||||
func (m *MinikubeRunner) RunCommand(cmdStr string, failError bool) string {
|
||||
func (m *MinikubeRunner) RunCommand(cmdStr string, failError bool, wait ...bool) string {
|
||||
profileArg := fmt.Sprintf("-p=%s ", m.Profile)
|
||||
cmdStr = profileArg + cmdStr
|
||||
cmdArgs := strings.Split(cmdStr, " ")
|
||||
|
@ -103,7 +112,7 @@ func (m *MinikubeRunner) RunCommand(cmdStr string, failError bool) string {
|
|||
|
||||
cmd := exec.Command(path, cmdArgs...)
|
||||
Logf("Run: %s", cmd.Args)
|
||||
stdout, stderr, err := m.teeRun(cmd)
|
||||
stdout, stderr, err := m.teeRun(cmd, wait...)
|
||||
if failError && err != nil {
|
||||
if exitError, ok := err.(*exec.ExitError); ok {
|
||||
m.T.Fatalf("Error running command: %s %s. Output: %s", cmdStr, exitError.Stderr, stdout)
|
||||
|
@ -115,7 +124,7 @@ func (m *MinikubeRunner) RunCommand(cmdStr string, failError bool) string {
|
|||
}
|
||||
|
||||
// RunWithContext calls the minikube command with a context, useful for timeouts.
|
||||
func (m *MinikubeRunner) RunWithContext(ctx context.Context, cmdStr string) (string, string, error) {
|
||||
func (m *MinikubeRunner) RunWithContext(ctx context.Context, cmdStr string, wait ...bool) (string, string, error) {
|
||||
profileArg := fmt.Sprintf("-p=%s ", m.Profile)
|
||||
cmdStr = profileArg + cmdStr
|
||||
cmdArgs := strings.Split(cmdStr, " ")
|
||||
|
@ -123,7 +132,7 @@ func (m *MinikubeRunner) RunWithContext(ctx context.Context, cmdStr string) (str
|
|||
|
||||
cmd := exec.CommandContext(ctx, path, cmdArgs...)
|
||||
Logf("Run: %s", cmd.Args)
|
||||
return m.teeRun(cmd)
|
||||
return m.teeRun(cmd, wait...)
|
||||
}
|
||||
|
||||
// RunDaemon executes a command, returning the stdout
|
||||
|
|
|
@ -72,7 +72,7 @@ func fileExists(fname string) error {
|
|||
// the odlest supported k8s version and then runs the current head minikube
|
||||
// and it tries to upgrade from the older supported k8s to news supported k8s
|
||||
func TestVersionUpgrade(t *testing.T) {
|
||||
p := t.Name()
|
||||
p := profile(t)
|
||||
if isTestNoneDriver() {
|
||||
p = "minikube"
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue