Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tcsh in docker-env subcommand #12332

Merged
merged 4 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/minikube/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ REM @FOR /f "tokens=*" %%i IN ('%s') DO @%%i
`, s...)
},
},
"tcsh": {
andriyDev marked this conversation as resolved.
Show resolved Hide resolved
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",
Expand Down
3 changes: 3 additions & 0 deletions pkg/minikube/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
101 changes: 62 additions & 39 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
})
}
}

Expand Down