mirror of https://github.com/docker/docs.git
shell selection: fix tests and add powershell test
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
e13e2b61c6
commit
33d8058d38
|
@ -151,8 +151,8 @@ func cmdEnv(c *cli.Context) {
|
||||||
switch userShell {
|
switch userShell {
|
||||||
case "fish":
|
case "fish":
|
||||||
shellCfg.Prefix = "set -x "
|
shellCfg.Prefix = "set -x "
|
||||||
shellCfg.Suffix = ";\n"
|
shellCfg.Suffix = "\";\n"
|
||||||
shellCfg.Delimiter = " "
|
shellCfg.Delimiter = " \""
|
||||||
case "powershell":
|
case "powershell":
|
||||||
shellCfg.Prefix = "$Env:"
|
shellCfg.Prefix = "$Env:"
|
||||||
shellCfg.Suffix = "\"\n"
|
shellCfg.Suffix = "\"\n"
|
||||||
|
@ -163,8 +163,8 @@ func cmdEnv(c *cli.Context) {
|
||||||
shellCfg.Delimiter = "="
|
shellCfg.Delimiter = "="
|
||||||
default:
|
default:
|
||||||
shellCfg.Prefix = "export "
|
shellCfg.Prefix = "export "
|
||||||
shellCfg.Suffix = "\n"
|
shellCfg.Suffix = "\"\n"
|
||||||
shellCfg.Delimiter = "="
|
shellCfg.Delimiter = "=\""
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl, err := t.Parse(envTmpl)
|
tmpl, err := t.Parse(envTmpl)
|
||||||
|
|
|
@ -103,9 +103,9 @@ func TestCmdEnvBash(t *testing.T) {
|
||||||
testMachineDir := filepath.Join(store.GetPath(), "machines", host.Name)
|
testMachineDir := filepath.Join(store.GetPath(), "machines", host.Name)
|
||||||
|
|
||||||
expected := map[string]string{
|
expected := map[string]string{
|
||||||
"DOCKER_TLS_VERIFY": "1",
|
"DOCKER_TLS_VERIFY": "\"1\"",
|
||||||
"DOCKER_CERT_PATH": fmt.Sprintf("\"%s\"", testMachineDir),
|
"DOCKER_CERT_PATH": fmt.Sprintf("\"%s\"", testMachineDir),
|
||||||
"DOCKER_HOST": "unix:///var/run/docker.sock",
|
"DOCKER_HOST": "\"unix:///var/run/docker.sock\"",
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range envvars {
|
for k, v := range envvars {
|
||||||
|
@ -201,9 +201,108 @@ func TestCmdEnvFish(t *testing.T) {
|
||||||
testMachineDir := filepath.Join(store.GetPath(), "machines", host.Name)
|
testMachineDir := filepath.Join(store.GetPath(), "machines", host.Name)
|
||||||
|
|
||||||
expected := map[string]string{
|
expected := map[string]string{
|
||||||
"DOCKER_TLS_VERIFY": "1",
|
"DOCKER_TLS_VERIFY": "\"1\"",
|
||||||
"DOCKER_CERT_PATH": fmt.Sprintf("\"%s\"", testMachineDir),
|
"DOCKER_CERT_PATH": fmt.Sprintf("\"%s\"", testMachineDir),
|
||||||
"DOCKER_HOST": "unix:///var/run/docker.sock",
|
"DOCKER_HOST": "\"unix:///var/run/docker.sock\"",
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range envvars {
|
||||||
|
if v != expected[k] {
|
||||||
|
t.Fatalf("Expected %s == <%s>, but was <%s>", k, expected[k], v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCmdEnvPowerShell(t *testing.T) {
|
||||||
|
stdout := os.Stdout
|
||||||
|
shell := os.Getenv("SHELL")
|
||||||
|
r, w, _ := os.Pipe()
|
||||||
|
|
||||||
|
os.Stdout = w
|
||||||
|
os.Setenv("MACHINE_STORAGE_PATH", TestStoreDir)
|
||||||
|
os.Setenv("SHELL", "")
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
os.Setenv("MACHINE_STORAGE_PATH", "")
|
||||||
|
os.Setenv("SHELL", shell)
|
||||||
|
os.Stdout = stdout
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err := clearHosts(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
flags := getTestDriverFlags()
|
||||||
|
|
||||||
|
store, sErr := getTestStore()
|
||||||
|
if sErr != nil {
|
||||||
|
t.Fatal(sErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
mcn, err := libmachine.New(store)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
hostOptions := &libmachine.HostOptions{
|
||||||
|
EngineOptions: &engine.EngineOptions{},
|
||||||
|
SwarmOptions: &swarm.SwarmOptions{
|
||||||
|
Master: false,
|
||||||
|
Discovery: "",
|
||||||
|
Address: "",
|
||||||
|
Host: "",
|
||||||
|
},
|
||||||
|
AuthOptions: &auth.AuthOptions{},
|
||||||
|
}
|
||||||
|
|
||||||
|
host, err := mcn.Create("test-a", "none", hostOptions, flags)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
host, err = mcn.Get("test-a")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error loading host: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := mcn.SetActive(host); err != nil {
|
||||||
|
t.Fatalf("error setting active host: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
outStr := make(chan string)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
var testOutput bytes.Buffer
|
||||||
|
io.Copy(&testOutput, r)
|
||||||
|
outStr <- testOutput.String()
|
||||||
|
}()
|
||||||
|
|
||||||
|
set := flag.NewFlagSet("config", 0)
|
||||||
|
set.String("shell", "powershell", "")
|
||||||
|
c := cli.NewContext(nil, set, set)
|
||||||
|
cmdEnv(c)
|
||||||
|
|
||||||
|
w.Close()
|
||||||
|
|
||||||
|
out := <-outStr
|
||||||
|
|
||||||
|
// parse the output into a map of envvar:value for easier testing below
|
||||||
|
envvars := make(map[string]string)
|
||||||
|
for _, e := range strings.Split(strings.TrimSpace(out), "\n") {
|
||||||
|
if !strings.HasPrefix(e, "$Env") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
kv := strings.SplitN(e, " = ", 2)
|
||||||
|
key, value := kv[0], kv[1]
|
||||||
|
envvars[strings.Replace(key, "$Env:", "", 1)] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
testMachineDir := filepath.Join(store.GetPath(), "machines", host.Name)
|
||||||
|
|
||||||
|
expected := map[string]string{
|
||||||
|
"DOCKER_TLS_VERIFY": "\"1\"",
|
||||||
|
"DOCKER_CERT_PATH": fmt.Sprintf("\"%s\"", testMachineDir),
|
||||||
|
"DOCKER_HOST": "\"unix:///var/run/docker.sock\"",
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range envvars {
|
for k, v := range envvars {
|
||||||
|
|
Loading…
Reference in New Issue