-
Notifications
You must be signed in to change notification settings - Fork 0
/
golist_test.go
49 lines (45 loc) · 1.08 KB
/
golist_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
package gvtunused
import (
"os/exec"
"testing"
)
func TestGoListImports(t *testing.T) {
testCases := []struct {
desc string
output string
imports []string
}{
{
desc: "single import list",
output: "github.com/slomek/gvt-unused",
imports: []string{"github.com/slomek/gvt-unused"},
}, {
desc: "multiple import list",
output: `github.com/slomek/gvt-unused/a
github.com/slomek/gvt-unused/b
github.com/slomek/gvt-unused/c
`,
imports: []string{
"github.com/slomek/gvt-unused/a",
"github.com/slomek/gvt-unused/b",
"github.com/slomek/gvt-unused/c"},
},
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
cmd := exec.Command("echo", tC.output)
imps, err := GoListImports(cmd)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if len(imps) != len(tC.imports) {
t.Fatalf("Expected %d imports, got: %d", len(tC.imports), len(imps))
}
for i, imp := range imps {
if tC.imports[i] != imp {
t.Errorf("Expected import #%d to be %s, got: %s", i, tC.imports[i], imp)
}
}
})
}
}