~juju-qa/ubuntu/yakkety/juju/juju-1.25.8

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/commands/machine_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-12-02 17:28:37 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161202172837-jkrbdlyjcxtrii2n
Initial commit of 1.25.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2014 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package commands
 
5
 
 
6
import (
 
7
        "github.com/juju/cmd"
 
8
        jc "github.com/juju/testing/checkers"
 
9
        gc "gopkg.in/check.v1"
 
10
 
 
11
        jujutesting "github.com/juju/juju/juju/testing"
 
12
        "github.com/juju/juju/state"
 
13
        "github.com/juju/juju/testing"
 
14
)
 
15
 
 
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
 
22
}
 
23
 
 
24
var _ = gc.Suite(&MachineSuite{})
 
25
 
 
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 {
 
32
                return context, err
 
33
        }
 
34
        return context, juju.Run(context)
 
35
}
 
36
 
 
37
func (s *MachineSuite) TestMachineAdd(c *gc.C) {
 
38
        machines, err := s.State.AllMachines()
 
39
        c.Assert(err, jc.ErrorIsNil)
 
40
        count := len(machines)
 
41
 
 
42
        ctx, err := s.RunMachineCommand(c, "add")
 
43
        c.Assert(testing.Stderr(ctx), jc.Contains, `created machine`)
 
44
 
 
45
        machines, err = s.State.AllMachines()
 
46
        c.Assert(err, jc.ErrorIsNil)
 
47
        c.Assert(machines, gc.HasLen, count+1)
 
48
}
 
49
 
 
50
func (s *MachineSuite) TestMachineRemove(c *gc.C) {
 
51
        machine := s.Factory.MakeMachine(c, nil)
 
52
 
 
53
        ctx, err := s.RunMachineCommand(c, "remove", machine.Id())
 
54
        c.Assert(testing.Stdout(ctx), gc.Equals, "")
 
55
 
 
56
        err = machine.Refresh()
 
57
        c.Assert(err, jc.ErrorIsNil)
 
58
 
 
59
        c.Assert(machine.Life(), gc.Equals, state.Dying)
 
60
}