github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/caas/kubernetes/provider/constraints_test.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package provider_test 5 6 import ( 7 "strings" 8 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/core/constraints" 13 "github.com/juju/juju/environs/context" 14 ) 15 16 type ConstraintsSuite struct { 17 BaseSuite 18 19 callCtx context.ProviderCallContext 20 } 21 22 var _ = gc.Suite(&ConstraintsSuite{}) 23 24 func (s *ConstraintsSuite) SetUpTest(c *gc.C) { 25 s.BaseSuite.SetUpTest(c) 26 s.callCtx = context.NewCloudCallContext() 27 } 28 29 func (s *ConstraintsSuite) TestConstraintsValidatorOkay(c *gc.C) { 30 ctrl := s.setupBroker(c) 31 defer ctrl.Finish() 32 33 validator, err := s.broker.ConstraintsValidator(context.NewCloudCallContext()) 34 c.Assert(err, jc.ErrorIsNil) 35 36 cons := constraints.MustParse("mem=64G") 37 unsupported, err := validator.Validate(cons) 38 c.Assert(err, jc.ErrorIsNil) 39 40 c.Check(unsupported, gc.HasLen, 0) 41 } 42 43 func (s *ConstraintsSuite) TestConstraintsValidatorEmpty(c *gc.C) { 44 ctrl := s.setupBroker(c) 45 defer ctrl.Finish() 46 47 validator, err := s.broker.ConstraintsValidator(context.NewCloudCallContext()) 48 c.Assert(err, jc.ErrorIsNil) 49 50 unsupported, err := validator.Validate(constraints.Value{}) 51 c.Assert(err, jc.ErrorIsNil) 52 53 c.Check(unsupported, gc.HasLen, 0) 54 } 55 56 func (s *ConstraintsSuite) TestConstraintsValidatorUnsupported(c *gc.C) { 57 ctrl := s.setupBroker(c) 58 defer ctrl.Finish() 59 60 validator, err := s.broker.ConstraintsValidator(context.NewCloudCallContext()) 61 c.Assert(err, jc.ErrorIsNil) 62 63 cons := constraints.MustParse(strings.Join([]string{ 64 "arch=amd64", 65 "tags=foo", 66 "mem=3", 67 "instance-type=some-type", 68 "cores=2", 69 "cpu-power=250", 70 "virt-type=kvm", 71 "root-disk=10M", 72 "spaces=foo", 73 "container=kvm", 74 }, " ")) 75 unsupported, err := validator.Validate(cons) 76 c.Assert(err, jc.ErrorIsNil) 77 78 expected := []string{ 79 "tags", 80 "cores", 81 "virt-type", 82 "arch", 83 "instance-type", 84 "root-disk", 85 "spaces", 86 "container", 87 } 88 c.Check(unsupported, jc.SameContents, expected) 89 }