LEFT | RIGHT |
(no file at all) | |
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "bytes" | 4 "bytes" |
5 "io/ioutil" | 5 "io/ioutil" |
6 . "launchpad.net/gocheck" | 6 . "launchpad.net/gocheck" |
7 "launchpad.net/juju-core/cmd" | 7 "launchpad.net/juju-core/cmd" |
8 "launchpad.net/juju-core/environs" | 8 "launchpad.net/juju-core/environs" |
9 "launchpad.net/juju-core/environs/dummy" | 9 "launchpad.net/juju-core/environs/dummy" |
10 "launchpad.net/juju-core/state" | 10 "launchpad.net/juju-core/state" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 ctx, err := runSyncToolsCommand(c, "-e", "test-target", "--public") | 190 ctx, err := runSyncToolsCommand(c, "-e", "test-target", "--public") |
191 c.Assert(err, IsNil) | 191 c.Assert(err, IsNil) |
192 c.Assert(ctx, NotNil) | 192 c.Assert(ctx, NotNil) |
193 targetTools, err := environs.ListTools(targetEnv, 1) | 193 targetTools, err := environs.ListTools(targetEnv, 1) |
194 c.Assert(err, IsNil) | 194 c.Assert(err, IsNil) |
195 // newest tools added to the private bucket | 195 // newest tools added to the private bucket |
196 assertToolsList(c, targetTools.Public, "1.9.0-quantal-amd64") | 196 assertToolsList(c, targetTools.Public, "1.9.0-quantal-amd64") |
197 c.Assert(targetTools.Private, HasLen, 0) | 197 c.Assert(targetTools.Private, HasLen, 0) |
198 } | 198 } |
199 | 199 |
200 type toolSuite struct{} | |
201 | |
202 var _ = Suite(&toolSuite{}) | |
203 | |
204 func mustParseTools(major, minor, patch, build int, series string, arch string)
*state.Tools { | 200 func mustParseTools(major, minor, patch, build int, series string, arch string)
*state.Tools { |
205 return &state.Tools{ | 201 return &state.Tools{ |
206 Binary: version.Binary{ | 202 Binary: version.Binary{ |
207 Number: version.Number{major, minor, patch, build}, | 203 Number: version.Number{major, minor, patch, build}, |
208 Series: series, | 204 Series: series, |
209 Arch: arch}} | 205 Arch: arch}} |
210 } | 206 } |
211 | 207 |
212 var ( | 208 var ( |
213 t1000precise = mustParseTools(1, 0, 0, 0, "precise", "amd64") | 209 t1000precise = mustParseTools(1, 0, 0, 0, "precise", "amd64") |
214 t1000quantal = mustParseTools(1, 0, 0, 0, "quantal", "amd64") | 210 t1000quantal = mustParseTools(1, 0, 0, 0, "quantal", "amd64") |
215 t1000quantal32 = mustParseTools(1, 0, 0, 0, "quantal", "i386") | 211 t1000quantal32 = mustParseTools(1, 0, 0, 0, "quantal", "i386") |
216 t1900quantal = mustParseTools(1, 9, 0, 0, "quantal", "amd64") | 212 t1900quantal = mustParseTools(1, 9, 0, 0, "quantal", "amd64") |
217 t2000precise = mustParseTools(2, 0, 0, 0, "precise", "amd64") | 213 t2000precise = mustParseTools(2, 0, 0, 0, "precise", "amd64") |
218 ) | 214 ) |
219 | |
220 func (s *toolSuite) TestFindNewestOneTool(c *C) { | |
221 for i, t := range []*state.Tools{ | |
222 t1000precise, | |
223 t1000quantal, | |
224 t1900quantal, | |
225 t2000precise, | |
226 } { | |
227 c.Log("test: %d %s", i, t.Binary.String()) | |
228 toolList := []*state.Tools{t} | |
229 res := findNewest(toolList) | |
230 c.Assert(res, HasLen, 1) | |
231 c.Assert(res[0], Equals, t) | |
232 } | |
233 } | |
234 | |
235 func (s *toolSuite) TestFindNewestOnlyOneBest(c *C) { | |
236 res := findNewest([]*state.Tools{t1000precise, t1900quantal}) | |
237 c.Assert(res, HasLen, 1) | |
238 c.Assert(res[0], Equals, t1900quantal) | |
239 } | |
240 | |
241 func (s *toolSuite) TestFindNewestMultipleBest(c *C) { | |
242 source := []*state.Tools{t1000precise, t1000quantal} | |
243 res := findNewest(source) | |
244 c.Assert(res, HasLen, 2) | |
245 // Order isn't strictly specified, but findNewest currently returns the | |
246 // order in source, so it makes the test easier to write | |
247 c.Assert(res, DeepEquals, source) | |
248 } | |
249 | |
250 func (s *toolSuite) TestFindMissingNoTarget(c *C) { | |
251 for i, t := range [][]*state.Tools{ | |
252 []*state.Tools{t1000precise}, | |
253 []*state.Tools{t1000precise, t1000quantal}, | |
254 } { | |
255 c.Log("test: %d", i) | |
256 res := findMissing(t, []*state.Tools(nil)) | |
257 c.Assert(res, DeepEquals, t) | |
258 } | |
259 } | |
260 | |
261 func (s *toolSuite) TestFindMissingSameEntries(c *C) { | |
262 for i, t := range [][]*state.Tools{ | |
263 []*state.Tools{t1000precise}, | |
264 []*state.Tools{t1000precise, t1000quantal}, | |
265 } { | |
266 c.Log("test: %d", i) | |
267 res := findMissing(t, t) | |
268 c.Assert(res, HasLen, 0) | |
269 } | |
270 } | |
271 | |
272 func (s *toolSuite) TestFindHasVersionNotSeries(c *C) { | |
273 res := findMissing( | |
274 []*state.Tools{t1000precise, t1000quantal}, | |
275 []*state.Tools{t1000quantal}) | |
276 c.Assert(res, HasLen, 1) | |
277 c.Assert(res[0], Equals, t1000precise) | |
278 res = findMissing( | |
279 []*state.Tools{t1000precise, t1000quantal}, | |
280 []*state.Tools{t1000precise}) | |
281 c.Assert(res, HasLen, 1) | |
282 c.Assert(res[0], Equals, t1000quantal) | |
283 } | |
284 | |
285 func (s *toolSuite) TestFindHasDifferentArch(c *C) { | |
286 res := findMissing( | |
287 []*state.Tools{t1000quantal, t1000quantal32}, | |
288 []*state.Tools{t1000quantal}) | |
289 c.Assert(res, HasLen, 1) | |
290 c.Assert(res[0], Equals, t1000quantal32) | |
291 res = findMissing( | |
292 []*state.Tools{t1000quantal, t1000quantal32}, | |
293 []*state.Tools{t1000quantal32}) | |
294 c.Assert(res, HasLen, 1) | |
295 c.Assert(res[0], Equals, t1000quantal) | |
296 } | |
LEFT | RIGHT |