github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cloudconfig/podcfg/podcfg_test.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package podcfg_test 5 6 import ( 7 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 10 "github.com/juju/juju/cloudconfig/podcfg" 11 "github.com/juju/juju/environs/config" 12 "github.com/juju/juju/state/multiwatcher" 13 "github.com/juju/juju/testing" 14 ) 15 16 type podcfgSuite struct { 17 testing.BaseSuite 18 } 19 20 var _ = gc.Suite(&podcfgSuite{}) 21 22 func (*podcfgSuite) TestPodLabelsController(c *gc.C) { 23 cfg := testing.CustomModelConfig(c, testing.Attrs{}) 24 controllerJobs := []multiwatcher.MachineJob{multiwatcher.JobManageModel} 25 nonControllerJobs := []multiwatcher.MachineJob{multiwatcher.JobHostUnits} 26 testPodLabels(c, cfg, controllerJobs, map[string]string{ 27 "juju-model-uuid": testing.ModelTag.Id(), 28 "juju-controller-uuid": testing.ControllerTag.Id(), 29 "juju-is-controller": "true", 30 }) 31 testPodLabels(c, cfg, nonControllerJobs, map[string]string{ 32 "juju-model-uuid": testing.ModelTag.Id(), 33 "juju-controller-uuid": testing.ControllerTag.Id(), 34 "juju-is-controller": "true", 35 }) 36 } 37 38 func (*podcfgSuite) TestPodLabelsUserSpecified(c *gc.C) { 39 cfg := testing.CustomModelConfig(c, testing.Attrs{ 40 "resource-tags": "a=b c=", 41 }) 42 testPodLabels(c, cfg, nil, map[string]string{ 43 "juju-model-uuid": testing.ModelTag.Id(), 44 "juju-controller-uuid": testing.ControllerTag.Id(), 45 "a": "b", 46 "c": "", 47 "juju-is-controller": "true", 48 }) 49 } 50 51 func testPodLabels(c *gc.C, cfg *config.Config, jobs []multiwatcher.MachineJob, expectTags map[string]string) { 52 tags := podcfg.PodLabels(testing.ModelTag.Id(), testing.ControllerTag.Id(), cfg, jobs) 53 c.Assert(tags, jc.DeepEquals, expectTags) 54 }