-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
stacktrace_cleanpath_test.go
62 lines (57 loc) · 1.47 KB
/
stacktrace_cleanpath_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package oops
///
/// Stolen from palantir/stacktrace repo
/// -> https://github.com/palantir/stacktrace/blob/master/cleanpath/gopath_test.go
/// -> Apache 2.0 LICENSE
///
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRemoveGoPath(t *testing.T) {
for _, testcase := range []struct {
gopath []string
path string
expected string
}{
{
// empty gopath
gopath: []string{},
path: "/some/dir/src/pkg/prog.go",
expected: "/some/dir/src/pkg/prog.go",
},
{
// single matching dir in gopath
gopath: []string{"/some/dir"},
path: "/some/dir/src/pkg/prog.go",
expected: "pkg/prog.go",
},
{
// nonmatching dir in gopath
gopath: []string{"/other/dir"},
path: "/some/dir/src/pkg/prog.go",
expected: "/some/dir/src/pkg/prog.go",
},
{
// multiple matching dirs in gopath, shorter first
gopath: []string{"/some", "/some/src/dir"},
path: "/some/src/dir/src/pkg/prog.go",
expected: "pkg/prog.go",
},
{
// multiple matching dirs in gopath, longer first
gopath: []string{"/some/src/dir", "/some"},
path: "/some/src/dir/src/pkg/prog.go",
expected: "pkg/prog.go",
},
} {
gopath := strings.Join(testcase.gopath, string(filepath.ListSeparator))
err := os.Setenv("GOPATH", gopath)
assert.NoError(t, err, "error setting gopath")
cleaned := removeGoPath(testcase.path)
assert.Equal(t, testcase.expected, cleaned, "testcase: %+v", testcase)
}
}