1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
8
jc "github.com/juju/testing/checkers"
11
jujutesting "github.com/juju/juju/juju/testing"
12
"github.com/juju/juju/state"
13
"github.com/juju/juju/testing"
16
// MachineSuite tests the connectivity of all the machine subcommands. These
17
// tests go from the command line, api client, api server, db. The db changes
18
// are then checked. Only one test for each command is done here to check
19
// connectivity. Exhaustive unit tests are at each layer.
20
type MachineSuite struct {
21
jujutesting.JujuConnSuite
24
var _ = gc.Suite(&MachineSuite{})
26
func (s *MachineSuite) RunMachineCommand(c *gc.C, commands ...string) (*cmd.Context, error) {
27
args := []string{"machine"}
28
args = append(args, commands...)
29
context := testing.Context(c)
30
juju := NewJujuCommand(context)
31
if err := testing.InitCommand(juju, args); err != nil {
34
return context, juju.Run(context)
37
func (s *MachineSuite) TestMachineAdd(c *gc.C) {
38
machines, err := s.State.AllMachines()
39
c.Assert(err, jc.ErrorIsNil)
40
count := len(machines)
42
ctx, err := s.RunMachineCommand(c, "add")
43
c.Assert(testing.Stderr(ctx), jc.Contains, `created machine`)
45
machines, err = s.State.AllMachines()
46
c.Assert(err, jc.ErrorIsNil)
47
c.Assert(machines, gc.HasLen, count+1)
50
func (s *MachineSuite) TestMachineRemove(c *gc.C) {
51
machine := s.Factory.MakeMachine(c, nil)
53
ctx, err := s.RunMachineCommand(c, "remove", machine.Id())
54
c.Assert(testing.Stdout(ctx), gc.Equals, "")
56
err = machine.Refresh()
57
c.Assert(err, jc.ErrorIsNil)
59
c.Assert(machine.Life(), gc.Equals, state.Dying)