-
Notifications
You must be signed in to change notification settings - Fork 1
/
version_test.go
50 lines (41 loc) · 933 Bytes
/
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
package main
import (
"sort"
"testing"
)
func TestParseVersion(t *testing.T) {
v, err := parseVersion("v3.2.1")
if err != nil {
t.Fatal(err)
}
if v.major != 3 {
t.Fatal("major doesnt equal 3")
}
if v.minor != 2 {
t.Fatal("minor doesnt equal 2")
}
if v.patch != 1 {
t.Fatal("patch doesnt equal 1")
}
}
func TestSortVersion(t *testing.T) {
vs := []string{"v4.2.1", "v0.5.7", "v2.15.99"}
var versionsArray versions
for _, v := range vs {
ver, err := parseVersion(v)
if err != nil {
t.Fatal(err)
}
versionsArray = append(versionsArray, ver)
}
sort.Sort(versionsArray)
if versionsArray[0].original != "v0.5.7" {
t.Fatal("0 Not in order got:", versionsArray[0].original)
}
if versionsArray[1].original != "v2.15.99" {
t.Fatal("1 Not in order got:", versionsArray[1].original)
}
if versionsArray[2].original != "v4.2.1" {
t.Fatal("2 Not in order got:", versionsArray[2].original)
}
}