Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1302)

Delta Between Two Patch Sets: cmd/juju/bootstrap_test.go

Issue 94060044: cmd/juju: refactor --series to use StringsValue
Left Patch Set: cmd/juju: refactor --series to use StringsValue Created 9 years, 10 months ago
Right Patch Set: cmd/juju: refactor --series to use StringsValue Created 9 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« cmd/juju/bootstrap.go ('K') | « cmd/juju/bootstrap.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package main 4 package main
5 5
6 import ( 6 import (
7 "bytes" 7 "bytes"
8 "fmt" 8 "fmt"
9 "strings" 9 "strings"
10 10
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 err: `ambiguous constraints: "mem" overlaps with "instance-type"`, 298 err: `ambiguous constraints: "mem" overlaps with "instance-type"`,
299 }, { 299 }, {
300 info: "bad --series", 300 info: "bad --series",
301 args: []string{"--series", "1bad1"}, 301 args: []string{"--series", "1bad1"},
302 err: `invalid value "1bad1" for flag --series: invalid series name "1ba d1"`, 302 err: `invalid value "1bad1" for flag --series: invalid series name "1ba d1"`,
303 }, { 303 }, {
304 info: "lonely --series", 304 info: "lonely --series",
305 args: []string{"--series", "fine"}, 305 args: []string{"--series", "fine"},
306 err: `--series requires --upload-tools`, 306 err: `--series requires --upload-tools`,
307 }, { 307 }, {
308 info: "lonely --upload-series",
309 args: []string{"--upload-series", "fine"},
310 err: `--upload-series requires --upload-tools`,
311 }, {
312 info: "--upload-series with --series",
313 args: []string{"--upload-tools", "--upload-series", "foo", "--series", " bar"},
314 err: `--upload-series and --series can't be used together`,
315 }, {
308 info: "bad environment", 316 info: "bad environment",
309 version: "1.2.3-%LTS%-amd64", 317 version: "1.2.3-%LTS%-amd64",
310 args: []string{"-e", "brokenenv"}, 318 args: []string{"-e", "brokenenv"},
311 err: `dummy.Bootstrap is broken`, 319 err: `dummy.Bootstrap is broken`,
312 }, { 320 }, {
313 info: "constraints", 321 info: "constraints",
314 args: []string{"--constraints", "mem=4G cpu-cores=4"}, 322 args: []string{"--constraints", "mem=4G cpu-cores=4"},
315 constraints: constraints.MustParse("mem=4G cpu-cores=4"), 323 constraints: constraints.MustParse("mem=4G cpu-cores=4"),
316 }, { 324 }, {
317 info: "unsupported constraint passed through but no error", 325 info: "unsupported constraint passed through but no error",
(...skipping 26 matching lines...) Expand all
344 version: "1.2.3-%LTS%-amd64", 352 version: "1.2.3-%LTS%-amd64",
345 args: []string{"--upload-tools"}, 353 args: []string{"--upload-tools"},
346 uploads: []string{ 354 uploads: []string{
347 "1.2.3.1-raring-amd64", 355 "1.2.3.1-raring-amd64",
348 "1.2.3.1-precise-amd64", 356 "1.2.3.1-precise-amd64",
349 "1.2.3.1-trusty-amd64", 357 "1.2.3.1-trusty-amd64",
350 }, 358 },
351 }, { 359 }, {
352 info: "--upload-tools rejects invalid series", 360 info: "--upload-tools rejects invalid series",
353 version: "1.2.3-saucy-amd64", 361 version: "1.2.3-saucy-amd64",
354 » args: []string{"--upload-tools", "--series", "ping,ping,pong"}, 362 » args: []string{"--upload-tools", "--upload-series", "ping,ping,pong"} ,
355 err: `invalid series "ping"`, 363 err: `invalid series "ping"`,
356 }, { 364 }, {
357 info: "--upload-tools rejects mismatched arch", 365 info: "--upload-tools rejects mismatched arch",
358 version: "1.3.3-saucy-amd64", 366 version: "1.3.3-saucy-amd64",
359 hostArch: "amd64", 367 hostArch: "amd64",
360 args: []string{"--upload-tools", "--constraints", "arch=ppc64"}, 368 args: []string{"--upload-tools", "--constraints", "arch=ppc64"},
361 err: `cannot build tools for "ppc64" using a machine running on "am d64"`, 369 err: `cannot build tools for "ppc64" using a machine running on "am d64"`,
362 }, { 370 }, {
363 info: "--upload-tools rejects non-supported arch", 371 info: "--upload-tools rejects non-supported arch",
364 version: "1.3.3-saucy-arm64", 372 version: "1.3.3-saucy-arm64",
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 ctx := coretesting.Context(c) 406 ctx := coretesting.Context(c)
399 code := cmd.Main(&BootstrapCommand{}, ctx, nil) 407 code := cmd.Main(&BootstrapCommand{}, ctx, nil)
400 c.Check(code, gc.Equals, 0) 408 c.Check(code, gc.Equals, 0)
401 409
402 ctx2 := coretesting.Context(c) 410 ctx2 := coretesting.Context(c)
403 code2 := cmd.Main(&BootstrapCommand{}, ctx2, nil) 411 code2 := cmd.Main(&BootstrapCommand{}, ctx2, nil)
404 c.Check(code2, gc.Equals, 1) 412 c.Check(code2, gc.Equals, 1)
405 expectedErrText := "error: environment is already bootstrapped\n" 413 expectedErrText := "error: environment is already bootstrapped\n"
406 c.Check(coretesting.Stderr(ctx2), gc.Equals, expectedErrText) 414 c.Check(coretesting.Stderr(ctx2), gc.Equals, expectedErrText)
407 c.Check(coretesting.Stdout(ctx2), gc.Equals, "") 415 c.Check(coretesting.Stdout(ctx2), gc.Equals, "")
416 }
417
418 func (s *BootstrapSuite) TestSeriesDeprecation(c *gc.C) {
419 ctx := s.checkSeriesArg(c, "--series")
420 c.Check(coretesting.Stderr(ctx), gc.Equals, "Use of --series is deprecat ed. Please use --upload-series instead.\n")
421 }
422
423 func (s *BootstrapSuite) TestNoDeprecationWithUploadSeries(c *gc.C) {
424 ctx := s.checkSeriesArg(c, "--upload-series")
425 c.Check(coretesting.Stderr(ctx), gc.Equals, "")
426 }
427
428 func (s *BootstrapSuite) checkSeriesArg(c *gc.C, argVariant string) *cmd.Context {
429 _bootstrap := &fakeBootstrapFuncs{}
430 s.PatchValue(&getBootstrapFuncs, func() BootstrapInterface {
431 return _bootstrap
432 })
433 _, fake := makeEmptyFakeHome(c)
434 defer fake.Restore()
435
436 bootstrapCommand := BootstrapCommand{}
437 ctx := coretesting.Context(c)
438 code := cmd.Main(&bootstrapCommand, ctx, []string{"--upload-tools", argV ariant, "foo,bar"})
thumper 2014/05/08 01:53:05 A better call would be the testing.RunCommand:
menn0 2014/05/08 02:35:48 I got cmd.Main pattern this from the other tests i
thumper 2014/05/08 04:53:52 Sure, that would be good.
439
440 c.Check(code, gc.Equals, 0)
441 c.Check(_bootstrap.uploadToolsSeries, gc.DeepEquals, []string{"foo", "ba r"})
442 return ctx
408 } 443 }
409 444
410 func (s *BootstrapSuite) TestBootstrapJenvWarning(c *gc.C) { 445 func (s *BootstrapSuite) TestBootstrapJenvWarning(c *gc.C) {
411 env, fake := makeEmptyFakeHome(c) 446 env, fake := makeEmptyFakeHome(c)
412 defer fake.Restore() 447 defer fake.Restore()
413 defaultSeriesVersion := version.Current 448 defaultSeriesVersion := version.Current
414 defaultSeriesVersion.Series = config.PreferredSeries(env.Config()) 449 defaultSeriesVersion.Series = config.PreferredSeries(env.Config())
415 // Force a dev version by having an odd minor version number. 450 // Force a dev version by having an odd minor version number.
416 // This is because we have not uploaded any tools and auto 451 // This is because we have not uploaded any tools and auto
417 // upload is only enabled for dev versions. 452 // upload is only enabled for dev versions.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 vAll = joinBinaryVersions(v100All, v120All, v190All, v200All) 732 vAll = joinBinaryVersions(v100All, v120All, v190All, v200All)
698 ) 733 )
699 734
700 func joinBinaryVersions(versions ...[]version.Binary) []version.Binary { 735 func joinBinaryVersions(versions ...[]version.Binary) []version.Binary {
701 var all []version.Binary 736 var all []version.Binary
702 for _, versions := range versions { 737 for _, versions := range versions {
703 all = append(all, versions...) 738 all = append(all, versions...)
704 } 739 }
705 return all 740 return all
706 } 741 }
742
743 // TODO(menn0): This fake BootstrapInterface implementation is
744 // currently quite minimal but could be easily extended to cover more
745 // test scenarios. This could help improve some of the tests in this
746 // file which execute large amounts of external functionality.
747 type fakeBootstrapFuncs struct {
748 uploadToolsSeries []string
749 }
750
751 func (fake *fakeBootstrapFuncs) EnsureNotBootstrapped(env environs.Environ) erro r {
752 return nil
753 }
754
755 func (fake *fakeBootstrapFuncs) UploadTools(ctx environs.BootstrapContext, env e nvirons.Environ, toolsArch *string, forceVersion bool, bootstrapSeries ...string ) error {
756 fake.uploadToolsSeries = bootstrapSeries
757 return nil
758 }
759
760 func (fake fakeBootstrapFuncs) Bootstrap(ctx environs.BootstrapContext, env envi rons.Environ, args environs.BootstrapParams) error {
761 return nil
762 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b