github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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 instance := &maas2Instance{machine: &fakeMachine{hostname: "peewee", systemID: "herman"}} 23 c.Assert(instance.String(), gc.Equals, "peewee:herman") 24 } 25 26 func (s *maas2InstanceSuite) TestID(c *gc.C) { 27 thing := &maas2Instance{machine: &fakeMachine{systemID: "herman"}} 28 c.Assert(thing.Id(), gc.Equals, instance.Id("herman")) 29 } 30 31 func (s *maas2InstanceSuite) TestAddresses(c *gc.C) { 32 instance := &maas2Instance{machine: &fakeMachine{ipAddresses: []string{ 33 "0.0.0.0", 34 "1.2.3.4", 35 "127.0.0.1", 36 }}} 37 expectedAddresses := []network.Address{ 38 network.NewAddress("0.0.0.0"), 39 network.NewAddress("1.2.3.4"), 40 network.NewAddress("127.0.0.1"), 41 } 42 addresses, err := instance.Addresses() 43 c.Assert(err, jc.ErrorIsNil) 44 c.Assert(addresses, jc.SameContents, expectedAddresses) 45 } 46 47 func (s *maas2InstanceSuite) TestZone(c *gc.C) { 48 instance := &maas2Instance{machine: &fakeMachine{zoneName: "inflatable"}} 49 zone, err := instance.zone() 50 c.Assert(err, jc.ErrorIsNil) 51 c.Assert(zone, gc.Equals, "inflatable") 52 } 53 54 func (s *maas2InstanceSuite) TestStatusSuccess(c *gc.C) { 55 thing := &maas2Instance{machine: &fakeMachine{statusMessage: "Wexler", statusName: "Deploying"}} 56 result := thing.Status() 57 c.Assert(result, jc.DeepEquals, instance.InstanceStatus{status.StatusAllocating, "Deploying: Wexler"}) 58 } 59 60 func (s *maas2InstanceSuite) TestStatusError(c *gc.C) { 61 thing := &maas2Instance{machine: &fakeMachine{statusMessage: "", statusName: ""}} 62 result := thing.Status() 63 c.Assert(result, jc.DeepEquals, instance.InstanceStatus{"", "error in getting status"}) 64 } 65 66 func (s *maas2InstanceSuite) TestHostname(c *gc.C) { 67 thing := &maas2Instance{machine: &fakeMachine{hostname: "saul-goodman"}} 68 result, err := thing.hostname() 69 c.Assert(err, jc.ErrorIsNil) 70 c.Assert(result, gc.Equals, "saul-goodman") 71 } 72 73 func (s *maas2InstanceSuite) TestHardwareCharacteristics(c *gc.C) { 74 machine := &fakeMachine{ 75 cpuCount: 3, 76 memory: 4, 77 architecture: "foo/bam", 78 zoneName: "bar", 79 tags: []string{"foo", "bar"}, 80 } 81 thing := &maas2Instance{machine: machine} 82 arch := "foo" 83 cpu := uint64(3) 84 mem := uint64(4) 85 zone := "bar" 86 tags := []string{"foo", "bar"} 87 expected := &instance.HardwareCharacteristics{ 88 Arch: &arch, 89 CpuCores: &cpu, 90 Mem: &mem, 91 AvailabilityZone: &zone, 92 Tags: &tags, 93 } 94 result, err := thing.hardwareCharacteristics() 95 c.Assert(err, jc.ErrorIsNil) 96 c.Assert(result, jc.DeepEquals, expected) 97 }