OSDN Git Service

:white_check_mark: Add version comparison test (#1294)
[bytom/bytom.git] / version / version_test.go
1 package version
2
3 import (
4         "fmt"
5         "math/rand"
6         "testing"
7         "time"
8
9         gover "github.com/hashicorp/go-version"
10 )
11
12 func TestRevisionLen(t *testing.T) {
13         if revisionLen > 16 {
14                 t.Error("revisionLen too long")
15         }
16 }
17
18 func TestCompare(t *testing.T) {
19         rand.Seed(time.Now().UnixNano())
20         i := rand.Uint64()
21         rev := fmt.Sprintf("%16x", i)[:revisionLen]
22
23         v1, err := gover.NewVersion(Version)
24         if err != nil {
25                 t.Error("Version 1 format error.")
26         }
27         v2, err := gover.NewVersion(Version + "+" + rev)
28         if err != nil {
29                 t.Error("Version 2 format error.")
30         }
31         if v1.GreaterThan(v2) || v1.GreaterThan(v2) {
32                 t.Error("Version comparison error.")
33         }
34 }
35
36 // In case someone edit the iota part and have the mapping changed:
37 // noUpdate: 0
38 // hasUpdate: 1
39 // hasMUpdate: 2
40 func TestFlag(t *testing.T) {
41         if noUpdate != 0 {
42                 t.Error("noUpdate value error")
43         }
44         if hasUpdate != 1 {
45                 t.Error("hasUpdate value error")
46         }
47         if hasMUpdate != 2 {
48                 t.Error("noUpdate value error")
49         }
50 }