Skip to content

Commit

Permalink
Merge pull request #8265 from medyagh/docker-env-windows
Browse files Browse the repository at this point in the history
integration tests: fix docker-env test in powershell
  • Loading branch information
medyagh authored May 27, 2020
2 parents 995cde8 + c861d4a commit c77959a
Showing 1 changed file with 55 additions and 13 deletions.
68 changes: 55 additions & 13 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,43 @@ func validateNodeLabels(ctx context.Context, t *testing.T, profile string) {
// check functionality of minikube after evaling docker-env
func validateDockerEnv(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)

mctx, cancel := context.WithTimeout(ctx, Seconds(13))
mctx, cancel := context.WithTimeout(ctx, Seconds(30))
defer cancel()
// we should be able to get minikube status with a bash which evaled docker-env
c := exec.CommandContext(mctx, "/bin/bash", "-c", "eval $("+Target()+" -p "+profile+" docker-env) && "+Target()+" status -p "+profile)
rr, err := Run(t, c)
var rr *RunResult
var err error
if runtime.GOOS == "windows" {
c := exec.CommandContext(mctx, "powershell.exe", "-NoProfile", "-NonInteractive", Target()+" -p "+profile+" docker-env | Invoke-Expression ;"+Target()+" status -p "+profile)
rr, err = Run(t, c)
} else {
c := exec.CommandContext(mctx, "/bin/bash", "-c", "eval $("+Target()+" -p "+profile+" docker-env) && "+Target()+" status -p "+profile)
// we should be able to get minikube status with a bash which evaled docker-env
rr, err = Run(t, c)
}
if mctx.Err() == context.DeadlineExceeded {
t.Errorf("failed to run the command by deadline. exceeded timeout. %s", rr.Command())
}
if err != nil {
t.Fatalf("failed to do minikube status after eval-ing docker-env %s", err)
t.Fatalf("failed to do status after eval-ing docker-env. error: %v", err)
}
if !strings.Contains(rr.Output(), "Running") {
t.Fatalf("expected status output to include 'Running' after eval docker-env but got: *%s*", rr.Output())
}

mctx, cancel = context.WithTimeout(ctx, Seconds(13))
mctx, cancel = context.WithTimeout(ctx, Seconds(30))
defer cancel()
// do a eval $(minikube -p profile docker-env) and check if we are point to docker inside minikube
c = exec.CommandContext(mctx, "/bin/bash", "-c", "eval $("+Target()+" -p "+profile+" docker-env) && docker images")
rr, err = Run(t, c)
if runtime.GOOS == "windows" { // testing docker-env eval in powershell
c := exec.CommandContext(mctx, "powershell.exe", "-NoProfile", "-NonInteractive", Target(), "-p "+profile+" docker-env | Invoke-Expression ; docker images")
rr, err = Run(t, c)
} else {
c := exec.CommandContext(mctx, "/bin/bash", "-c", "eval $("+Target()+" -p "+profile+" docker-env) && docker images")
rr, err = Run(t, c)
}

if mctx.Err() == context.DeadlineExceeded {
t.Errorf("failed to run the command in 30 seconds. exceeded 30s timeout. %s", rr.Command())
}

if err != nil {
t.Fatalf("failed to run minikube docker-env. args %q : %v ", rr.Command(), err)
}
Expand Down Expand Up @@ -319,7 +338,6 @@ func validateComponentHealth(ctx context.Context, t *testing.T, profile string)

func validateStatusCmd(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)

rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "status"))
if err != nil {
t.Errorf("failed to run minikube status. args %q : %v", rr.Command(), err)
Expand Down Expand Up @@ -507,7 +525,8 @@ func validateCacheCmd(ctx context.Context, t *testing.T, profile string) {
t.Run("cache_reload", func(t *testing.T) { // deleting image inside minikube node manually and expecting reload to bring it back
img := "busybox:latest"
// deleting image inside minikube node manually
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "sudo", "docker", "rmi", img)) // for some reason crictl rmi doesn't work
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "sudo", "docker", "rmi", img))

if err != nil {
t.Errorf("failed to delete inside the node %q : %v", rr.Command(), err)
}
Expand Down Expand Up @@ -812,12 +831,35 @@ func validateAddonsCmd(ctx context.Context, t *testing.T, profile string) {
// validateSSHCmd asserts basic "ssh" command functionality
func validateSSHCmd(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)

if NoneDriver() {
t.Skipf("skipping: ssh unsupported by none")
}
mctx, cancel := context.WithTimeout(ctx, Minutes(1))
defer cancel()

want := "hello\n"
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", fmt.Sprintf("echo hello")))

rr, err := Run(t, exec.CommandContext(mctx, Target(), "-p", profile, "ssh", "echo hello"))
if mctx.Err() == context.DeadlineExceeded {
t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command())
}
if err != nil {
t.Errorf("failed to run an ssh command. args %q : %v", rr.Command(), err)
}
if rr.Stdout.String() != want {
t.Errorf("expected minikube ssh command output to be -%q- but got *%q*. args %q", want, rr.Stdout.String(), rr.Command())
}

// testing hostname as well because testing something like "minikube ssh echo" could be confusing
// because it is not clear if echo was run inside minikube on the powershell
// so better to test something inside minikube, that is meaningful per profile
// in this case /etc/hostname is same as the profile name
want = profile + "\n"
rr, err = Run(t, exec.CommandContext(mctx, Target(), "-p", profile, "ssh", "cat /etc/hostname"))
if mctx.Err() == context.DeadlineExceeded {
t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command())
}

if err != nil {
t.Errorf("failed to run an ssh command. args %q : %v", rr.Command(), err)
}
Expand Down

0 comments on commit c77959a

Please sign in to comment.