~wallyworld/juju-core/fast-lxc-everywhere

« back to all changes in this revision

Viewing changes to constraints/constraints_test.go

  • Committer: Tarmac
  • Author(s): Ian Booth
  • Date: 2014-04-24 12:33:19 UTC
  • mfrom: (2664.1.4 constraints-vocab)
  • Revision ID: tarmac-20140424123319-iifvboa1kjuprj7l
[r=wallyworld] Support constraints vocabs

Add support to constraints validation for
vocabs for each attribute. eg arch and
instance-type can only have well defined
values for each provider. The vocab check
is part of constraints validation.

https://codereview.appspot.com/96730043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
534
534
        c.Assert(err, gc.ErrorMatches, `unknown constraint "foo"`)
535
535
}
536
536
 
537
 
var attributesWithValuesTests = []struct {
538
 
        cons     string
539
 
        attrs    []string
540
 
        expected []string
541
 
}{
542
 
        {
543
 
                cons:     "",
544
 
                expected: []string{},
545
 
        },
546
 
        {
547
 
                cons:     "root-disk=8G mem=4G arch=amd64 cpu-power=1000 cpu-cores=4",
548
 
                expected: []string{"arch", "cpu-cores", "cpu-power", "mem", "root-disk"},
549
 
        },
550
 
}
551
 
 
552
537
func (s *ConstraintsSuite) TestAttributesWithValues(c *gc.C) {
553
 
        for i, t := range attributesWithValuesTests {
 
538
        for i, consStr := range []string{
 
539
                "",
 
540
                "root-disk=8G mem=4G arch=amd64 cpu-power=1000 cpu-cores=4 instance-type=foo tags=foo,bar",
 
541
        } {
554
542
                c.Logf("test %d", i)
555
 
                cons := constraints.MustParse(t.cons)
 
543
                cons := constraints.MustParse(consStr)
556
544
                obtained := constraints.AttributesWithValues(cons)
557
 
                c.Check(obtained, gc.DeepEquals, t.expected)
 
545
                assertMissing := func(attrName string) {
 
546
                        _, ok := obtained[attrName]
 
547
                        c.Check(ok, jc.IsFalse)
 
548
                }
 
549
                if cons.Arch != nil {
 
550
                        c.Check(obtained["arch"], gc.Equals, *cons.Arch)
 
551
                } else {
 
552
                        assertMissing("arch")
 
553
                }
 
554
                if cons.Mem != nil {
 
555
                        c.Check(obtained["mem"], gc.Equals, *cons.Mem)
 
556
                } else {
 
557
                        assertMissing("mem")
 
558
                }
 
559
                if cons.CpuCores != nil {
 
560
                        c.Check(obtained["cpu-cores"], gc.Equals, *cons.CpuCores)
 
561
                } else {
 
562
                        assertMissing("cpu-cores")
 
563
                }
 
564
                if cons.CpuPower != nil {
 
565
                        c.Check(obtained["cpu-power"], gc.Equals, *cons.CpuPower)
 
566
                } else {
 
567
                        assertMissing("cpu-power")
 
568
                }
 
569
                if cons.RootDisk != nil {
 
570
                        c.Check(obtained["root-disk"], gc.Equals, *cons.RootDisk)
 
571
                } else {
 
572
                        assertMissing("root-disk")
 
573
                }
 
574
                if cons.Tags != nil {
 
575
                        c.Check(obtained["tags"], gc.DeepEquals, *cons.Tags)
 
576
                } else {
 
577
                        assertMissing("tags")
 
578
                }
 
579
                if cons.InstanceType != nil {
 
580
                        c.Check(obtained["instance-type"], gc.Equals, *cons.InstanceType)
 
581
                } else {
 
582
                        assertMissing("instance-type")
 
583
                }
558
584
        }
559
585
}
560
586