github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/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 := &params.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  				InstanceId: "juju-badd06-0",
    42  				Series:     "trusty",
    43  				Hardware:   "availability-zone=us-east-1",
    44  			},
    45  			"1": {
    46  				Id: "1",
    47  				AgentStatus: params.DetailedStatus{
    48  					Status: "started",
    49  				},
    50  				DNSName:    "10.0.0.2",
    51  				InstanceId: "juju-badd06-1",
    52  				Series:     "trusty",
    53  				Containers: map[string]params.MachineStatus{
    54  					"1/lxd/0": {
    55  						Id: "1/lxd/0",
    56  						AgentStatus: params.DetailedStatus{
    57  							Status: "pending",
    58  						},
    59  						DNSName:    "10.0.0.3",
    60  						InstanceId: "juju-badd06-1-lxd-0",
    61  						Series:     "trusty",
    62  					},
    63  				},
    64  			},
    65  		},
    66  	}
    67  	return result, nil
    68  
    69  }
    70  func (*fakeStatusAPI) Close() error {
    71  	return nil
    72  }
    73  
    74  func (s *MachineListCommandSuite) SetUpTest(c *gc.C) {
    75  	s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
    76  }
    77  
    78  func (s *MachineListCommandSuite) TestMachine(c *gc.C) {
    79  	context, err := testing.RunCommand(c, newMachineListCommand())
    80  	c.Assert(err, jc.ErrorIsNil)
    81  	c.Assert(testing.Stdout(context), gc.Equals, ""+
    82  		"MACHINE  STATE    DNS       INS-ID               SERIES  AZ\n"+
    83  		"0        started  10.0.0.1  juju-badd06-0        trusty  us-east-1\n"+
    84  		"1        started  10.0.0.2  juju-badd06-1        trusty  \n"+
    85  		"1/lxd/0  pending  10.0.0.3  juju-badd06-1-lxd-0  trusty  \n"+
    86  		"\n")
    87  }
    88  
    89  func (s *MachineListCommandSuite) TestListMachineYaml(c *gc.C) {
    90  	context, err := testing.RunCommand(c, newMachineListCommand(), "--format", "yaml")
    91  	c.Assert(err, jc.ErrorIsNil)
    92  	c.Assert(testing.Stdout(context), gc.Equals, ""+
    93  		"model: dummyenv\n"+
    94  		"machines:\n"+
    95  		"  \"0\":\n"+
    96  		"    juju-status:\n"+
    97  		"      current: started\n"+
    98  		"    dns-name: 10.0.0.1\n"+
    99  		"    instance-id: juju-badd06-0\n"+
   100  		"    series: trusty\n"+
   101  		"    hardware: availability-zone=us-east-1\n"+
   102  		"  \"1\":\n"+
   103  		"    juju-status:\n"+
   104  		"      current: started\n"+
   105  		"    dns-name: 10.0.0.2\n"+
   106  		"    instance-id: juju-badd06-1\n"+
   107  		"    series: trusty\n"+
   108  		"    containers:\n"+
   109  		"      1/lxd/0:\n"+
   110  		"        juju-status:\n"+
   111  		"          current: pending\n"+
   112  		"        dns-name: 10.0.0.3\n"+
   113  		"        instance-id: juju-badd06-1-lxd-0\n"+
   114  		"        series: trusty\n")
   115  }
   116  
   117  func (s *MachineListCommandSuite) TestListMachineJson(c *gc.C) {
   118  	context, err := testing.RunCommand(c, newMachineListCommand(), "--format", "json")
   119  	c.Assert(err, jc.ErrorIsNil)
   120  	c.Assert(testing.Stdout(context), gc.Equals, ""+
   121  		"{\"model\":\"dummyenv\",\"machines\":{\"0\":{\"juju-status\":{\"current\":\"started\"},\"dns-name\":\"10.0.0.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\",\"instance-id\":\"juju-badd06-1\",\"machine-status\":{},\"series\":\"trusty\",\"containers\":{\"1/lxd/0\":{\"juju-status\":{\"current\":\"pending\"},\"dns-name\":\"10.0.0.3\",\"instance-id\":\"juju-badd06-1-lxd-0\",\"machine-status\":{},\"series\":\"trusty\"}}}}}\n")
   122  }
   123  
   124  func (s *MachineListCommandSuite) TestListMachineArgsError(c *gc.C) {
   125  	_, err := testing.RunCommand(c, newMachineListCommand(), "0")
   126  	c.Assert(err, gc.ErrorMatches, `unrecognized args: \["0"\]`)
   127  }