1
0
mirror of https://github.com/docker/docs.git synced 2026-11-05 00:14:17 +03:00

FIX #2746 Improve shell detection in bugsnag reports

Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
David Gageot
2016-01-06 10:36:00 +01:00
parent ad3e6b5bf0
commit fc025e1984
7 changed files with 25 additions and 26 deletions

View File

@@ -9,10 +9,10 @@ import (
"text/template"
"github.com/docker/machine/commands/mcndirs"
"github.com/docker/machine/commands/shell"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/check"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/shell"
)
const (

View File

@@ -17,6 +17,7 @@ import (
"github.com/bugsnag/bugsnag-go"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/shell"
"github.com/docker/machine/version"
)
@@ -125,12 +126,8 @@ func addFile(path string, metaData *bugsnag.MetaData) {
}
func detectRunningShell(metaData *bugsnag.MetaData) {
shell := os.Getenv("SHELL")
if shell != "" {
metaData.Add("device", "shell", shell)
}
shell = os.Getenv("__fish_bin_dir")
if shell != "" {
shell, err := shell.Detect()
if err == nil {
metaData.Add("device", "shell", shell)
}
}

View File

@@ -8,22 +8,24 @@ import (
)
func TestDetectBash(t *testing.T) {
originalShell := os.Getenv("SHELL")
defer func(shell string) { os.Setenv("SHELL", shell) }(os.Getenv("SHELL"))
os.Setenv("SHELL", "/bin/bash")
defer os.Setenv("SHELL", originalShell)
shell, err := Detect()
assert.Nil(t, err)
assert.Equal(t, "bash", shell)
assert.NoError(t, err)
}
func TestDetectFish(t *testing.T) {
originalShell := os.Getenv("SHELL")
defer func(shell string) { os.Setenv("SHELL", shell) }(os.Getenv("SHELL"))
os.Setenv("SHELL", "/bin/bash")
defer os.Setenv("SHELL", originalShell)
originalFishdir := os.Getenv("__fish_bin_dir")
defer func(fishDir string) { os.Setenv("__fish_bin_dir", fishDir) }(os.Getenv("__fish_bin_dir"))
os.Setenv("__fish_bin_dir", "/usr/local/Cellar/fish/2.2.0/bin")
defer os.Setenv("__fish_bin_dir", originalFishdir)
shell, err := Detect()
assert.Nil(t, err)
assert.Equal(t, "fish", shell)
assert.NoError(t, err)
}

View File

@@ -3,19 +3,18 @@
package shell
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestUnknowShell(t *testing.T) {
originalShell := os.Getenv("SHELL")
func TestUnknownShell(t *testing.T) {
defer func(shell string) { os.Setenv("SHELL", shell) }(os.Getenv("SHELL"))
os.Setenv("SHELL", "")
defer os.Setenv("SHELL", originalShell)
shell, err := Detect()
fmt.Println(shell)
assert.Equal(t, err, ErrUnknownShell)
assert.Equal(t, "", shell)
assert.Empty(t, shell)
}

View File

@@ -8,17 +8,18 @@ import (
)
func TestDetect(t *testing.T) {
originalShell := os.Getenv("SHELL")
defer func(shell string) { os.Setenv("SHELL", shell) }(os.Getenv("SHELL"))
os.Setenv("SHELL", "")
defer os.Setenv("SHELL", originalShell)
shell, err := Detect()
assert.Nil(t, err)
assert.Equal(t, "cmd", shell)
assert.NoError(t, err)
}
func TestStartedBy(t *testing.T) {
shell, err := startedBy()
assert.Nil(t, err)
assert.NotNil(t, shell)
assert.Equal(t, "go.exe", shell)
assert.NoError(t, err)
}