-
Notifications
You must be signed in to change notification settings - Fork 3
/
version_test.go
48 lines (42 loc) · 1.06 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
package relic
import (
"testing"
)
func TestVersion(t *testing.T) {
versionString := "34.5.33"
version, err := AsVersion(versionString)
if err != nil {
t.Error(err)
}
// Check parsed version numbers match the version string
if version.String() != versionString {
t.Errorf("versionString '%s' should match parsed version '%s'", versionString, version.String())
}
}
func TestParseVersion(t *testing.T) {
version, err := ParseVersion("23.255.1")
if err != nil {
t.Error(err)
}
if uint8(23) != version.Major {
t.Errorf("Major numbers should match when parsed")
}
if uint8(255) != version.Minor {
t.Errorf("Minor numbers should match when parsed")
}
if uint8(1) != version.Patch {
t.Errorf("Patch numbers should match when parsed")
}
_, err = ParseVersion("2312.3.1")
if err == nil {
t.Errorf("Major number 2312 is larger than byte")
}
_, err = ParseVersion("231.256.1")
if err == nil {
t.Errorf("Minor number 256 is larger than byte")
}
_, err = ParseVersion("231.3.5645")
if err == nil {
t.Errorf("Patch number 5645 is larger than byte")
}
}