github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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 ModelName: "dummyenv", 31 Machines: map[string]params.MachineStatus{ 32 "0": { 33 Id: "0", 34 AgentStatus: params.DetailedStatus{ 35 Status: "started", 36 }, 37 DNSName: "10.0.0.1", 38 InstanceId: "juju-dummy-machine-0", 39 Series: "trusty", 40 Hardware: "availability-zone=us-east-1", 41 }, 42 "1": { 43 Id: "1", 44 AgentStatus: params.DetailedStatus{ 45 Status: "pending", 46 }, 47 DNSName: "10.0.0.2", 48 InstanceId: "juju-dummy-machine-1", 49 Series: "trusty", 50 }, 51 }, 52 } 53 return result, nil 54 55 } 56 func (*fakeStatusAPI) Close() error { 57 return nil 58 } 59 60 func (s *MachineListCommandSuite) SetUpTest(c *gc.C) { 61 s.FakeJujuXDGDataHomeSuite.SetUpTest(c) 62 } 63 64 func (s *MachineListCommandSuite) TestMachine(c *gc.C) { 65 context, err := testing.RunCommand(c, newMachineListCommand()) 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 *MachineListCommandSuite) TestListMachineYaml(c *gc.C) { 77 context, err := testing.RunCommand(c, newMachineListCommand(), "--format", "yaml") 78 c.Assert(err, jc.ErrorIsNil) 79 c.Assert(testing.Stdout(context), gc.Equals, ""+ 80 "model: dummyenv\n"+ 81 "machines:\n"+ 82 " \"0\":\n"+ 83 " juju-status:\n"+ 84 " current: started\n"+ 85 " dns-name: 10.0.0.1\n"+ 86 " instance-id: juju-dummy-machine-0\n"+ 87 " series: trusty\n"+ 88 " hardware: availability-zone=us-east-1\n"+ 89 " \"1\":\n"+ 90 " juju-status:\n"+ 91 " current: pending\n"+ 92 " dns-name: 10.0.0.2\n"+ 93 " instance-id: juju-dummy-machine-1\n"+ 94 " series: trusty\n") 95 } 96 97 func (s *MachineListCommandSuite) TestListMachineJson(c *gc.C) { 98 context, err := testing.RunCommand(c, newMachineListCommand(), "--format", "json") 99 c.Assert(err, jc.ErrorIsNil) 100 c.Assert(testing.Stdout(context), gc.Equals, ""+ 101 "{\"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") 102 } 103 104 func (s *MachineListCommandSuite) TestListMachineArgsError(c *gc.C) { 105 _, err := testing.RunCommand(c, newMachineListCommand(), "0") 106 c.Assert(err, gc.ErrorMatches, "The list-machines command does not take any arguments") 107 }