-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathversion_test.go
114 lines (97 loc) · 3.04 KB
/
version_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package distri
import "testing"
func TestExtractPackageRevisionVersion(t *testing.T) {
for _, tt := range []struct {
filename string
want PackageVersion
}{
{
filename: "less-amd64-530",
want: PackageVersion{Pkg: "less", Arch: "amd64", Upstream: "530", DistriRevision: 0},
},
{
filename: "530",
want: PackageVersion{Upstream: "530", DistriRevision: 0},
},
{
filename: "530-3",
want: PackageVersion{Upstream: "530", DistriRevision: 3},
},
{
filename: "v0.0.0-20180314180146-1d60e4601c6f",
want: PackageVersion{Upstream: "v0.0.0-20180314180146-1d60e4601c6f"},
},
{
filename: "gcc-i686-amd64-8.2.0-3.squashfs",
want: PackageVersion{Pkg: "gcc-i686", Arch: "amd64", Upstream: "8.2.0", DistriRevision: 3},
},
{
filename: "gcc-i686-amd64-8.2.0.squashfs",
want: PackageVersion{Pkg: "gcc-i686", Arch: "amd64", Upstream: "8.2.0", DistriRevision: 0},
},
{
filename: "glibc-i686-host-amd64-2.27-3",
want: PackageVersion{Pkg: "glibc-i686-host", Arch: "amd64", Upstream: "2.27", DistriRevision: 3},
},
{
filename: "less-amd64-530-2",
want: PackageVersion{Pkg: "less", Arch: "amd64", Upstream: "530", DistriRevision: 2},
},
{
filename: "less-amd64-530-17.squashfs.gz",
want: PackageVersion{Pkg: "less", Arch: "amd64", Upstream: "530", DistriRevision: 17},
},
{
filename: "../less-amd64-530-17/bin/less", // exchange dir link target
want: PackageVersion{Pkg: "less", Arch: "amd64", Upstream: "530", DistriRevision: 17},
},
{
filename: "../libxslt-amd64-1.1.32-1/bin/xslt-config",
want: PackageVersion{Pkg: "libxslt", Arch: "amd64", Upstream: "1.1.32", DistriRevision: 1},
},
{
filename: "_build/git/build-2.9.5-3.log", // build log
want: PackageVersion{Upstream: "2.9.5", DistriRevision: 3},
},
{
filename: "_build/git/build-2.9.5.log", // build log
want: PackageVersion{Upstream: "2.9.5", DistriRevision: 0},
},
{
filename: "_build/git/build-amd64-2.9.5.log", // build log
want: PackageVersion{Arch: "amd64", Upstream: "2.9.5", DistriRevision: 0},
},
{
filename: "../../../linux-amd64-4.18.7/out/lib/modules/4.18.7/build",
want: PackageVersion{Pkg: "linux", Arch: "amd64", Upstream: "4.18.7", DistriRevision: 0},
},
} {
t.Run(tt.filename, func(t *testing.T) {
got := ParseVersion(tt.filename)
if got != tt.want {
t.Fatalf("extractVersion(%v) = %#v, want %#v", tt.filename, got, tt.want)
}
})
}
}
func TestPackageRevisionLess(t *testing.T) {
for _, tt := range []struct {
a, b string
want bool
}{
{
a: "../libxslt-amd64-1.1.32/bin/xslt-config",
b: "../libxslt-amd64-1.1.32-1/bin/xslt-config",
want: true,
},
} {
t.Run(tt.a+"_"+tt.b, func(t *testing.T) {
got := PackageRevisionLess(tt.a, tt.b)
if got != tt.want {
t.Logf("ParseVersion(%s) = %v", tt.a, ParseVersion(tt.a))
t.Logf("ParseVersion(%s) = %v", tt.b, ParseVersion(tt.b))
t.Errorf("PackageRevisionLess(%s, %s) = %v, want %v", tt.a, tt.b, got, tt.want)
}
})
}
}