| OLD | NEW |
| 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" |
| 14 ) | 15 ) |
| 15 | 16 |
| 16 type CmdSuite struct { | 17 type CmdSuite struct { |
| 17 testing.JujuConnSuite | 18 testing.JujuConnSuite |
| 18 } | 19 } |
| 19 | 20 |
| 20 var _ = Suite(&CmdSuite{}) | 21 var _ = Suite(&CmdSuite{}) |
| 21 | 22 |
| 22 var config = ` | 23 var config = ` |
| 23 default: | 24 default: |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 testInit(c, com, append(args, "--environment", "walthamstow"), "
") | 99 testInit(c, com, append(args, "--environment", "walthamstow"), "
") |
| 99 assertConnName(c, com, "walthamstow") | 100 assertConnName(c, com, "walthamstow") |
| 100 | 101 |
| 101 com, args = cmdFunc() | 102 com, args = cmdFunc() |
| 102 testInit(c, com, append(args, "hotdog"), "unrecognized args.*") | 103 testInit(c, com, append(args, "hotdog"), "unrecognized args.*") |
| 103 } | 104 } |
| 104 } | 105 } |
| 105 | 106 |
| 106 func runCommand(com cmd.Command, args ...string) (opc chan dummy.Operation, errc
chan error) { | 107 func runCommand(com cmd.Command, args ...string) (opc chan dummy.Operation, errc
chan error) { |
| 107 errc = make(chan error, 1) | 108 errc = make(chan error, 1) |
| 108 » opc = make(chan dummy.Operation) | 109 » opc = make(chan dummy.Operation, 20) |
| 109 dummy.Reset() | 110 dummy.Reset() |
| 110 dummy.Listen(opc) | 111 dummy.Listen(opc) |
| 111 go func() { | 112 go func() { |
| 112 // signal that we're done with this ops channel. | 113 // signal that we're done with this ops channel. |
| 113 defer dummy.Listen(nil) | 114 defer dummy.Listen(nil) |
| 114 | 115 |
| 115 err := com.Init(newFlagSet(), args) | 116 err := com.Init(newFlagSet(), args) |
| 116 if err != nil { | 117 if err != nil { |
| 117 errc <- err | 118 errc <- err |
| 118 return | 119 return |
| 119 } | 120 } |
| 120 | 121 |
| 121 err = com.Run(cmd.DefaultContext()) | 122 err = com.Run(cmd.DefaultContext()) |
| 122 errc <- err | 123 errc <- err |
| 123 }() | 124 }() |
| 124 return | 125 return |
| 125 } | 126 } |
| 126 | 127 |
| 127 func (*CmdSuite) TestBootstrapCommand(c *C) { | 128 func (*CmdSuite) TestBootstrapCommand(c *C) { |
| 128 // normal bootstrap | 129 // normal bootstrap |
| 129 opc, errc := runCommand(new(BootstrapCommand)) | 130 opc, errc := runCommand(new(BootstrapCommand)) |
| 131 c.Check(<-errc, IsNil) |
| 130 c.Check((<-opc).(dummy.OpBootstrap).Env, Equals, "peckham") | 132 c.Check((<-opc).(dummy.OpBootstrap).Env, Equals, "peckham") |
| 131 c.Check(<-errc, IsNil) | |
| 132 | 133 |
| 133 // bootstrap with tool uploading - checking that a file | 134 // bootstrap with tool uploading - checking that a file |
| 134 // is uploaded should be sufficient, as the detailed semantics | 135 // is uploaded should be sufficient, as the detailed semantics |
| 135 // of UploadTools are tested in environs. | 136 // of UploadTools are tested in environs. |
| 137 time.Sleep(500 * time.Millisecond) |
| 136 opc, errc = runCommand(new(BootstrapCommand), "--upload-tools") | 138 opc, errc = runCommand(new(BootstrapCommand), "--upload-tools") |
| 139 c.Check(<-errc, IsNil) |
| 137 c.Check((<-opc).(dummy.OpPutFile).Env, Equals, "peckham") | 140 c.Check((<-opc).(dummy.OpPutFile).Env, Equals, "peckham") |
| 138 c.Check((<-opc).(dummy.OpBootstrap).Env, Equals, "peckham") | 141 c.Check((<-opc).(dummy.OpBootstrap).Env, Equals, "peckham") |
| 139 c.Check(<-errc, IsNil) | |
| 140 | 142 |
| 141 envs, err := environs.ReadEnvirons("") | 143 envs, err := environs.ReadEnvirons("") |
| 142 c.Assert(err, IsNil) | 144 c.Assert(err, IsNil) |
| 143 env, err := envs.Open("peckham") | 145 env, err := envs.Open("peckham") |
| 144 c.Assert(err, IsNil) | 146 c.Assert(err, IsNil) |
| 145 | 147 |
| 146 oldVarDir := environs.VarDir | 148 oldVarDir := environs.VarDir |
| 147 defer func() { | 149 defer func() { |
| 148 environs.VarDir = oldVarDir | 150 environs.VarDir = oldVarDir |
| 149 }() | 151 }() |
| 150 environs.VarDir = c.MkDir() | 152 environs.VarDir = c.MkDir() |
| 151 | 153 |
| 152 tools, err := environs.FindTools(env, version.Current, environs.CompatVe
rsion) | 154 tools, err := environs.FindTools(env, version.Current, environs.CompatVe
rsion) |
| 153 c.Assert(err, IsNil) | 155 c.Assert(err, IsNil) |
| 154 resp, err := http.Get(tools.URL) | 156 resp, err := http.Get(tools.URL) |
| 155 c.Assert(err, IsNil) | 157 c.Assert(err, IsNil) |
| 156 defer resp.Body.Close() | 158 defer resp.Body.Close() |
| 157 | 159 |
| 158 err = environs.UnpackTools(tools, resp.Body) | 160 err = environs.UnpackTools(tools, resp.Body) |
| 159 c.Assert(err, IsNil) | 161 c.Assert(err, IsNil) |
| 160 | 162 |
| 161 // bootstrap with broken environment | 163 // bootstrap with broken environment |
| 162 opc, errc = runCommand(new(BootstrapCommand), "-e", "brokenenv") | 164 opc, errc = runCommand(new(BootstrapCommand), "-e", "brokenenv") |
| 165 c.Check(<-errc, ErrorMatches, "dummy.Bootstrap is broken") |
| 163 c.Check(<-opc, IsNil) | 166 c.Check(<-opc, IsNil) |
| 164 c.Check(<-errc, ErrorMatches, "dummy.Bootstrap is broken") | |
| 165 } | 167 } |
| 166 | 168 |
| 167 func (*CmdSuite) TestDestroyCommand(c *C) { | 169 func (*CmdSuite) TestDestroyCommand(c *C) { |
| 168 // normal destroy | 170 // normal destroy |
| 169 opc, errc := runCommand(new(DestroyCommand)) | 171 opc, errc := runCommand(new(DestroyCommand)) |
| 172 c.Check(<-errc, IsNil) |
| 170 c.Check((<-opc).(dummy.OpDestroy).Env, Equals, "peckham") | 173 c.Check((<-opc).(dummy.OpDestroy).Env, Equals, "peckham") |
| 171 c.Check(<-errc, IsNil) | |
| 172 | 174 |
| 173 // destroy with broken environment | 175 // destroy with broken environment |
| 174 opc, errc = runCommand(new(DestroyCommand), "-e", "brokenenv") | 176 opc, errc = runCommand(new(DestroyCommand), "-e", "brokenenv") |
| 177 c.Check(<-errc, ErrorMatches, "dummy.Destroy is broken") |
| 175 c.Check(<-opc, IsNil) | 178 c.Check(<-opc, IsNil) |
| 176 c.Check(<-errc, ErrorMatches, "dummy.Destroy is broken") | |
| 177 } | 179 } |
| 178 | 180 |
| 179 var deployTests = []struct { | 181 var deployTests = []struct { |
| 180 args []string | 182 args []string |
| 181 com *DeployCommand | 183 com *DeployCommand |
| 182 }{ | 184 }{ |
| 183 { | 185 { |
| 184 []string{"charm-name"}, | 186 []string{"charm-name"}, |
| 185 &DeployCommand{}, | 187 &DeployCommand{}, |
| 186 }, { | 188 }, { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 return com, com.Init(newFlagSet(), args) | 287 return com, com.Init(newFlagSet(), args) |
| 286 } | 288 } |
| 287 | 289 |
| 288 func (*CmdSuite) TestUnexposeCommandInit(c *C) { | 290 func (*CmdSuite) TestUnexposeCommandInit(c *C) { |
| 289 // missing args | 291 // missing args |
| 290 _, err := initUnexposeCommand() | 292 _, err := initUnexposeCommand() |
| 291 c.Assert(err, ErrorMatches, "no service name specified") | 293 c.Assert(err, ErrorMatches, "no service name specified") |
| 292 | 294 |
| 293 // environment tested elsewhere | 295 // environment tested elsewhere |
| 294 } | 296 } |
| OLD | NEW |