Left: | ||
Right: |
OLD | NEW |
---|---|
1 package jujutest | 1 package jujutest |
2 | 2 |
3 import ( | 3 import ( |
4 "bytes" | 4 "bytes" |
5 "io" | 5 "io" |
6 "io/ioutil" | 6 "io/ioutil" |
7 . "launchpad.net/gocheck" | 7 . "launchpad.net/gocheck" |
8 "launchpad.net/juju-core/environs" | 8 "launchpad.net/juju-core/environs" |
9 "launchpad.net/juju-core/juju/testing" | 9 "launchpad.net/juju-core/juju/testing" |
10 coretesting "launchpad.net/juju-core/testing" | 10 coretesting "launchpad.net/juju-core/testing" |
11 "launchpad.net/juju-core/trivial" | 11 "launchpad.net/juju-core/trivial" |
12 "net/http" | 12 "net/http" |
13 ) | 13 ) |
14 | 14 |
15 // Tests is a gocheck suite containing tests verifying juju functionality | 15 // Tests is a gocheck suite containing tests verifying juju functionality |
16 // against the environment with Name that must exist within Environs. The | 16 // against the environment with Name that must exist within Environs. The |
17 // tests are not designed to be run against a live server - the Environ | 17 // tests are not designed to be run against a live server - the Environ |
18 // is opened once for each test, and some potentially expensive operations | 18 // is opened once for each test, and some potentially expensive operations |
19 // may be executed. | 19 // may be executed. |
20 type Tests struct { | 20 type Tests struct { |
21 coretesting.LoggingSuite | 21 coretesting.LoggingSuite |
22 » Environs *environs.Environs | 22 » Environs *environs.Environs |
23 » Name string | 23 » Name string |
24 » Env environs.Environ | 24 » Env environs.Environ |
25 » ServerCertAndKey []byte | |
niemeyer
2012/11/14 13:59:07
StateServerPEM
rog
2012/11/14 15:04:14
Done.
| |
25 } | 26 } |
26 | 27 |
27 // Open opens an instance of the testing environment. | 28 // Open opens an instance of the testing environment. |
28 func (t *Tests) Open(c *C) environs.Environ { | 29 func (t *Tests) Open(c *C) environs.Environ { |
29 e, err := t.Environs.Open(t.Name) | 30 e, err := t.Environs.Open(t.Name) |
30 c.Assert(err, IsNil, Commentf("opening environ %q", t.Name)) | 31 c.Assert(err, IsNil, Commentf("opening environ %q", t.Name)) |
31 c.Assert(e, NotNil) | 32 c.Assert(e, NotNil) |
32 return e | 33 return e |
33 } | 34 } |
34 | 35 |
35 func (t *Tests) SetUpTest(c *C) { | 36 func (t *Tests) SetUpTest(c *C) { |
36 t.LoggingSuite.SetUpTest(c) | 37 t.LoggingSuite.SetUpTest(c) |
37 t.Env = t.Open(c) | 38 t.Env = t.Open(c) |
38 } | 39 } |
39 | 40 |
40 func (t *Tests) TearDownTest(c *C) { | 41 func (t *Tests) TearDownTest(c *C) { |
41 if t.Env != nil { | 42 if t.Env != nil { |
42 err := t.Env.Destroy(nil) | 43 err := t.Env.Destroy(nil) |
43 c.Check(err, IsNil) | 44 c.Check(err, IsNil) |
44 t.Env = nil | 45 t.Env = nil |
45 } | 46 } |
46 t.LoggingSuite.TearDownTest(c) | 47 t.LoggingSuite.TearDownTest(c) |
47 } | 48 } |
48 | 49 |
49 func (t *Tests) TestBootstrapWithoutAdminSecret(c *C) { | 50 func (t *Tests) TestBootstrapWithoutAdminSecret(c *C) { |
50 m := t.Env.Config().AllAttrs() | 51 m := t.Env.Config().AllAttrs() |
51 delete(m, "admin-secret") | 52 delete(m, "admin-secret") |
52 env, err := environs.NewFromAttrs(m) | 53 env, err := environs.NewFromAttrs(m) |
53 c.Assert(err, IsNil) | 54 c.Assert(err, IsNil) |
54 » err = env.Bootstrap(false) | 55 » err = env.Bootstrap(false, t.ServerCertAndKey) |
55 c.Assert(err, ErrorMatches, ".*admin-secret is required for bootstrap") | 56 c.Assert(err, ErrorMatches, ".*admin-secret is required for bootstrap") |
56 } | 57 } |
57 | 58 |
58 func (t *Tests) TestStartStop(c *C) { | 59 func (t *Tests) TestStartStop(c *C) { |
59 e := t.Open(c) | 60 e := t.Open(c) |
60 | 61 |
61 insts, err := e.Instances(nil) | 62 insts, err := e.Instances(nil) |
62 c.Assert(err, IsNil) | 63 c.Assert(err, IsNil) |
63 c.Assert(insts, HasLen, 0) | 64 c.Assert(insts, HasLen, 0) |
64 | 65 |
(...skipping 28 matching lines...) Expand all Loading... | |
93 c.Assert(insts[1].Id(), Equals, id1) | 94 c.Assert(insts[1].Id(), Equals, id1) |
94 | 95 |
95 insts, err = e.AllInstances() | 96 insts, err = e.AllInstances() |
96 c.Assert(err, IsNil) | 97 c.Assert(err, IsNil) |
97 c.Assert(insts[0].Id(), Equals, id1) | 98 c.Assert(insts[0].Id(), Equals, id1) |
98 } | 99 } |
99 | 100 |
100 func (t *Tests) TestBootstrap(c *C) { | 101 func (t *Tests) TestBootstrap(c *C) { |
101 // TODO tests for Bootstrap(true) | 102 // TODO tests for Bootstrap(true) |
102 e := t.Open(c) | 103 e := t.Open(c) |
103 » err := e.Bootstrap(false) | 104 » err := e.Bootstrap(false, t.ServerCertAndKey) |
104 c.Assert(err, IsNil) | 105 c.Assert(err, IsNil) |
105 | 106 |
106 info, err := e.StateInfo() | 107 info, err := e.StateInfo() |
107 c.Assert(info, NotNil) | 108 c.Assert(info, NotNil) |
108 c.Check(info.Addrs, Not(HasLen), 0) | 109 c.Check(info.Addrs, Not(HasLen), 0) |
109 | 110 |
110 » err = e.Bootstrap(false) | 111 » err = e.Bootstrap(false, t.ServerCertAndKey) |
111 c.Assert(err, ErrorMatches, "environment is already bootstrapped") | 112 c.Assert(err, ErrorMatches, "environment is already bootstrapped") |
112 | 113 |
113 e2 := t.Open(c) | 114 e2 := t.Open(c) |
114 » err = e2.Bootstrap(false) | 115 » err = e2.Bootstrap(false, t.ServerCertAndKey) |
115 c.Assert(err, ErrorMatches, "environment is already bootstrapped") | 116 c.Assert(err, ErrorMatches, "environment is already bootstrapped") |
116 | 117 |
117 info2, err := e2.StateInfo() | 118 info2, err := e2.StateInfo() |
118 c.Check(info2, DeepEquals, info) | 119 c.Check(info2, DeepEquals, info) |
119 | 120 |
120 err = e2.Destroy(nil) | 121 err = e2.Destroy(nil) |
121 c.Assert(err, IsNil) | 122 c.Assert(err, IsNil) |
122 | 123 |
123 // Open again because Destroy invalidates old environments. | 124 // Open again because Destroy invalidates old environments. |
124 e3 := t.Open(c) | 125 e3 := t.Open(c) |
125 | 126 |
126 » err = e3.Bootstrap(false) | 127 » err = e3.Bootstrap(false, t.ServerCertAndKey) |
127 c.Assert(err, IsNil) | 128 c.Assert(err, IsNil) |
128 | 129 |
129 » err = e3.Bootstrap(false) | 130 » err = e3.Bootstrap(false, t.ServerCertAndKey) |
130 c.Assert(err, NotNil) | 131 c.Assert(err, NotNil) |
131 } | 132 } |
132 | 133 |
133 var noRetry = trivial.AttemptStrategy{} | 134 var noRetry = trivial.AttemptStrategy{} |
134 | 135 |
135 func (t *Tests) TestPersistence(c *C) { | 136 func (t *Tests) TestPersistence(c *C) { |
136 storage := t.Open(c).Storage() | 137 storage := t.Open(c).Storage() |
137 | 138 |
138 names := []string{ | 139 names := []string{ |
139 "aa", | 140 "aa", |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 } | 224 } |
224 c.Logf("get retrying after earlier get succeeded. *sigh*.") | 225 c.Logf("get retrying after earlier get succeeded. *sigh*.") |
225 } | 226 } |
226 c.Assert(err, IsNil) | 227 c.Assert(err, IsNil) |
227 data, err = ioutil.ReadAll(resp.Body) | 228 data, err = ioutil.ReadAll(resp.Body) |
228 c.Assert(err, IsNil) | 229 c.Assert(err, IsNil) |
229 defer resp.Body.Close() | 230 defer resp.Body.Close() |
230 c.Assert(resp.StatusCode, Equals, 200, Commentf("error response: %s", da ta)) | 231 c.Assert(resp.StatusCode, Equals, 200, Commentf("error response: %s", da ta)) |
231 c.Check(data, DeepEquals, contents) | 232 c.Check(data, DeepEquals, contents) |
232 } | 233 } |
OLD | NEW |