github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/vsphere/environ_policy_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package vsphere_test
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  
    10  	"github.com/juju/juju/core/constraints"
    11  )
    12  
    13  type environPolSuite struct {
    14  	EnvironFixture
    15  }
    16  
    17  var _ = gc.Suite(&environPolSuite{})
    18  
    19  func (s *environPolSuite) TestConstraintsValidator(c *gc.C) {
    20  	validator, err := s.env.ConstraintsValidator(s.callCtx)
    21  	c.Assert(err, jc.ErrorIsNil)
    22  
    23  	cons := constraints.MustParse("arch=amd64")
    24  	unsupported, err := validator.Validate(cons)
    25  	c.Assert(err, jc.ErrorIsNil)
    26  
    27  	c.Check(unsupported, gc.HasLen, 0)
    28  }
    29  
    30  func (s *environPolSuite) TestConstraintsValidatorEmpty(c *gc.C) {
    31  	validator, err := s.env.ConstraintsValidator(s.callCtx)
    32  	c.Assert(err, jc.ErrorIsNil)
    33  
    34  	unsupported, err := validator.Validate(constraints.Value{})
    35  	c.Assert(err, jc.ErrorIsNil)
    36  
    37  	c.Check(unsupported, gc.HasLen, 0)
    38  }
    39  
    40  func (s *environPolSuite) TestConstraintsValidatorUnsupported(c *gc.C) {
    41  	validator, err := s.env.ConstraintsValidator(s.callCtx)
    42  	c.Assert(err, jc.ErrorIsNil)
    43  
    44  	cons := constraints.MustParse("arch=amd64 tags=foo virt-type=kvm")
    45  	unsupported, err := validator.Validate(cons)
    46  	c.Assert(err, jc.ErrorIsNil)
    47  
    48  	c.Check(unsupported, jc.SameContents, []string{"tags", "virt-type"})
    49  }
    50  
    51  func (s *environPolSuite) TestConstraintsValidatorVocabArch(c *gc.C) {
    52  	validator, err := s.env.ConstraintsValidator(s.callCtx)
    53  	c.Assert(err, jc.ErrorIsNil)
    54  
    55  	cons := constraints.MustParse("arch=ppc64el")
    56  	_, err = validator.Validate(cons)
    57  	c.Check(err, gc.ErrorMatches, "invalid constraint value: arch=ppc64el\nvalid values are:.*")
    58  }