-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgomodule_libs_test.go
65 lines (59 loc) · 1.97 KB
/
gomodule_libs_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
package dragon
import "testing"
func TestVersionsLatest(t *testing.T) {
expects := map[string]map[string][]lib{
"111": map[string][]lib{
"v1.0.1": []lib{lib{path: "p", object: "101"}, lib{path: "p", object: "101"}},
"v1.1.1": []lib{lib{path: "p", object: "111"}, lib{path: "p", object: "111"}},
"v1.0.0": []lib{lib{path: "p", object: "100"}, lib{path: "p", object: "100"}},
},
"2": map[string][]lib{
"v0.0.0-1": []lib{lib{path: "p", object: "1"}, lib{path: "p", object: "1"}},
"v0.0.0-2": []lib{lib{path: "p", object: "2"}, lib{path: "p", object: "2"}},
"v0.0.0-0": []lib{lib{path: "p", object: "0"}, lib{path: "p", object: "0"}},
},
}
for expect, v := range expects {
vers := &versions{libByVersion: map[string][]lib{}}
for version, libs := range v {
for _, lib := range libs {
vers.append(version, lib)
}
}
libs := vers.latest()
for _, lib := range libs {
if lib.object != expect {
t.Errorf("versions.latest should return latest libs")
}
}
}
}
func TestExtractImportPathAndVersion(t *testing.T) {
expects := map[string][]string{
"golang.org/x/[email protected]/nettest": []string{
"golang.org/x/net/nettest",
"v0.0.0-20190125091013-d26f9f9a57f3",
},
"golang.org/x/[email protected]/godoc/dl": []string{
"golang.org/x/tools/godoc/dl",
"v0.0.0-20190201231825-51e363b66d25",
},
"github.com/donvito/hellomod/[email protected]": []string{
"github.com/donvito/hellomod/v2",
"v2.0.0",
},
"github.com/donvito/hellomod/[email protected]": []string{
"github.com/donvito/hellomod/v2",
"v2.0.0-alpha.1.beta",
},
}
for path, expect := range expects {
importPath, version := extractImportPathAndVersion(path)
if importPath != expect[0] {
t.Errorf("extractImportPathAndVersion should return import path %s, but %s", expect[0], importPath)
}
if version != expect[1] {
t.Errorf("extractImportPathAndVersion should return version %s, but %s", expect[1], version)
}
}
}