-
Notifications
You must be signed in to change notification settings - Fork 1
/
version_test.go
68 lines (63 loc) · 1.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
package license
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestVersion_String(t *testing.T) {
tests := []struct {
version Version
expect string
}{
{
version: Version(301001234),
expect: "3.100.1234",
},
{
version: Version(1001234),
expect: "0.100.1234",
},
{
version: Version(10001),
expect: "0.1.1",
},
}
for _, test := range tests {
assert.Equal(t, test.version.String(), test.expect)
}
}
func TestNewVersion(t *testing.T) {
tests := []struct {
version string
expect Version
shouldFail bool
}{
{
version: "0.1.1",
expect: Version(10001),
},
{
version: "3.100.1234",
expect: Version(301001234),
},
{
version: "1.1",
expect: Version(100010000),
},
{
version: "1.1.1",
expect: Version(100010001),
},
{
version: "1.1.faulty",
shouldFail: true,
},
}
for _, test := range tests {
val, err := NewVersion(test.version)
if test.shouldFail {
assert.Error(t, err)
} else {
assert.Equal(t, val, test.expect)
}
}
}