-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_test.go
78 lines (72 loc) · 1.4 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package pkg
import (
"go/build"
"runtime"
"testing"
)
func TestIsInstalled(t *testing.T) {
c := &Corpus{
ctxt: NewContext(&build.Default, 0),
}
x := PackageIndex{c: c}
var tests = []struct {
p Package
exp bool
}{
// Test Packages
{
Package{
Root: runtime.GOROOT(),
Name: "testing",
ImportPath: "testing",
},
true,
},
// Test invalid package
{
Package{
Root: runtime.GOROOT(),
Name: "INVALID",
ImportPath: "INVALID",
},
false,
},
// Test Commands
{
Package{
Root: runtime.GOROOT(),
Name: "main",
ImportPath: "cmd/go",
},
true,
},
}
for _, test := range tests {
p := &test.p
if x.isInstalled(p) != test.exp {
t.Fatalf("PackageIndex.isInstalled: name (%s) import path (%s) root (%s) expected: %v",
p.Name, p.ImportPath, p.Root, test.exp)
}
}
}
func TestLookup(t *testing.T) {
c := &Corpus{
ctxt: NewContext(&build.Default, 0),
}
x := PackageIndex{c: c}
pkg := &Package{
Dir: "/usr/local/go/src/bufio",
Name: "bufio",
ImportPath: "bufio",
Root: "/usr/local/go",
SrcRoot: "/usr/local/go/src",
Goroot: true,
}
x.addPackage(pkg)
if _, ok := x.lookupPath(pkg.Dir); !ok {
t.Errorf("PackageIndex lookupPath: (%+v)\n", pkg)
}
if _, ok := x.lookup(pkg.SrcRoot, pkg.ImportPath); !ok {
t.Errorf("PackageIndex lookup: (%+v)\n", pkg)
}
}