github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/provider/vsphere/environ_policy_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  	"github.com/juju/utils/arch"
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/constraints"
    14  	"github.com/juju/juju/provider/vsphere"
    15  )
    16  
    17  type environPolSuite struct {
    18  	vsphere.BaseSuite
    19  }
    20  
    21  var _ = gc.Suite(&environPolSuite{})
    22  
    23  func (s *environPolSuite) TestSupportedArchitectures(c *gc.C) {
    24  	archList, err := s.Env.SupportedArchitectures()
    25  	c.Assert(err, jc.ErrorIsNil)
    26  
    27  	c.Check(archList, jc.SameContents, []string{arch.AMD64})
    28  }
    29  
    30  func (s *environPolSuite) TestConstraintsValidator(c *gc.C) {
    31  	validator, err := s.Env.ConstraintsValidator()
    32  	c.Assert(err, jc.ErrorIsNil)
    33  
    34  	cons := constraints.MustParse("arch=amd64")
    35  	unsupported, err := validator.Validate(cons)
    36  	c.Assert(err, jc.ErrorIsNil)
    37  
    38  	c.Check(unsupported, gc.HasLen, 0)
    39  }
    40  
    41  func (s *environPolSuite) TestConstraintsValidatorEmpty(c *gc.C) {
    42  	validator, err := s.Env.ConstraintsValidator()
    43  	c.Assert(err, jc.ErrorIsNil)
    44  
    45  	unsupported, err := validator.Validate(constraints.Value{})
    46  	c.Assert(err, jc.ErrorIsNil)
    47  
    48  	c.Check(unsupported, gc.HasLen, 0)
    49  }
    50  
    51  func (s *environPolSuite) TestConstraintsValidatorUnsupported(c *gc.C) {
    52  	validator, err := s.Env.ConstraintsValidator()
    53  	c.Assert(err, jc.ErrorIsNil)
    54  
    55  	cons := constraints.MustParse("arch=amd64 tags=foo virt-type=kvm")
    56  	unsupported, err := validator.Validate(cons)
    57  	c.Assert(err, jc.ErrorIsNil)
    58  
    59  	c.Check(unsupported, jc.SameContents, []string{"tags", "virt-type"})
    60  }
    61  
    62  func (s *environPolSuite) TestConstraintsValidatorVocabArch(c *gc.C) {
    63  	validator, err := s.Env.ConstraintsValidator()
    64  	c.Assert(err, jc.ErrorIsNil)
    65  
    66  	cons := constraints.MustParse("arch=ppc64el")
    67  	_, err = validator.Validate(cons)
    68  
    69  	c.Check(err, gc.ErrorMatches, "invalid constraint value: arch=ppc64el\nvalid values are:.*")
    70  }
    71  
    72  func (s *environPolSuite) TestSupportNetworks(c *gc.C) {
    73  	isSupported := s.Env.SupportNetworks()
    74  
    75  	c.Check(isSupported, jc.IsFalse)
    76  }
    77  
    78  func (s *environPolSuite) TestSupportAddressAllocation(c *gc.C) {
    79  	isSupported, err := s.Env.SupportAddressAllocation("some-network")
    80  	c.Assert(err, jc.ErrorIsNil)
    81  
    82  	c.Check(isSupported, jc.IsFalse)
    83  }
    84  
    85  func (s *environPolSuite) TestSupportAddressAllocationEmpty(c *gc.C) {
    86  	isSupported, err := s.Env.SupportAddressAllocation("")
    87  	c.Assert(err, jc.ErrorIsNil)
    88  
    89  	c.Check(isSupported, jc.IsFalse)
    90  }