github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/provider/vsphere/environ_availzones_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 // +build !gccgo 5 6 package vsphere_test 7 8 import ( 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/instance" 13 "github.com/juju/juju/provider/vsphere" 14 ) 15 16 type environAvailzonesSuite struct { 17 vsphere.BaseSuite 18 } 19 20 var _ = gc.Suite(&environAvailzonesSuite{}) 21 22 func (s *environAvailzonesSuite) SetUpTest(c *gc.C) { 23 s.BaseSuite.SetUpTest(c) 24 } 25 26 func (s *environAvailzonesSuite) TestAvailabilityZones(c *gc.C) { 27 client := vsphere.ExposeEnvFakeClient(s.Env) 28 s.FakeAvailabilityZones(client, "z1", "z2") 29 zones, err := s.Env.AvailabilityZones() 30 31 c.Assert(err, jc.ErrorIsNil) 32 c.Assert(len(zones), gc.Equals, 2) 33 c.Assert(zones[0].Name(), gc.Equals, "z1") 34 c.Assert(zones[1].Name(), gc.Equals, "z2") 35 } 36 37 func (s *environAvailzonesSuite) TestInstanceAvailabilityZoneNames(c *gc.C) { 38 client := vsphere.ExposeEnvFakeClient(s.Env) 39 client.SetPropertyProxyHandler("FakeDatacenter", vsphere.RetrieveDatacenterProperties) 40 namespace, err := instance.NewNamespace(s.Env.Config().UUID()) 41 c.Assert(err, jc.ErrorIsNil) 42 vmName, err := namespace.Hostname("1") 43 c.Assert(err, jc.ErrorIsNil) 44 s.FakeInstancesWithResourcePool(client, vsphere.InstRp{Inst: vmName, Rp: "rp1"}) 45 s.FakeAvailabilityZonesWithResourcePool(client, vsphere.ZoneRp{Zone: "z1", Rp: "rp1"}, vsphere.ZoneRp{Zone: "z2", Rp: "rp2"}) 46 47 zones, err := s.Env.InstanceAvailabilityZoneNames([]instance.Id{instance.Id(vmName)}) 48 49 c.Assert(err, jc.ErrorIsNil) 50 c.Assert(len(zones), gc.Equals, 1) 51 c.Assert(zones[0], gc.Equals, "z1") 52 }