github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/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-badd06-0\n"+
    40  		"    series: trusty\n"+
    41  		"    hardware: availability-zone=us-east-1\n"+
    42  		"  \"1\":\n"+
    43  		"    juju-status:\n"+
    44  		"      current: started\n"+
    45  		"    dns-name: 10.0.0.2\n"+
    46  		"    instance-id: juju-badd06-1\n"+
    47  		"    series: trusty\n"+
    48  		"    containers:\n"+
    49  		"      1/lxd/0:\n"+
    50  		"        juju-status:\n"+
    51  		"          current: pending\n"+
    52  		"        dns-name: 10.0.0.3\n"+
    53  		"        instance-id: juju-badd06-1-lxd-0\n"+
    54  		"        series: trusty\n")
    55  }
    56  func (s *MachineShowCommandSuite) TestShowSingleMachine(c *gc.C) {
    57  	context, err := testing.RunCommand(c, newMachineShowCommand(), "0")
    58  	c.Assert(err, jc.ErrorIsNil)
    59  	c.Assert(testing.Stdout(context), gc.Equals, ""+
    60  		"model: dummyenv\n"+
    61  		"machines:\n"+
    62  		"  \"0\":\n"+
    63  		"    juju-status:\n"+
    64  		"      current: started\n"+
    65  		"    dns-name: 10.0.0.1\n"+
    66  		"    instance-id: juju-badd06-0\n"+
    67  		"    series: trusty\n"+
    68  		"    hardware: availability-zone=us-east-1\n")
    69  }
    70  
    71  func (s *MachineShowCommandSuite) TestShowTabularMachine(c *gc.C) {
    72  	context, err := testing.RunCommand(c, newMachineShowCommand(), "--format", "tabular", "0", "1")
    73  	c.Assert(err, jc.ErrorIsNil)
    74  	c.Assert(testing.Stdout(context), gc.Equals, ""+
    75  		"MACHINE  STATE    DNS       INS-ID               SERIES  AZ\n"+
    76  		"0        started  10.0.0.1  juju-badd06-0        trusty  us-east-1\n"+
    77  		"1        started  10.0.0.2  juju-badd06-1        trusty  \n"+
    78  		"1/lxd/0  pending  10.0.0.3  juju-badd06-1-lxd-0  trusty  \n"+
    79  		"\n")
    80  }
    81  
    82  func (s *MachineShowCommandSuite) TestShowJsonMachine(c *gc.C) {
    83  	context, err := testing.RunCommand(c, newMachineShowCommand(), "--format", "json", "0", "1")
    84  	c.Assert(err, jc.ErrorIsNil)
    85  	c.Assert(testing.Stdout(context), gc.Equals, ""+
    86  		"{\"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")
    87  }