OSDN Git Service

new repo
[bytom/vapor.git] / version / version_test.go
1 package version
2
3 import (
4         "testing"
5
6         gover "github.com/hashicorp/go-version"
7 )
8
9 func TestCompare(t *testing.T) {
10         v1, err := gover.NewVersion(Version)
11         if err != nil {
12                 t.Fatal("Version 1 format error.")
13         }
14         v2, err := gover.NewVersion(Version + "+f873dfca")
15         if err != nil {
16                 t.Fatal("Version 2 format error.")
17         }
18         if v1.GreaterThan(v2) || v1.GreaterThan(v2) {
19                 t.Error("Version comparison error.")
20         }
21 }
22
23 func TestCompatibleWith(t *testing.T) {
24         cases := []struct {
25                 a      string
26                 b      string
27                 result bool
28         }{
29                 {
30                         "1.0.4",
31                         "1.0.4",
32                         true,
33                 },
34                 {
35                         "1.0.4",
36                         "1.0.5",
37                         true,
38                 },
39                 {
40                         "1.0.4",
41                         "1.1.5",
42                         true,
43                 },
44                 {
45                         "1.0.5",
46                         "1.0.5-90825109",
47                         true,
48                 },
49                 {
50                         "1.0.5",
51                         "1.0.5+90825109",
52                         true,
53                 },
54                 {
55                         "1.0.5",
56                         "2.0.5",
57                         false,
58                 },
59                 {
60                         "1.0.5-90825109",
61                         "1.0.5+90825109",
62                         true,
63                 },
64         }
65
66         for i, c := range cases {
67                 Version = c.a
68                 if result, _ := CompatibleWith(c.b); c.result != result {
69                         t.Errorf("case %d: got %t want %t", i, c.result, result)
70                 }
71         }
72 }
73
74 // In case someone edit the iota part and have the mapping changed:
75 // noUpdate: 0
76 // hasUpdate: 1
77 // hasMUpdate: 2
78 func TestFlag(t *testing.T) {
79         if noUpdate != 0 {
80                 t.Error("noUpdate value error")
81         }
82         if hasUpdate != 1 {
83                 t.Error("hasUpdate value error")
84         }
85         if hasMUpdate != 2 {
86                 t.Error("noUpdate value error")
87         }
88 }