Index: environs/jujutest/tests.go |
=== modified file 'environs/jujutest/tests.go' |
--- environs/jujutest/tests.go 2013-01-23 16:31:08 +0000 |
+++ environs/jujutest/tests.go 2013-02-25 10:37:40 +0000 |
@@ -6,9 +6,8 @@ |
"io/ioutil" |
. "launchpad.net/gocheck" |
"launchpad.net/juju-core/environs" |
- "launchpad.net/juju-core/juju/testing" |
"launchpad.net/juju-core/state" |
- coretesting "launchpad.net/juju-core/testing" |
+ "launchpad.net/juju-core/testing" |
"launchpad.net/juju-core/trivial" |
"net/http" |
) |
@@ -19,7 +18,7 @@ |
// is opened once for each test, and some potentially expensive operations |
// may be executed. |
type Tests struct { |
- coretesting.LoggingSuite |
+ testing.LoggingSuite |
Config map[string]interface{} |
Env environs.Environ |
} |
@@ -51,67 +50,81 @@ |
delete(m, "admin-secret") |
env, err := environs.NewFromAttrs(m) |
c.Assert(err, IsNil) |
- err = environs.Bootstrap(env, false, panicWrite) |
+ err = Bootstrap(env, false) |
c.Assert(err, ErrorMatches, ".*admin-secret is required for bootstrap") |
} |
func (t *Tests) TestStartStop(c *C) { |
e := t.Open(c) |
+ err := Bootstrap(e, false) |
+ c.Assert(err, IsNil) |
insts, err := e.Instances(nil) |
c.Assert(err, IsNil) |
c.Assert(insts, HasLen, 0) |
- inst0, err := e.StartInstance("0", testing.InvalidStateInfo("0"), testing.InvalidAPIInfo("0"), nil) |
- c.Assert(err, IsNil) |
- c.Assert(inst0, NotNil) |
- id0 := inst0.Id() |
- |
- inst1, err := e.StartInstance("1", testing.InvalidStateInfo("1"), testing.InvalidAPIInfo("1"), nil) |
+ inst1, err := StartInstance(e, "1") |
c.Assert(err, IsNil) |
c.Assert(inst1, NotNil) |
id1 := inst1.Id() |
- insts, err = e.Instances([]state.InstanceId{id0, id1}) |
+ inst2, err := StartInstance(e, "2") |
+ c.Assert(err, IsNil) |
+ c.Assert(inst2, NotNil) |
+ id2 := inst2.Id() |
+ |
+ insts, err = e.Instances([]state.InstanceId{id1, id2}) |
c.Assert(err, IsNil) |
c.Assert(insts, HasLen, 2) |
- c.Assert(insts[0].Id(), Equals, id0) |
- c.Assert(insts[1].Id(), Equals, id1) |
+ c.Assert(insts[0].Id(), Equals, id1) |
+ c.Assert(insts[1].Id(), Equals, id2) |
// order of results is not specified |
insts, err = e.AllInstances() |
c.Assert(err, IsNil) |
- c.Assert(insts, HasLen, 2) |
- c.Assert(insts[0].Id(), Not(Equals), insts[1].Id()) |
+ assertInstancePresent(c, id1, insts) |
+ assertInstancePresent(c, id2, insts) |
- err = e.StopInstances([]environs.Instance{inst0}) |
+ err = e.StopInstances([]environs.Instance{inst1}) |
c.Assert(err, IsNil) |
- insts, err = e.Instances([]state.InstanceId{id0, id1}) |
+ insts, err = e.Instances([]state.InstanceId{id1, id2}) |
c.Assert(err, Equals, environs.ErrPartialInstances) |
c.Assert(insts[0], IsNil) |
- c.Assert(insts[1].Id(), Equals, id1) |
+ c.Assert(insts[1].Id(), Equals, id2) |
insts, err = e.AllInstances() |
c.Assert(err, IsNil) |
- c.Assert(insts[0].Id(), Equals, id1) |
+ assertInstancePresent(c, id2, insts) |
+} |
+ |
+func assertInstancePresent(c *C, id state.InstanceId, insts []environs.Instance) { |
+ for _, inst := range insts { |
+ if inst == nil { |
+ continue |
+ } |
+ if inst.Id() == id { |
+ return |
+ } |
+ } |
+ c.Fatalf("%q not present", id) |
} |
func (t *Tests) TestBootstrap(c *C) { |
// TODO tests for Bootstrap(true) |
e := t.Open(c) |
- err := environs.Bootstrap(e, false, panicWrite) |
+ err := Bootstrap(e, false) |
c.Assert(err, IsNil) |
info, apiInfo, err := e.StateInfo() |
c.Check(info.Addrs, Not(HasLen), 0) |
c.Check(apiInfo.Addrs, Not(HasLen), 0) |
- err = environs.Bootstrap(e, false, panicWrite) |
+ err = Bootstrap(e, false) |
c.Assert(err, ErrorMatches, "environment is already bootstrapped") |
e2 := t.Open(c) |
- err = environs.Bootstrap(e2, false, panicWrite) |
+ err = Bootstrap(e2, false) |
c.Assert(err, ErrorMatches, "environment is already bootstrapped") |
info2, apiInfo2, err := e2.StateInfo() |
@@ -124,10 +137,10 @@ |
// Open again because Destroy invalidates old environments. |
e3 := t.Open(c) |
- err = environs.Bootstrap(e3, false, panicWrite) |
+ err = Bootstrap(e3, false) |
c.Assert(err, IsNil) |
- err = environs.Bootstrap(e3, false, panicWrite) |
+ err = Bootstrap(e3, false) |
c.Assert(err, NotNil) |
} |