Skip to content

Commit 2bb50e4

Browse files
Merge pull request #12332 from andriyDev/TCSHEnvSupport
Add support for tcsh in docker-env subcommand
2 parents 43de46d + 79fa08b commit 2bb50e4

File tree

3 files changed

+76
-39
lines changed

3 files changed

+76
-39
lines changed

pkg/minikube/shell/shell.go

+11
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ REM @FOR /f "tokens=*" %%i IN ('%s') DO @%%i
125125
`, s...)
126126
},
127127
},
128+
"tcsh": {
129+
prefix: "setenv ",
130+
suffix: "\";\n",
131+
delimiter: " \"",
132+
unsetPrefix: "unsetenv ",
133+
unsetSuffix: ";\n",
134+
unsetDelimiter: "",
135+
usageHint: func(s ...interface{}) string {
136+
return fmt.Sprintf("\n: \"%s\"\n: eval `%s`\n", s...)
137+
},
138+
},
128139
"none": {
129140
prefix: "",
130141
suffix: "\n",

pkg/minikube/shell/shell_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestGenerateUsageHint(t *testing.T) {
4141
{EnvConfig{"fish"}, `# foo
4242
# bar | source`},
4343
{EnvConfig{"none"}, ``},
44+
{EnvConfig{"tcsh"}, "\n: \"foo\"\n: eval `bar`\n"},
4445
}
4546
for _, tc := range testCases {
4647
tc := tc
@@ -67,6 +68,7 @@ func TestCfgSet(t *testing.T) {
6768
{"", "eval", EnvConfig{"emacs"}, `")`},
6869
{"", "eval", EnvConfig{"none"}, ``},
6970
{"", "eval", EnvConfig{"fish"}, `";`},
71+
{"", "eval", EnvConfig{"tcsh"}, `";`},
7072
}
7173
for _, tc := range testCases {
7274
tc := tc
@@ -100,6 +102,7 @@ set -e bar;`},
100102
{[]string{"baz", "bar"}, EnvConfig{"emacs"}, `(setenv "baz" nil)
101103
(setenv "bar" nil)`},
102104
{[]string{"baz", "bar"}, EnvConfig{"none"}, "baz\nbar"},
105+
{[]string{"baz", "bar"}, EnvConfig{"tcsh"}, "unsetenv baz;\nunsetenv bar;"},
103106
}
104107
for _, tc := range testCases {
105108
tc := tc

test/integration/functional_test.go

+62-39
Original file line numberDiff line numberDiff line change
@@ -467,53 +467,76 @@ func validateDockerEnv(ctx context.Context, t *testing.T, profile string) {
467467
t.Skipf("only validate docker env with docker container runtime, currently testing %s", cr)
468468
}
469469
defer PostMortemLogs(t, profile)
470-
mctx, cancel := context.WithTimeout(ctx, Seconds(120))
471-
defer cancel()
472-
var rr *RunResult
473-
var err error
474-
if runtime.GOOS == "windows" {
475-
c := exec.CommandContext(mctx, "powershell.exe", "-NoProfile", "-NonInteractive", Target()+" -p "+profile+" docker-env | Invoke-Expression ;"+Target()+" status -p "+profile)
476-
rr, err = Run(t, c)
477-
} else {
478-
c := exec.CommandContext(mctx, "/bin/bash", "-c", "eval $("+Target()+" -p "+profile+" docker-env) && "+Target()+" status -p "+profile)
479-
// we should be able to get minikube status with a bash which evaled docker-env
480-
rr, err = Run(t, c)
481-
}
482-
if mctx.Err() == context.DeadlineExceeded {
483-
t.Errorf("failed to run the command by deadline. exceeded timeout. %s", rr.Command())
484-
}
485-
if err != nil {
486-
t.Fatalf("failed to do status after eval-ing docker-env. error: %v", err)
470+
471+
type ShellTest struct {
472+
name string
473+
commandPrefix []string
474+
formatArg string
487475
}
488-
if !strings.Contains(rr.Output(), "Running") {
489-
t.Fatalf("expected status output to include 'Running' after eval docker-env but got: *%s*", rr.Output())
476+
477+
windowsTests := []ShellTest{
478+
{"powershell", []string{"powershell.exe", "-NoProfile", "-NonInteractive"}, "%[1]s -p %[2]s docker-env | Invoke-Expression ; "},
490479
}
491-
if !strings.Contains(rr.Output(), "in-use") {
492-
t.Fatalf("expected status output to include `in-use` after eval docker-env but got *%s*", rr.Output())
480+
posixTests := []ShellTest{
481+
{"bash", []string{"/bin/bash", "-c"}, "eval $(%[1]s -p %[2]s docker-env) && "},
493482
}
494483

495-
mctx, cancel = context.WithTimeout(ctx, Seconds(60))
496-
defer cancel()
497-
// do a eval $(minikube -p profile docker-env) and check if we are point to docker inside minikube
498-
if runtime.GOOS == "windows" { // testing docker-env eval in powershell
499-
c := exec.CommandContext(mctx, "powershell.exe", "-NoProfile", "-NonInteractive", Target()+" -p "+profile+" docker-env | Invoke-Expression ; docker images")
500-
rr, err = Run(t, c)
501-
} else {
502-
c := exec.CommandContext(mctx, "/bin/bash", "-c", "eval $("+Target()+" -p "+profile+" docker-env) && docker images")
503-
rr, err = Run(t, c)
484+
tests := posixTests
485+
if runtime.GOOS == "windows" {
486+
tests = windowsTests
504487
}
488+
for _, tc := range tests {
489+
t.Run(tc.name, func(t *testing.T) {
490+
mctx, cancel := context.WithTimeout(ctx, Seconds(120))
491+
defer cancel()
505492

506-
if mctx.Err() == context.DeadlineExceeded {
507-
t.Errorf("failed to run the command in 30 seconds. exceeded 30s timeout. %s", rr.Command())
508-
}
493+
command := make([]string, len(tc.commandPrefix)+1)
494+
// Would use "copy" built-in here, but that is shadowed by "copy" package
495+
for i, v := range tc.commandPrefix {
496+
command[i] = v
497+
}
509498

510-
if err != nil {
511-
t.Fatalf("failed to run minikube docker-env. args %q : %v ", rr.Command(), err)
512-
}
499+
formattedArg := fmt.Sprintf(tc.formatArg, Target(), profile)
513500

514-
expectedImgInside := "gcr.io/k8s-minikube/storage-provisioner"
515-
if !strings.Contains(rr.Output(), expectedImgInside) {
516-
t.Fatalf("expected 'docker images' to have %q inside minikube. but the output is: *%s*", expectedImgInside, rr.Output())
501+
// we should be able to get minikube status with a shell which evaled docker-env
502+
command[len(command)-1] = formattedArg + Target() + " status -p " + profile
503+
c := exec.CommandContext(mctx, command[0], command[1:]...)
504+
rr, err := Run(t, c)
505+
506+
if mctx.Err() == context.DeadlineExceeded {
507+
t.Errorf("failed to run the command by deadline. exceeded timeout. %s", rr.Command())
508+
}
509+
if err != nil {
510+
t.Fatalf("failed to do status after eval-ing docker-env. error: %v", err)
511+
}
512+
if !strings.Contains(rr.Output(), "Running") {
513+
t.Fatalf("expected status output to include 'Running' after eval docker-env but got: *%s*", rr.Output())
514+
}
515+
if !strings.Contains(rr.Output(), "in-use") {
516+
t.Fatalf("expected status output to include `in-use` after eval docker-env but got *%s*", rr.Output())
517+
}
518+
519+
mctx, cancel = context.WithTimeout(ctx, Seconds(60))
520+
defer cancel()
521+
522+
// do a eval $(minikube -p profile docker-env) and check if we are point to docker inside minikube
523+
command[len(command)-1] = formattedArg + "docker images"
524+
c = exec.CommandContext(mctx, command[0], command[1:]...)
525+
rr, err = Run(t, c)
526+
527+
if mctx.Err() == context.DeadlineExceeded {
528+
t.Errorf("failed to run the command in 30 seconds. exceeded 30s timeout. %s", rr.Command())
529+
}
530+
531+
if err != nil {
532+
t.Fatalf("failed to run minikube docker-env. args %q : %v ", rr.Command(), err)
533+
}
534+
535+
expectedImgInside := "gcr.io/k8s-minikube/storage-provisioner"
536+
if !strings.Contains(rr.Output(), expectedImgInside) {
537+
t.Fatalf("expected 'docker images' to have %q inside minikube. but the output is: *%s*", expectedImgInside, rr.Output())
538+
}
539+
})
517540
}
518541
}
519542

0 commit comments

Comments
 (0)