github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/commands/machine_test.go (about) 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) RunCommand(c *gc.C, args ...string) (*cmd.Context, error) { 27 context := testing.Context(c) 28 juju := NewJujuCommand(context) 29 if err := testing.InitCommand(juju, args); err != nil { 30 return context, err 31 } 32 return context, juju.Run(context) 33 } 34 35 func (s *MachineSuite) TestMachineAdd(c *gc.C) { 36 machines, err := s.State.AllMachines() 37 c.Assert(err, jc.ErrorIsNil) 38 count := len(machines) 39 40 ctx, err := s.RunCommand(c, "add-machine") 41 c.Assert(testing.Stderr(ctx), jc.Contains, `created machine`) 42 43 machines, err = s.State.AllMachines() 44 c.Assert(err, jc.ErrorIsNil) 45 c.Assert(machines, gc.HasLen, count+1) 46 } 47 48 func (s *MachineSuite) TestMachineRemove(c *gc.C) { 49 machine := s.Factory.MakeMachine(c, nil) 50 51 ctx, err := s.RunCommand(c, "remove-machine", machine.Id()) 52 c.Assert(testing.Stdout(ctx), gc.Equals, "") 53 54 err = machine.Refresh() 55 c.Assert(err, jc.ErrorIsNil) 56 57 c.Assert(machine.Life(), gc.Equals, state.Dying) 58 }