Update tests to include all current output quirks

pull/6527/head
Thomas Stromberg 2020-02-06 15:54:57 -08:00
parent b478fbaa1a
commit 6e19c62896
2 changed files with 59 additions and 41 deletions

View File

@ -345,13 +345,13 @@ var dockerEnvCmd = &cobra.Command{
}
if unset {
if err := generateUnsetScript(ec, os.Stdout); err != nil {
if err := unsetScript(ec, os.Stdout); err != nil {
exit.WithError("Error generating unset output", err)
}
return
}
if err := generateSetScript(ec, os.Stdout); err != nil {
if err := setScript(ec, os.Stdout); err != nil {
exit.WithError("Error generating set output", err)
}
},
@ -367,8 +367,8 @@ type EnvConfig struct {
noProxy bool
}
// generateSetScript writes out a shell-compatible 'docker-env' script
func generateSetScript(ec EnvConfig, w io.Writer) error {
// setScript writes out a shell-compatible 'docker-env' script
func setScript(ec EnvConfig, w io.Writer) error {
tmpl := template.Must(template.New("envConfig").Parse(envTmpl))
envVars, err := dockerEnvVars(ec)
if err != nil {
@ -377,8 +377,8 @@ func generateSetScript(ec EnvConfig, w io.Writer) error {
return tmpl.Execute(w, shellCfgSet(ec, envVars))
}
// generateSetScript writes out a shell-compatible 'docker-env unset' script
func generateUnsetScript(ec EnvConfig, w io.Writer) error {
// setScript writes out a shell-compatible 'docker-env unset' script
func unsetScript(ec EnvConfig, w io.Writer) error {
tmpl := template.Must(template.New("envConfig").Parse(envTmpl))
return tmpl.Execute(w, shellCfgUnset(ec))
}

View File

@ -47,7 +47,7 @@ export DOCKER_HOST="tcp://127.0.0.1:2376"
export DOCKER_CERT_PATH="/certs"
export MINIKUBE_ACTIVE_DOCKERD="bash"
# To point your shell to minikube's docker-daemon,
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval $(minikube -p bash docker-env)
`,
`unset DOCKER_TLS_VERIFY
@ -55,8 +55,9 @@ unset DOCKER_HOST
unset DOCKER_CERT_PATH
unset MINIKUBE_ACTIVE_DOCKERD
# To point your shell to minikube's docker-daemon,
# eval $(minikube -p bash docker-env)`,
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval $(minikube -p bash docker-env)
`,
},
{
EnvConfig{profile: "fish", shell: "fish", driver: "kvm2", hostIP: "127.0.0.1", certsDir: "/certs"},
@ -66,7 +67,7 @@ set -gx DOCKER_HOST "tcp://127.0.0.1:2376";
set -gx DOCKER_CERT_PATH "/certs";
set -gx MINIKUBE_ACTIVE_DOCKERD "fish";
# To point your shell to minikube's docker-daemon,
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval (minikube -p fish docker-env)
`,
`set -e DOCKER_TLS_VERIFY;
@ -74,8 +75,9 @@ set -e DOCKER_HOST;
set -e DOCKER_CERT_PATH;
set -e MINIKUBE_ACTIVE_DOCKERD;
# To point your shell to minikube's docker-daemon,
# eval (minikube -p fish docker-env)`,
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval (minikube -p fish docker-env)
`,
},
{
EnvConfig{profile: "powershell", shell: "powershell", driver: "hyperv", hostIP: "192.168.0.1", certsDir: "/certs"},
@ -85,16 +87,18 @@ $Env:DOCKER_HOST = "tcp://192.168.0.1:2376"
$Env:DOCKER_CERT_PATH = "/certs"
$Env:MINIKUBE_ACTIVE_DOCKERD = "powershell"
# To point your shell to minikube's docker-daemon,
# Please run command bellow to point your shell to minikube's docker-daemon :
# & minikube -p powershell docker-env | Invoke-Expression
`,
`,
`Remove-Item Env:\\DOCKER_TLS_VERIFY
Remove-Item Env:\\DOCKER_HOST
Remove-Item Env:\\DOCKER_CERT_PATH
Remove-Item Env:\\MINIKUBE_ACTIVE_DOCKERD
# To point your shell to minikube's docker-daemon,
# & minikube -p powershell docker-env | Invoke-Expression`,
# Please run command bellow to point your shell to minikube's docker-daemon :
# & minikube -p powershell docker-env | Invoke-Expression
`,
},
{
EnvConfig{profile: "cmd", shell: "cmd", driver: "hyperv", hostIP: "192.168.0.1", certsDir: "/certs"},
@ -104,16 +108,18 @@ SET DOCKER_HOST=tcp://192.168.0.1:2376
SET DOCKER_CERT_PATH=/certs
SET MINIKUBE_ACTIVE_DOCKERD=cmd
REM To point your shell to minikube's docker-daemon,
REM Please run command bellow to point your shell to minikube's docker-daemon :
REM @FOR /f "tokens=*" %i IN ('minikube -p cmd docker-env') DO @%i
`,
`,
`SET DOCKER_TLS_VERIFY=
SET DOCKER_HOST=
SET DOCKER_CERT_PATH=
SET MINIKUBE_ACTIVE_DOCKERD=
REM To point your shell to minikube's docker-daemon,
REM @FOR /f "tokens=*" %i IN ('minikube -p cmd docker-env') DO @%i`,
REM Please run command bellow to point your shell to minikube's docker-daemon :
REM @FOR /f "tokens=*" %i IN ('minikube -p cmd docker-env') DO @%i
`,
},
{
EnvConfig{profile: "emacs", shell: "emacs", driver: "hyperv", hostIP: "192.168.0.1", certsDir: "/certs"},
@ -123,16 +129,17 @@ REM @FOR /f "tokens=*" %i IN ('minikube -p cmd docker-env') DO @%i`,
(setenv "DOCKER_CERT_PATH" "/certs")
(setenv "MINIKUBE_ACTIVE_DOCKERD" "emacs")
;; To point your shell to minikube's docker-daemon,
;; Please run command bellow to point your shell to minikube's docker-daemon :
;; (with-temp-buffer (shell-command "minikube -p emacs docker-env" (current-buffer)) (eval-buffer))
`,
`,
`(setenv "DOCKER_TLS_VERIFY" nil)
(setenv "DOCKER_HOST" nil)
(setenv "DOCKER_CERT_PATH" nil)
(setenv "MINIKUBE_ACTIVE_DOCKERD" nil)
;; To point your shell to minikube's docker-daemon,
;; (with-temp-buffer (shell-command "minikube -p emacs docker-env" (current-buffer)) (eval-buffer))`,
;; Please run command bellow to point your shell to minikube's docker-daemon :
;; (with-temp-buffer (shell-command "minikube -p emacs docker-env" (current-buffer)) (eval-buffer))
`,
},
{
EnvConfig{profile: "bash-no-proxy", shell: "bash", driver: "kvm2", hostIP: "127.0.0.1", certsDir: "/certs", noProxy: true},
@ -143,7 +150,7 @@ export DOCKER_CERT_PATH="/certs"
export MINIKUBE_ACTIVE_DOCKERD="bash-no-proxy"
export NO_PROXY="127.0.0.1"
# To point your shell to minikube's docker-daemon,
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval $(minikube -p bash-no-proxy docker-env)
`,
@ -151,7 +158,11 @@ export NO_PROXY="127.0.0.1"
unset DOCKER_HOST
unset DOCKER_CERT_PATH
unset MINIKUBE_ACTIVE_DOCKERD
unset no_proxy127.0.0.1`,
unset NO_PROXY127.0.0.1
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval $(minikube -p bash-no-proxy docker-env)
`,
},
{
EnvConfig{profile: "bash-no-proxy-lower", shell: "bash", driver: "kvm2", hostIP: "127.0.0.1", certsDir: "/certs", noProxy: true},
@ -162,7 +173,7 @@ export DOCKER_CERT_PATH="/certs"
export MINIKUBE_ACTIVE_DOCKERD="bash-no-proxy-lower"
export no_proxy="127.0.0.1"
# To point your shell to minikube's docker-daemon,
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval $(minikube -p bash-no-proxy-lower docker-env)
`,
@ -170,7 +181,11 @@ export no_proxy="127.0.0.1"
unset DOCKER_HOST
unset DOCKER_CERT_PATH
unset MINIKUBE_ACTIVE_DOCKERD
unset no_proxy127.0.0.1`,
unset no_proxy127.0.0.1
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval $(minikube -p bash-no-proxy-lower docker-env)
`,
},
{
EnvConfig{profile: "bash-no-proxy-idempotent", shell: "bash", driver: "kvm2", hostIP: "127.0.0.1", certsDir: "/certs", noProxy: true},
@ -181,7 +196,7 @@ export DOCKER_CERT_PATH="/certs"
export MINIKUBE_ACTIVE_DOCKERD="bash-no-proxy-idempotent"
export no_proxy="127.0.0.1"
# To point your shell to minikube's docker-daemon,
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval $(minikube -p bash-no-proxy-idempotent docker-env)
`,
@ -191,8 +206,9 @@ unset DOCKER_CERT_PATH
unset MINIKUBE_ACTIVE_DOCKERD
unset no_proxy127.0.0.1
# To point your shell to minikube's docker-daemon,
# eval $(minikube -p bash-no-proxy-idempotent docker-env)`,
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval $(minikube -p bash-no-proxy-idempotent docker-env)
`,
},
{
EnvConfig{profile: "sh-no-proxy-add", shell: "bash", driver: "kvm2", hostIP: "127.0.0.1", certsDir: "/certs", noProxy: true},
@ -203,8 +219,9 @@ export DOCKER_CERT_PATH="/certs"
export MINIKUBE_ACTIVE_DOCKERD="sh-no-proxy-add"
export NO_PROXY="192.168.0.1,10.0.0.4,127.0.0.1"
# To point your shell to minikube's docker-daemon,
# eval $(minikube -p sh-no-proxy-add docker-env)`,
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval $(minikube -p sh-no-proxy-add docker-env)
`,
`unset DOCKER_TLS_VERIFY
unset DOCKER_HOST
@ -212,8 +229,9 @@ unset DOCKER_CERT_PATH
unset MINIKUBE_ACTIVE_DOCKERD
unset NO_PROXY192.168.0.1,10.0.0.4
# To point your shell to minikube's docker-daemon,
# eval $(minikube -p sh-no-proxy-add docker-env)`,
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval $(minikube -p sh-no-proxy-add docker-env)
`,
},
}
for _, tc := range tests {
@ -221,21 +239,21 @@ unset NO_PROXY192.168.0.1,10.0.0.4
defaultNoProxyGetter = tc.noProxyGetter
var b []byte
buf := bytes.NewBuffer(b)
if err := generateSetScript(tc.config, buf); err != nil {
t.Errorf("generateSetScript(%+v) error: %v", tc.config, err)
if err := setScript(tc.config, buf); err != nil {
t.Errorf("setScript(%+v) error: %v", tc.config, err)
}
got := buf.String()
if diff := cmp.Diff(tc.wantSet, got); diff != "" {
t.Errorf("generateSetScript(%+v) content mismatch (-want +got):\n%s\n\nraw output:\n%s", tc.config, diff, got)
t.Errorf("setScript(%+v) mismatch (-want +got):\n%s\n\nraw output:\n%s\nquoted: %q", tc.config, diff, got, got)
}
buf = bytes.NewBuffer(b)
if err := generateUnsetScript(tc.config, buf); err != nil {
t.Errorf("generateUnsetScript(%+v) error: %v", tc.config, err)
if err := unsetScript(tc.config, buf); err != nil {
t.Errorf("unsetScript(%+v) error: %v", tc.config, err)
}
got = buf.String()
if diff := cmp.Diff(tc.wantUnset, got); diff != "" {
t.Errorf("generateUnsetScript(%+v) content mismatch (-want +got):\n%s\n\nraw output:\n%s", tc.config, diff, got)
t.Errorf("unsetScript(%+v) mismatch (-want +got):\n%s\n\nraw output:\n%s\nquoted: %q", tc.config, diff, got, got)
}
})