~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/state/modelconfig_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
426
426
                "http-proxy":  "http://http-proxy",
427
427
                "https-proxy": "https://https-proxy",
428
428
        }
429
 
        err := s.State.UpdateModelConfigDefaultValues(attrs, nil)
 
429
        err := s.State.UpdateModelConfigDefaultValues(attrs, nil, nil)
430
430
        c.Assert(err, jc.ErrorIsNil)
431
431
 
432
432
        attrs = map[string]interface{}{
433
433
                "apt-mirror": "http://different-mirror",
434
434
        }
435
 
        err = s.State.UpdateModelConfigDefaultValues(attrs, []string{"http-proxy", "https-proxy"})
 
435
        err = s.State.UpdateModelConfigDefaultValues(attrs, []string{"http-proxy", "https-proxy"}, nil)
436
436
        c.Assert(err, jc.ErrorIsNil)
437
437
 
438
438
        info := statetesting.NewMongoInfo()
465
465
                }}}
466
466
        c.Assert(cfg, jc.DeepEquals, expectedValues)
467
467
}
 
468
 
 
469
func (s *ModelConfigSourceSuite) TestUpdateModelConfigRegionDefaults(c *gc.C) {
 
470
        // The test env is setup with dummy/dummy-region having a no-proxy
 
471
        // dummy-proxy value and nether-region with a nether-proxy value.
 
472
        //
 
473
        // First we change the no-proxy setting in dummy-region
 
474
        attrs := map[string]interface{}{
 
475
                "no-proxy": "changed-proxy",
 
476
        }
 
477
 
 
478
        rspec, err := environs.NewRegionSpec("dummy", "dummy-region")
 
479
        c.Assert(err, jc.ErrorIsNil)
 
480
 
 
481
        err = s.State.UpdateModelConfigDefaultValues(attrs, nil, rspec)
 
482
        c.Assert(err, jc.ErrorIsNil)
 
483
 
 
484
        // Then check in another state.
 
485
        info := statetesting.NewMongoInfo()
 
486
        anotherState, err := state.Open(s.modelTag, s.State.ControllerTag(), info, mongotest.DialOpts(), state.NewPolicyFunc(nil))
 
487
        c.Assert(err, jc.ErrorIsNil)
 
488
        defer anotherState.Close()
 
489
 
 
490
        cfg, err := anotherState.ModelConfigDefaultValues()
 
491
        c.Assert(err, jc.ErrorIsNil)
 
492
        expectedValues := make(config.ModelDefaultAttributes)
 
493
        for attr, val := range config.ConfigDefaults() {
 
494
                expectedValues[attr] = config.AttributeDefaultValues{
 
495
                        Default: val,
 
496
                }
 
497
        }
 
498
        expectedValues["http-proxy"] = config.AttributeDefaultValues{
 
499
                Controller: "http://proxy",
 
500
                Default:    "",
 
501
        }
 
502
        expectedValues["apt-mirror"] = config.AttributeDefaultValues{
 
503
                Controller: "http://mirror",
 
504
                Default:    "",
 
505
                Regions: []config.RegionDefaultValue{{
 
506
                        Name:  "dummy-region",
 
507
                        Value: "http://dummy-mirror",
 
508
                }}}
 
509
        expectedValues["no-proxy"] = config.AttributeDefaultValues{
 
510
                Default: "",
 
511
                Regions: []config.RegionDefaultValue{{
 
512
                        Name:  "dummy-region",
 
513
                        Value: "changed-proxy",
 
514
                }}}
 
515
        c.Assert(cfg, jc.DeepEquals, expectedValues)
 
516
 
 
517
        // remove the dummy-region setting
 
518
        err = s.State.UpdateModelConfigDefaultValues(nil, []string{"no-proxy"}, rspec)
 
519
 
 
520
        // and check again
 
521
        cfg, err = anotherState.ModelConfigDefaultValues()
 
522
        c.Assert(err, jc.ErrorIsNil)
 
523
        cfg, err = anotherState.ModelConfigDefaultValues()
 
524
        c.Assert(err, jc.ErrorIsNil)
 
525
        expectedValues = make(config.ModelDefaultAttributes)
 
526
        for attr, val := range config.ConfigDefaults() {
 
527
                expectedValues[attr] = config.AttributeDefaultValues{
 
528
                        Default: val,
 
529
                }
 
530
        }
 
531
        expectedValues["http-proxy"] = config.AttributeDefaultValues{
 
532
                Controller: "http://proxy",
 
533
                Default:    "",
 
534
        }
 
535
        expectedValues["apt-mirror"] = config.AttributeDefaultValues{
 
536
                Controller: "http://mirror",
 
537
                Default:    "",
 
538
                Regions: []config.RegionDefaultValue{{
 
539
                        Name:  "dummy-region",
 
540
                        Value: "http://dummy-mirror",
 
541
                }}}
 
542
        c.Assert(cfg, jc.DeepEquals, expectedValues)
 
543
}