github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/cmd/juju/machine/list_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/apiserver/params" 12 "github.com/juju/juju/cmd/juju/machine" 13 "github.com/juju/juju/testing" 14 ) 15 16 type MachineListCommandSuite struct { 17 testing.FakeJujuXDGDataHomeSuite 18 } 19 20 var _ = gc.Suite(&MachineListCommandSuite{}) 21 22 func newMachineListCommand() cmd.Command { 23 return machine.NewListCommandForTest(&fakeStatusAPI{}) 24 } 25 26 type fakeStatusAPI struct{} 27 28 func (*fakeStatusAPI) Status(c []string) (*params.FullStatus, error) { 29 result := ¶ms.FullStatus{ 30 Model: params.ModelStatusInfo{ 31 Name: "dummyenv", 32 Version: "1.2.3", 33 }, 34 Machines: map[string]params.MachineStatus{ 35 "0": { 36 Id: "0", 37 AgentStatus: params.DetailedStatus{ 38 Status: "started", 39 }, 40 DNSName: "10.0.0.1", 41 IPAddresses: []string{ 42 "10.0.0.1", 43 "10.0.1.1", 44 }, 45 InstanceId: "juju-badd06-0", 46 Series: "trusty", 47 Hardware: "availability-zone=us-east-1", 48 }, 49 "1": { 50 Id: "1", 51 AgentStatus: params.DetailedStatus{ 52 Status: "started", 53 }, 54 DNSName: "10.0.0.2", 55 IPAddresses: []string{ 56 "10.0.0.2", 57 "10.0.1.2", 58 }, 59 InstanceId: "juju-badd06-1", 60 Series: "trusty", 61 Containers: map[string]params.MachineStatus{ 62 "1/lxd/0": { 63 Id: "1/lxd/0", 64 AgentStatus: params.DetailedStatus{ 65 Status: "pending", 66 }, 67 DNSName: "10.0.0.3", 68 IPAddresses: []string{ 69 "10.0.0.3", 70 "10.0.1.3", 71 }, 72 InstanceId: "juju-badd06-1-lxd-0", 73 Series: "trusty", 74 }, 75 }, 76 }, 77 }, 78 } 79 return result, nil 80 81 } 82 func (*fakeStatusAPI) Close() error { 83 return nil 84 } 85 86 func (s *MachineListCommandSuite) SetUpTest(c *gc.C) { 87 s.FakeJujuXDGDataHomeSuite.SetUpTest(c) 88 } 89 90 func (s *MachineListCommandSuite) TestMachine(c *gc.C) { 91 context, err := testing.RunCommand(c, newMachineListCommand()) 92 c.Assert(err, jc.ErrorIsNil) 93 c.Assert(testing.Stdout(context), gc.Equals, ""+ 94 "Machine State DNS Inst id Series AZ\n"+ 95 "0 started 10.0.0.1 juju-badd06-0 trusty us-east-1\n"+ 96 "1 started 10.0.0.2 juju-badd06-1 trusty \n"+ 97 "1/lxd/0 pending 10.0.0.3 juju-badd06-1-lxd-0 trusty \n"+ 98 "\n") 99 } 100 101 func (s *MachineListCommandSuite) TestListMachineYaml(c *gc.C) { 102 context, err := testing.RunCommand(c, newMachineListCommand(), "--format", "yaml") 103 c.Assert(err, jc.ErrorIsNil) 104 c.Assert(testing.Stdout(context), gc.Equals, ""+ 105 "model: dummyenv\n"+ 106 "machines:\n"+ 107 " \"0\":\n"+ 108 " juju-status:\n"+ 109 " current: started\n"+ 110 " dns-name: 10.0.0.1\n"+ 111 " ip-addresses:\n"+ 112 " - 10.0.0.1\n"+ 113 " - 10.0.1.1\n"+ 114 " instance-id: juju-badd06-0\n"+ 115 " series: trusty\n"+ 116 " hardware: availability-zone=us-east-1\n"+ 117 " \"1\":\n"+ 118 " juju-status:\n"+ 119 " current: started\n"+ 120 " dns-name: 10.0.0.2\n"+ 121 " ip-addresses:\n"+ 122 " - 10.0.0.2\n"+ 123 " - 10.0.1.2\n"+ 124 " instance-id: juju-badd06-1\n"+ 125 " series: trusty\n"+ 126 " containers:\n"+ 127 " 1/lxd/0:\n"+ 128 " juju-status:\n"+ 129 " current: pending\n"+ 130 " dns-name: 10.0.0.3\n"+ 131 " ip-addresses:\n"+ 132 " - 10.0.0.3\n"+ 133 " - 10.0.1.3\n"+ 134 " instance-id: juju-badd06-1-lxd-0\n"+ 135 " series: trusty\n") 136 } 137 138 func (s *MachineListCommandSuite) TestListMachineJson(c *gc.C) { 139 context, err := testing.RunCommand(c, newMachineListCommand(), "--format", "json") 140 c.Assert(err, jc.ErrorIsNil) 141 c.Assert(testing.Stdout(context), gc.Equals, ""+ 142 "{\"model\":\"dummyenv\",\"machines\":{\"0\":{\"juju-status\":{\"current\":\"started\"},\"dns-name\":\"10.0.0.1\",\"ip-addresses\":[\"10.0.0.1\",\"10.0.1.1\"],\"instance-id\":\"juju-badd06-0\",\"machine-status\":{},\"series\":\"trusty\",\"hardware\":\"availability-zone=us-east-1\"},\"1\":{\"juju-status\":{\"current\":\"started\"},\"dns-name\":\"10.0.0.2\",\"ip-addresses\":[\"10.0.0.2\",\"10.0.1.2\"],\"instance-id\":\"juju-badd06-1\",\"machine-status\":{},\"series\":\"trusty\",\"containers\":{\"1/lxd/0\":{\"juju-status\":{\"current\":\"pending\"},\"dns-name\":\"10.0.0.3\",\"ip-addresses\":[\"10.0.0.3\",\"10.0.1.3\"],\"instance-id\":\"juju-badd06-1-lxd-0\",\"machine-status\":{},\"series\":\"trusty\"}}}}}\n") 143 } 144 145 func (s *MachineListCommandSuite) TestListMachineArgsError(c *gc.C) { 146 _, err := testing.RunCommand(c, newMachineListCommand(), "0") 147 c.Assert(err, gc.ErrorMatches, `unrecognized args: \["0"\]`) 148 }