github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/machine/show_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for info. 3 4 package machine_test 5 6 import ( 7 "github.com/juju/cmd" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 11 "github.com/juju/juju/cmd/juju/machine" 12 "github.com/juju/juju/testing" 13 ) 14 15 type MachineShowCommandSuite struct { 16 testing.FakeJujuXDGDataHomeSuite 17 } 18 19 var _ = gc.Suite(&MachineShowCommandSuite{}) 20 21 func newMachineShowCommand() cmd.Command { 22 return machine.NewShowCommandForTest(&fakeStatusAPI{}) 23 } 24 25 func (s *MachineShowCommandSuite) SetUpTest(c *gc.C) { 26 s.FakeJujuXDGDataHomeSuite.SetUpTest(c) 27 } 28 29 func (s *MachineShowCommandSuite) TestShowMachine(c *gc.C) { 30 context, err := testing.RunCommand(c, newMachineShowCommand()) 31 c.Assert(err, jc.ErrorIsNil) 32 c.Assert(testing.Stdout(context), gc.Equals, ""+ 33 "model: dummyenv\n"+ 34 "machines:\n"+ 35 " \"0\":\n"+ 36 " juju-status:\n"+ 37 " current: started\n"+ 38 " dns-name: 10.0.0.1\n"+ 39 " instance-id: juju-dummy-machine-0\n"+ 40 " series: trusty\n"+ 41 " hardware: availability-zone=us-east-1\n"+ 42 " \"1\":\n"+ 43 " juju-status:\n"+ 44 " current: pending\n"+ 45 " dns-name: 10.0.0.2\n"+ 46 " instance-id: juju-dummy-machine-1\n"+ 47 " series: trusty\n") 48 } 49 func (s *MachineShowCommandSuite) TestShowSingleMachine(c *gc.C) { 50 context, err := testing.RunCommand(c, newMachineShowCommand(), "0") 51 c.Assert(err, jc.ErrorIsNil) 52 c.Assert(testing.Stdout(context), gc.Equals, ""+ 53 "model: dummyenv\n"+ 54 "machines:\n"+ 55 " \"0\":\n"+ 56 " juju-status:\n"+ 57 " current: started\n"+ 58 " dns-name: 10.0.0.1\n"+ 59 " instance-id: juju-dummy-machine-0\n"+ 60 " series: trusty\n"+ 61 " hardware: availability-zone=us-east-1\n") 62 } 63 64 func (s *MachineShowCommandSuite) TestShowTabularMachine(c *gc.C) { 65 context, err := testing.RunCommand(c, newMachineShowCommand(), "--format", "tabular", "0", "1") 66 c.Assert(err, jc.ErrorIsNil) 67 c.Assert(testing.Stdout(context), gc.Equals, ""+ 68 "\n"+ 69 "[Machines] \n"+ 70 "ID STATE DNS INS-ID SERIES AZ \n"+ 71 "0 started 10.0.0.1 juju-dummy-machine-0 trusty us-east-1 \n"+ 72 "1 pending 10.0.0.2 juju-dummy-machine-1 trusty \n"+ 73 "\n") 74 } 75 76 func (s *MachineShowCommandSuite) TestShowJsonMachine(c *gc.C) { 77 context, err := testing.RunCommand(c, newMachineShowCommand(), "--format", "json", "0", "1") 78 c.Assert(err, jc.ErrorIsNil) 79 c.Assert(testing.Stdout(context), gc.Equals, ""+ 80 "{\"model\":\"dummyenv\",\"machines\":{\"0\":{\"juju-status\":{\"current\":\"started\"},\"dns-name\":\"10.0.0.1\",\"instance-id\":\"juju-dummy-machine-0\",\"machine-status\":{},\"series\":\"trusty\",\"hardware\":\"availability-zone=us-east-1\"},\"1\":{\"juju-status\":{\"current\":\"pending\"},\"dns-name\":\"10.0.0.2\",\"instance-id\":\"juju-dummy-machine-1\",\"machine-status\":{},\"series\":\"trusty\"}}}\n") 81 }