Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 package tools_test | |
2 | |
3 import ( | |
4 . "launchpad.net/gocheck" | |
5 "launchpad.net/juju-core/environs/tools" | |
6 "launchpad.net/juju-core/state" | |
7 "launchpad.net/juju-core/version" | |
8 "testing" | |
9 ) | |
10 | |
11 func TestPackage(t *testing.T) { | |
12 TestingT(t) | |
13 } | |
14 | |
15 type ListSuite struct{} | |
16 | |
17 var _ = Suite(&ListSuite{}) | |
18 | |
19 func mustParseTools(name string) *state.Tools { | |
20 return &state.Tools{Binary: version.MustParseBinary(name)} | |
21 } | |
22 | |
23 func extend(lists ...tools.List) tools.List { | |
24 var result tools.List | |
25 for _, list := range lists { | |
26 result = append(result, list...) | |
27 } | |
28 return result | |
29 } | |
30 | |
31 var ( | |
32 t100precise = mustParseTools("1.0.0-precise-amd64") | |
33 t100precise32 = mustParseTools("1.0.0-precise-i386") | |
34 t100quantal = mustParseTools("1.0.0-quantal-amd64") | |
35 t100quantal32 = mustParseTools("1.0.0-quantal-i386") | |
36 t100all = tools.List{ | |
37 t100precise, t100precise32, t100quantal, t100quantal32, | |
38 } | |
39 t190precise = mustParseTools("1.9.0-precise-amd64") | |
40 t190precise32 = mustParseTools("1.9.0-precise-i386") | |
41 t190quantal = mustParseTools("1.9.0-quantal-amd64") | |
42 t190all = tools.List{ | |
43 t190precise, t190precise32, t190quantal, | |
44 } | |
45 t200precise = mustParseTools("2.0.0-precise-amd64") | |
46 t200quantal32 = mustParseTools("2.0.0-quantal-i386") | |
47 t200all = tools.List{ | |
48 t200precise, t200quantal32, | |
49 } | |
50 t2001precise = mustParseTools("2.0.0.1-precise-amd64") | |
51 tAll = extend(t100all, t190all, append(t200all, t2001precise)) | |
52 ) | |
53 | |
54 type stringsTest struct { | |
55 src tools.List | |
56 expect []string | |
57 } | |
58 | |
59 func (s *ListSuite) TestSeries(c *C) { | |
60 for i, test := range []stringsTest{{ | |
61 tools.List{t100precise}, | |
62 []string{"precise"}, | |
63 }, { | |
64 tools.List{t100precise, t100precise32, t200precise}, | |
65 []string{"precise"}, | |
66 }, { | |
67 tAll, | |
68 []string{"precise", "quantal"}, | |
69 }} { | |
70 c.Logf("test %d", i) | |
71 c.Check(test.src.Series(), DeepEquals, test.expect) | |
72 } | |
73 } | |
74 | |
75 func (s *ListSuite) TestArches(c *C) { | |
76 for i, test := range []stringsTest{{ | |
77 tools.List{t100precise}, | |
78 []string{"amd64"}, | |
79 }, { | |
80 tools.List{t100precise, t100quantal, t200precise}, | |
81 []string{"amd64"}, | |
82 }, { | |
83 tAll, | |
84 []string{"amd64", "i386"}, | |
85 }} { | |
86 c.Logf("test %d", i) | |
87 c.Check(test.src.Arches(), DeepEquals, test.expect) | |
88 } | |
89 } | |
90 | |
91 func (s *ListSuite) TestNewest(c *C) { | |
92 for i, test := range []struct { | |
93 src tools.List | |
94 expect tools.List | |
95 }{{ | |
96 tools.List{t100precise}, | |
97 tools.List{t100precise}, | |
98 }, { | |
99 t100all, | |
100 t100all, | |
101 }, { | |
102 extend(t100all, t190all, t200all), | |
103 t200all, | |
104 }, { | |
105 tAll, | |
106 tools.List{t2001precise}, | |
107 }} { | |
108 c.Logf("test %d", i) | |
109 c.Check(test.src.Newest(), DeepEquals, test.expect) | |
110 } | |
111 } | |
112 | |
113 func (s *ListSuite) TestDifference(c *C) { | |
114 for i, test := range []struct { | |
115 src tools.List | |
116 arg tools.List | |
117 expect tools.List | |
118 }{{ | |
119 nil, tools.List{t100precise}, nil, | |
120 }, { | |
121 tools.List{t100precise}, nil, tools.List{t100precise}, | |
122 }, { | |
123 tools.List{t100precise}, tools.List{t100precise}, nil, | |
124 }, { | |
125 nil, tAll, nil, | |
126 }, { | |
127 tAll, nil, tAll, | |
128 }, { | |
129 tAll, tAll, nil, | |
130 }, { | |
131 t100all, | |
132 tools.List{t100precise}, | |
133 tools.List{t100precise32, t100quantal, t100quantal32}, | |
134 }, { | |
135 t100all, | |
136 tools.List{t100precise32, t100quantal, t100quantal32}, | |
137 tools.List{t100precise}, | |
138 }, { | |
139 t100all, t190all, t100all, | |
140 }, { | |
141 t190all, t100all, t190all, | |
142 }, { | |
143 extend(t100all, t190all), | |
144 t190all, | |
145 t100all, | |
146 }} { | |
147 c.Logf("test %d", i) | |
148 c.Check(test.src.Difference(test.arg), DeepEquals, test.expect) | |
149 } | |
150 } | |
151 | |
152 func (s *ListSuite) TestFilter(c *C) { | |
153 for i, test := range []struct { | |
154 src tools.List | |
155 filter tools.Filter | |
156 expect tools.List | |
157 }{{ | |
158 tools.List{t100precise}, | |
159 tools.Filter{}, | |
160 tools.List{t100precise}, | |
161 }, { | |
162 tAll, | |
163 tools.Filter{}, | |
164 tAll, | |
165 }, { | |
166 tAll, | |
167 tools.Filter{Released: true}, | |
168 t200all, | |
169 }, { | |
170 t100all, | |
171 tools.Filter{Released: true}, | |
172 nil, | |
173 }, { | |
174 tAll, | |
175 tools.Filter{Number: version.MustParse("1.9.0")}, | |
176 t190all, | |
177 }, { | |
178 tAll, | |
179 tools.Filter{Number: version.MustParse("1.9.0.1")}, | |
180 nil, | |
181 }, { | |
182 tAll, | |
183 tools.Filter{Series: "quantal"}, | |
184 tools.List{t100quantal, t100quantal32, t190quantal, t200quantal3 2}, | |
185 }, { | |
186 tAll, | |
187 tools.Filter{Series: "raring"}, | |
188 nil, | |
189 }, { | |
190 tAll, | |
191 tools.Filter{Arch: "i386"}, | |
192 tools.List{t100precise32, t100quantal32, t190precise32, t200quan tal32}, | |
193 }, { | |
194 tAll, | |
195 tools.Filter{Arch: "arm"}, | |
196 nil, | |
197 }, { | |
198 tAll, | |
199 tools.Filter{ | |
200 Released: true, | |
201 Number: version.MustParse("2.0.0"), | |
202 Series: "quantal", | |
203 Arch: "i386", | |
204 }, | |
205 tools.List{t200quantal32}, | |
206 }} { | |
thumper
2013/04/10 04:32:51
This line does my head in. I do find it easier to
rog
2013/04/10 08:30:32
+1.
i prefer the tests to be outside the function
TheMue
2013/04/10 09:25:00
And another +1.
fwereade
2013/04/10 23:07:30
Public opinion is clearly against me here, so I'll
| |
207 c.Logf("test %d", i) | |
208 actual, err := test.src.Filter(test.filter) | |
209 c.Check(actual, DeepEquals, test.expect) | |
210 if len(test.expect) > 0 { | |
211 c.Check(err, IsNil) | |
212 } else { | |
213 c.Check(err, Equals, tools.ErrNoMatches) | |
214 } | |
215 } | |
216 } | |
OLD | NEW |