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