github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/provider/vsphere/environ_instance_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/environs"
    13  	"github.com/juju/juju/instance"
    14  	"github.com/juju/juju/provider/common"
    15  	"github.com/juju/juju/provider/vsphere"
    16  )
    17  
    18  type environInstanceSuite struct {
    19  	vsphere.BaseSuite
    20  }
    21  
    22  var _ = gc.Suite(&environInstanceSuite{})
    23  
    24  func (s *environInstanceSuite) SetUpTest(c *gc.C) {
    25  	s.BaseSuite.SetUpTest(c)
    26  }
    27  
    28  func (s *environAvailzonesSuite) TestInstances(c *gc.C) {
    29  	client := vsphere.ExposeEnvFakeClient(s.Env)
    30  	client.SetPropertyProxyHandler("FakeDatacenter", vsphere.RetrieveDatacenterProperties)
    31  	vmName1 := common.MachineFullName(s.Env.Config().UUID(), "1")
    32  	vmName2 := common.MachineFullName(s.Env.Config().UUID(), "2")
    33  	s.FakeInstancesWithResourcePool(client, vsphere.InstRp{Inst: vmName1, Rp: "rp1"}, vsphere.InstRp{Inst: vmName2, Rp: "rp2"})
    34  
    35  	instances, err := s.Env.Instances([]instance.Id{instance.Id(vmName1), instance.Id(vmName2)})
    36  
    37  	c.Assert(err, jc.ErrorIsNil)
    38  	c.Assert(len(instances), gc.Equals, 2)
    39  	c.Assert(string(instances[0].Id()), gc.Equals, vmName1)
    40  	c.Assert(string(instances[1].Id()), gc.Equals, vmName2)
    41  }
    42  
    43  func (s *environAvailzonesSuite) TestInstancesReturnNoInstances(c *gc.C) {
    44  	client := vsphere.ExposeEnvFakeClient(s.Env)
    45  	client.SetPropertyProxyHandler("FakeDatacenter", vsphere.RetrieveDatacenterProperties)
    46  	s.FakeInstancesWithResourcePool(client, vsphere.InstRp{Inst: "Some name that don't match naming convention", Rp: "rp1"})
    47  
    48  	_, err := s.Env.Instances([]instance.Id{instance.Id("Some other name")})
    49  
    50  	c.Assert(err, gc.Equals, environs.ErrNoInstances)
    51  }
    52  
    53  func (s *environAvailzonesSuite) TestInstancesReturnPartialInstances(c *gc.C) {
    54  	client := vsphere.ExposeEnvFakeClient(s.Env)
    55  	client.SetPropertyProxyHandler("FakeDatacenter", vsphere.RetrieveDatacenterProperties)
    56  	vmName1 := common.MachineFullName(s.Env.Config().UUID(), "1")
    57  	vmName2 := common.MachineFullName(s.Env.Config().UUID(), "2")
    58  	s.FakeInstancesWithResourcePool(client, vsphere.InstRp{Inst: vmName1, Rp: "rp1"}, vsphere.InstRp{Inst: "Some inst", Rp: "rp2"})
    59  
    60  	_, err := s.Env.Instances([]instance.Id{instance.Id(vmName1), instance.Id(vmName2)})
    61  
    62  	c.Assert(err, gc.Equals, environs.ErrPartialInstances)
    63  }