-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage_test.go
56 lines (44 loc) · 1.17 KB
/
package_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
package main
import "testing"
func TestGetImports_NoDir(t *testing.T) {
dir := "testdata/unexisting_dir"
imports, err := getImports(dir)
if err == nil {
t.Errorf("I expected to get error, but got nil")
}
if len(imports) > 0 {
t.Errorf("I expected to get empty imports, but current length is %d", len(imports))
}
}
func TestGetImports_EmptyDir(t *testing.T) {
dir := "testdata/src/empty"
imports, err := getImports(dir)
if err != nil {
t.Errorf("I got unexpected error: %s", err)
}
if len(imports) > 0 {
t.Errorf("I expected to get empty imports, but current length is %d", len(imports))
}
}
func TestGetImports_GoodDir(t *testing.T) {
dir := "testdata/src/good"
imports, err := getImports(dir)
if err != nil {
t.Errorf("I got unexpected error: %s", err)
}
expected := map[string]bool{
"github.com/golang/dep": true,
"github.com/golang/dep/gps": true,
"os": true,
"fmt": true,
"sync": true,
}
if len(expected) != len(imports) {
t.Errorf("I expected to get %d packages but got %d", len(expected), len(imports))
}
for _, pn := range imports {
if !expected[pn] {
t.Errorf("I expected to get package %s, but do not see it", pn)
}
}
}