diff --git a/pkg/minikube/shell/shell.go b/pkg/minikube/shell/shell.go index 2b5c550310ca..88a479ab5efa 100644 --- a/pkg/minikube/shell/shell.go +++ b/pkg/minikube/shell/shell.go @@ -125,6 +125,17 @@ REM @FOR /f "tokens=*" %%i IN ('%s') DO @%%i `, s...) }, }, + "tcsh": { + prefix: "setenv ", + suffix: "\";\n", + delimiter: " \"", + unsetPrefix: "unsetenv ", + unsetSuffix: ";\n", + unsetDelimiter: "", + usageHint: func(s ...interface{}) string { + return fmt.Sprintf("\n: \"%s\"\n: eval `%s`\n", s...) + }, + }, "none": { prefix: "", suffix: "\n", diff --git a/pkg/minikube/shell/shell_test.go b/pkg/minikube/shell/shell_test.go index cf8de26c2619..30aac5148ab5 100644 --- a/pkg/minikube/shell/shell_test.go +++ b/pkg/minikube/shell/shell_test.go @@ -41,6 +41,7 @@ func TestGenerateUsageHint(t *testing.T) { {EnvConfig{"fish"}, `# foo # bar | source`}, {EnvConfig{"none"}, ``}, + {EnvConfig{"tcsh"}, "\n: \"foo\"\n: eval `bar`\n"}, } for _, tc := range testCases { tc := tc @@ -67,6 +68,7 @@ func TestCfgSet(t *testing.T) { {"", "eval", EnvConfig{"emacs"}, `")`}, {"", "eval", EnvConfig{"none"}, ``}, {"", "eval", EnvConfig{"fish"}, `";`}, + {"", "eval", EnvConfig{"tcsh"}, `";`}, } for _, tc := range testCases { tc := tc @@ -100,6 +102,7 @@ set -e bar;`}, {[]string{"baz", "bar"}, EnvConfig{"emacs"}, `(setenv "baz" nil) (setenv "bar" nil)`}, {[]string{"baz", "bar"}, EnvConfig{"none"}, "baz\nbar"}, + {[]string{"baz", "bar"}, EnvConfig{"tcsh"}, "unsetenv baz;\nunsetenv bar;"}, } for _, tc := range testCases { tc := tc diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 10bee2cbbfd7..fa25d4ddff55 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -467,53 +467,76 @@ func validateDockerEnv(ctx context.Context, t *testing.T, profile string) { t.Skipf("only validate docker env with docker container runtime, currently testing %s", cr) } defer PostMortemLogs(t, profile) - mctx, cancel := context.WithTimeout(ctx, Seconds(120)) - defer cancel() - 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 status after eval-ing docker-env. error: %v", err) + + type ShellTest struct { + name string + commandPrefix []string + formatArg string } - if !strings.Contains(rr.Output(), "Running") { - t.Fatalf("expected status output to include 'Running' after eval docker-env but got: *%s*", rr.Output()) + + windowsTests := []ShellTest{ + {"powershell", []string{"powershell.exe", "-NoProfile", "-NonInteractive"}, "%[1]s -p %[2]s docker-env | Invoke-Expression ; "}, } - if !strings.Contains(rr.Output(), "in-use") { - t.Fatalf("expected status output to include `in-use` after eval docker-env but got *%s*", rr.Output()) + posixTests := []ShellTest{ + {"bash", []string{"/bin/bash", "-c"}, "eval $(%[1]s -p %[2]s docker-env) && "}, } - mctx, cancel = context.WithTimeout(ctx, Seconds(60)) - defer cancel() - // do a eval $(minikube -p profile docker-env) and check if we are point to docker inside minikube - 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) + tests := posixTests + if runtime.GOOS == "windows" { + tests = windowsTests } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + mctx, cancel := context.WithTimeout(ctx, Seconds(120)) + defer cancel() - if mctx.Err() == context.DeadlineExceeded { - t.Errorf("failed to run the command in 30 seconds. exceeded 30s timeout. %s", rr.Command()) - } + command := make([]string, len(tc.commandPrefix)+1) + // Would use "copy" built-in here, but that is shadowed by "copy" package + for i, v := range tc.commandPrefix { + command[i] = v + } - if err != nil { - t.Fatalf("failed to run minikube docker-env. args %q : %v ", rr.Command(), err) - } + formattedArg := fmt.Sprintf(tc.formatArg, Target(), profile) - expectedImgInside := "gcr.io/k8s-minikube/storage-provisioner" - if !strings.Contains(rr.Output(), expectedImgInside) { - t.Fatalf("expected 'docker images' to have %q inside minikube. but the output is: *%s*", expectedImgInside, rr.Output()) + // we should be able to get minikube status with a shell which evaled docker-env + command[len(command)-1] = formattedArg + Target() + " status -p " + profile + c := exec.CommandContext(mctx, command[0], command[1:]...) + 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 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()) + } + if !strings.Contains(rr.Output(), "in-use") { + t.Fatalf("expected status output to include `in-use` after eval docker-env but got *%s*", rr.Output()) + } + + mctx, cancel = context.WithTimeout(ctx, Seconds(60)) + defer cancel() + + // do a eval $(minikube -p profile docker-env) and check if we are point to docker inside minikube + command[len(command)-1] = formattedArg + "docker images" + c = exec.CommandContext(mctx, command[0], command[1:]...) + 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) + } + + expectedImgInside := "gcr.io/k8s-minikube/storage-provisioner" + if !strings.Contains(rr.Output(), expectedImgInside) { + t.Fatalf("expected 'docker images' to have %q inside minikube. but the output is: *%s*", expectedImgInside, rr.Output()) + } + }) } }