github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/provider/maas/maas2instance_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package maas
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  
    10  	"github.com/juju/juju/instance"
    11  	"github.com/juju/juju/network"
    12  	"github.com/juju/juju/status"
    13  )
    14  
    15  type maas2InstanceSuite struct {
    16  	baseProviderSuite
    17  }
    18  
    19  var _ = gc.Suite(&maas2InstanceSuite{})
    20  
    21  func (s *maas2InstanceSuite) TestString(c *gc.C) {
    22  	machine := &fakeMachine{hostname: "peewee", systemID: "herman"}
    23  	instance := &maas2Instance{machine: machine}
    24  	c.Assert(instance.String(), gc.Equals, "peewee:herman")
    25  }
    26  
    27  func (s *maas2InstanceSuite) TestID(c *gc.C) {
    28  	machine := &fakeMachine{systemID: "herman"}
    29  	thing := &maas2Instance{machine: machine}
    30  	c.Assert(thing.Id(), gc.Equals, instance.Id("herman"))
    31  }
    32  
    33  func (s *maas2InstanceSuite) TestAddresses(c *gc.C) {
    34  	machine := &fakeMachine{ipAddresses: []string{
    35  		"0.0.0.0",
    36  		"1.2.3.4",
    37  		"127.0.0.1",
    38  	}}
    39  	instance := &maas2Instance{machine: machine}
    40  	expectedAddresses := []network.Address{
    41  		network.NewAddress("0.0.0.0"),
    42  		network.NewAddress("1.2.3.4"),
    43  		network.NewAddress("127.0.0.1"),
    44  	}
    45  	addresses, err := instance.Addresses()
    46  	c.Assert(err, jc.ErrorIsNil)
    47  	c.Assert(addresses, jc.SameContents, expectedAddresses)
    48  }
    49  
    50  func (s *maas2InstanceSuite) TestZone(c *gc.C) {
    51  	machine := &fakeMachine{zoneName: "inflatable"}
    52  	instance := &maas2Instance{machine: machine}
    53  	zone, err := instance.zone()
    54  	c.Assert(err, jc.ErrorIsNil)
    55  	c.Assert(zone, gc.Equals, "inflatable")
    56  }
    57  
    58  func (s *maas2InstanceSuite) TestStatusSuccess(c *gc.C) {
    59  	machine := &fakeMachine{statusMessage: "Wexler", statusName: "Deploying"}
    60  	thing := &maas2Instance{machine: machine}
    61  	result := thing.Status()
    62  	c.Assert(result, jc.DeepEquals, instance.InstanceStatus{status.Allocating, "Deploying: Wexler"})
    63  }
    64  
    65  func (s *maas2InstanceSuite) TestStatusError(c *gc.C) {
    66  	machine := &fakeMachine{statusMessage: "", statusName: ""}
    67  	thing := &maas2Instance{machine: machine}
    68  	result := thing.Status()
    69  	c.Assert(result, jc.DeepEquals, instance.InstanceStatus{"", "error in getting status"})
    70  }
    71  
    72  func (s *maas2InstanceSuite) TestHostname(c *gc.C) {
    73  	machine := &fakeMachine{hostname: "saul-goodman"}
    74  	thing := &maas2Instance{machine: machine}
    75  	result, err := thing.hostname()
    76  	c.Assert(err, jc.ErrorIsNil)
    77  	c.Assert(result, gc.Equals, "saul-goodman")
    78  }
    79  
    80  func (s *maas2InstanceSuite) TestHardwareCharacteristics(c *gc.C) {
    81  	machine := &fakeMachine{
    82  		cpuCount:     3,
    83  		memory:       4,
    84  		architecture: "foo/bam",
    85  		zoneName:     "bar",
    86  		tags:         []string{"foo", "bar"},
    87  	}
    88  	thing := &maas2Instance{machine: machine}
    89  	arch := "foo"
    90  	cpu := uint64(3)
    91  	mem := uint64(4)
    92  	zone := "bar"
    93  	tags := []string{"foo", "bar"}
    94  	expected := &instance.HardwareCharacteristics{
    95  		Arch:             &arch,
    96  		CpuCores:         &cpu,
    97  		Mem:              &mem,
    98  		AvailabilityZone: &zone,
    99  		Tags:             &tags,
   100  	}
   101  	result, err := thing.hardwareCharacteristics()
   102  	c.Assert(err, jc.ErrorIsNil)
   103  	c.Assert(result, jc.DeepEquals, expected)
   104  }