LEFT | RIGHT |
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "launchpad.net/gnuflag" | 4 "launchpad.net/gnuflag" |
5 . "launchpad.net/gocheck" | 5 . "launchpad.net/gocheck" |
6 "launchpad.net/juju-core/cmd" | 6 "launchpad.net/juju-core/cmd" |
7 "launchpad.net/juju-core/environs" | 7 "launchpad.net/juju-core/environs" |
8 "launchpad.net/juju-core/environs/dummy" | 8 "launchpad.net/juju-core/environs/dummy" |
9 "launchpad.net/juju-core/juju/testing" | 9 "launchpad.net/juju-core/juju/testing" |
10 "launchpad.net/juju-core/version" | 10 "launchpad.net/juju-core/version" |
11 "net/http" | 11 "net/http" |
12 "os" | 12 "os" |
13 "reflect" | 13 "reflect" |
14 "time" | |
15 ) | 14 ) |
16 | 15 |
17 type CmdSuite struct { | 16 type CmdSuite struct { |
18 testing.JujuConnSuite | 17 testing.JujuConnSuite |
19 } | 18 } |
20 | 19 |
21 var _ = Suite(&CmdSuite{}) | 20 var _ = Suite(&CmdSuite{}) |
22 | 21 |
23 var config = ` | 22 var config = ` |
24 default: | 23 default: |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 testInit(c, com, append(args, "--environment", "walthamstow"), "
") | 98 testInit(c, com, append(args, "--environment", "walthamstow"), "
") |
100 assertConnName(c, com, "walthamstow") | 99 assertConnName(c, com, "walthamstow") |
101 | 100 |
102 com, args = cmdFunc() | 101 com, args = cmdFunc() |
103 testInit(c, com, append(args, "hotdog"), "unrecognized args.*") | 102 testInit(c, com, append(args, "hotdog"), "unrecognized args.*") |
104 } | 103 } |
105 } | 104 } |
106 | 105 |
107 func runCommand(com cmd.Command, args ...string) (opc chan dummy.Operation, errc
chan error) { | 106 func runCommand(com cmd.Command, args ...string) (opc chan dummy.Operation, errc
chan error) { |
108 errc = make(chan error, 1) | 107 errc = make(chan error, 1) |
109 » opc = make(chan dummy.Operation, 20) | 108 » opc = make(chan dummy.Operation, 200) |
110 dummy.Reset() | 109 dummy.Reset() |
111 dummy.Listen(opc) | 110 dummy.Listen(opc) |
112 go func() { | 111 go func() { |
113 // signal that we're done with this ops channel. | 112 // signal that we're done with this ops channel. |
114 defer dummy.Listen(nil) | 113 defer dummy.Listen(nil) |
115 | 114 |
116 err := com.Init(newFlagSet(), args) | 115 err := com.Init(newFlagSet(), args) |
117 if err != nil { | 116 if err != nil { |
118 errc <- err | 117 errc <- err |
119 return | 118 return |
120 } | 119 } |
121 | 120 |
122 err = com.Run(cmd.DefaultContext()) | 121 err = com.Run(cmd.DefaultContext()) |
123 errc <- err | 122 errc <- err |
124 }() | 123 }() |
125 return | 124 return |
126 } | 125 } |
127 | 126 |
128 func (*CmdSuite) TestBootstrapCommand(c *C) { | 127 func (*CmdSuite) TestBootstrapCommand(c *C) { |
129 // normal bootstrap | 128 // normal bootstrap |
130 opc, errc := runCommand(new(BootstrapCommand)) | 129 opc, errc := runCommand(new(BootstrapCommand)) |
131 c.Check(<-errc, IsNil) | 130 c.Check(<-errc, IsNil) |
132 c.Check((<-opc).(dummy.OpBootstrap).Env, Equals, "peckham") | 131 c.Check((<-opc).(dummy.OpBootstrap).Env, Equals, "peckham") |
133 | 132 |
134 // bootstrap with tool uploading - checking that a file | 133 // bootstrap with tool uploading - checking that a file |
135 // is uploaded should be sufficient, as the detailed semantics | 134 // is uploaded should be sufficient, as the detailed semantics |
136 // of UploadTools are tested in environs. | 135 // of UploadTools are tested in environs. |
137 time.Sleep(500 * time.Millisecond) | |
138 opc, errc = runCommand(new(BootstrapCommand), "--upload-tools") | 136 opc, errc = runCommand(new(BootstrapCommand), "--upload-tools") |
139 c.Check(<-errc, IsNil) | 137 c.Check(<-errc, IsNil) |
140 c.Check((<-opc).(dummy.OpPutFile).Env, Equals, "peckham") | 138 c.Check((<-opc).(dummy.OpPutFile).Env, Equals, "peckham") |
141 c.Check((<-opc).(dummy.OpBootstrap).Env, Equals, "peckham") | 139 c.Check((<-opc).(dummy.OpBootstrap).Env, Equals, "peckham") |
142 | 140 |
143 envs, err := environs.ReadEnvirons("") | 141 envs, err := environs.ReadEnvirons("") |
144 c.Assert(err, IsNil) | 142 c.Assert(err, IsNil) |
145 env, err := envs.Open("peckham") | 143 env, err := envs.Open("peckham") |
146 c.Assert(err, IsNil) | 144 c.Assert(err, IsNil) |
147 | 145 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 return com, com.Init(newFlagSet(), args) | 285 return com, com.Init(newFlagSet(), args) |
288 } | 286 } |
289 | 287 |
290 func (*CmdSuite) TestUnexposeCommandInit(c *C) { | 288 func (*CmdSuite) TestUnexposeCommandInit(c *C) { |
291 // missing args | 289 // missing args |
292 _, err := initUnexposeCommand() | 290 _, err := initUnexposeCommand() |
293 c.Assert(err, ErrorMatches, "no service name specified") | 291 c.Assert(err, ErrorMatches, "no service name specified") |
294 | 292 |
295 // environment tested elsewhere | 293 // environment tested elsewhere |
296 } | 294 } |
LEFT | RIGHT |