forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_test.go
112 lines (103 loc) · 2.8 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package version
import (
"fmt"
"runtime"
jc "github.com/juju/testing/checkers"
semversion "github.com/juju/version/v2"
gc "gopkg.in/check.v1"
)
type suite struct{}
var _ = gc.Suite(&suite{})
var isDevTests = []struct {
num semversion.Number
dev bool
}{{
num: semversion.Number{},
}, {
num: semversion.Number{Major: 0, Minor: 0, Patch: 1},
}, {
num: semversion.Number{Major: 0, Minor: 0, Patch: 2},
}, {
num: semversion.Number{Major: 0, Minor: 1, Patch: 0},
dev: true,
}, {
num: semversion.Number{Major: 0, Minor: 2, Patch: 3},
}, {
num: semversion.Number{Major: 1, Minor: 0, Patch: 0},
}, {
num: semversion.Number{Major: 10, Minor: 234, Patch: 3456},
}, {
num: semversion.Number{Major: 10, Minor: 234, Patch: 3456, Build: 1},
dev: true,
}, {
num: semversion.Number{Major: 10, Minor: 234, Patch: 3456, Build: 64},
dev: true,
}, {
num: semversion.Number{Major: 10, Minor: 235, Patch: 3456},
}, {
num: semversion.Number{Major: 1, Minor: 21, Patch: 1, Tag: "alpha"},
dev: true,
}, {
num: semversion.Number{Major: 1, Minor: 21, Patch: 1, Tag: "alpha", Build: 1},
dev: true,
}, {
num: semversion.Number{Major: 1, Minor: 21},
}}
func (*suite) TestIsDev(c *gc.C) {
for i, test := range isDevTests {
c.Logf("test %d", i)
c.Check(IsDev(test.num), gc.Equals, test.dev)
}
}
func (s *suite) TestCompiler(c *gc.C) {
c.Assert(Compiler, gc.Equals, runtime.Compiler)
}
func (s *suite) TestCheckJujuMinVersion(c *gc.C) {
for _, test := range []struct {
toCheck semversion.Number
jujuVersion semversion.Number
error bool
}{
{
toCheck: semversion.Zero,
jujuVersion: semversion.MustParse("2.8.0"),
error: false,
}, {
toCheck: semversion.MustParse("2.8.0"),
jujuVersion: semversion.MustParse("2.8.0"),
error: false,
}, {
toCheck: semversion.MustParse("2.8.0"),
jujuVersion: semversion.MustParse("2.8.1"),
error: false,
}, {
toCheck: semversion.MustParse("2.8.0"),
jujuVersion: semversion.MustParse("2.9.0"),
error: false,
}, {
toCheck: semversion.MustParse("2.8.0"),
jujuVersion: semversion.MustParse("3.0.0"),
error: false,
}, {
toCheck: semversion.MustParse("2.8.0"),
jujuVersion: semversion.MustParse("2.8-beta1"),
error: false,
}, {
toCheck: semversion.MustParse("2.8.0"),
jujuVersion: semversion.MustParse("2.7.0"),
error: true,
},
} {
err := CheckJujuMinVersion(test.toCheck, test.jujuVersion)
if test.error {
c.Assert(err, jc.Satisfies, IsMinVersionError)
c.Assert(err.Error(), gc.Equals,
fmt.Sprintf("charm's min version (%s) is higher than this juju model's version (%s)",
test.toCheck, test.jujuVersion))
} else {
c.Assert(err, jc.ErrorIsNil)
}
}
}