Esempio n. 1
0
func (s *upgradeModelConfigSuite) TestUpgradeModelConfigProviderNotConfigUpgrader(c *gc.C) {
	s.registry.providers["someprovider"] = &mockEnvironProvider{}
	err := upgrades.UpgradeModelConfig(s.reader, s.updater, s.registry)
	c.Assert(err, jc.ErrorIsNil)
	s.registry.CheckCalls(c, []testing.StubCall{{
		FuncName: "Provider", Args: []interface{}{"someprovider"},
	}})
	s.stub.CheckCallNames(c, "ModelConfig")
}
Esempio n. 2
0
func (s *upgradeModelConfigSuite) TestUpgradeModelConfigUpgradeConfigError(c *gc.C) {
	s.registry.providers["someprovider"] = &mockModelConfigUpgrader{
		upgradeConfig: func(cfg *config.Config) (*config.Config, error) {
			return nil, errors.New("cannot upgrade config")
		},
	}
	err := upgrades.UpgradeModelConfig(s.reader, s.updater, s.registry)
	c.Assert(err, gc.ErrorMatches, "upgrading config: cannot upgrade config")
	s.stub.CheckCallNames(c, "ModelConfig")
}
Esempio n. 3
0
func (s *upgradeModelConfigSuite) TestUpgradeModelConfigUpdateConfigError(c *gc.C) {
	s.stub.SetErrors(nil, errors.New("cannot update environ config"))
	s.registry.providers["someprovider"] = &mockModelConfigUpgrader{
		upgradeConfig: func(cfg *config.Config) (*config.Config, error) {
			return cfg, nil
		},
	}
	err := upgrades.UpgradeModelConfig(s.reader, s.updater, s.registry)
	c.Assert(err, gc.ErrorMatches, "updating config in state: cannot update environ config")

	s.stub.CheckCallNames(c, "ModelConfig", "UpdateModelConfig")
	updateCall := s.stub.Calls()[1]
	c.Assert(updateCall.Args, gc.HasLen, 3)
	c.Assert(updateCall.Args[0], jc.DeepEquals, s.cfg.AllAttrs())
	c.Assert(updateCall.Args[1], gc.IsNil)
	c.Assert(updateCall.Args[2], gc.IsNil)
}
Esempio n. 4
0
func (s *upgradeModelConfigSuite) TestUpgradeModelConfigProviderConfigUpgrader(c *gc.C) {
	var err error
	s.cfg, err = s.cfg.Apply(map[string]interface{}{"test-key": "test-value"})
	c.Assert(err, jc.ErrorIsNil)

	s.registry.providers["someprovider"] = &mockModelConfigUpgrader{
		upgradeConfig: func(cfg *config.Config) (*config.Config, error) {
			return cfg.Remove([]string{"test-key"})
		},
	}
	err = upgrades.UpgradeModelConfig(s.reader, s.updater, s.registry)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "ModelConfig", "UpdateModelConfig")
	updateCall := s.stub.Calls()[1]
	expectedAttrs := s.cfg.AllAttrs()
	delete(expectedAttrs, "test-key")
	c.Assert(updateCall.Args, gc.HasLen, 3)
	c.Assert(updateCall.Args[0], jc.DeepEquals, expectedAttrs)
	c.Assert(updateCall.Args[1], jc.SameContents, []string{"test-key"})
	c.Assert(updateCall.Args[2], gc.IsNil)
}
Esempio n. 5
0
func (s *upgradeModelConfigSuite) TestUpgradeModelConfigProviderNotRegistered(c *gc.C) {
	s.registry.SetErrors(errors.New(`no registered provider for "someprovider"`))
	err := upgrades.UpgradeModelConfig(s.reader, s.updater, s.registry)
	c.Assert(err, gc.ErrorMatches, `getting provider: no registered provider for "someprovider"`)
	s.stub.CheckCallNames(c, "ModelConfig")
}
Esempio n. 6
0
func (s *upgradeModelConfigSuite) TestUpgradeModelConfigModelConfigError(c *gc.C) {
	s.stub.SetErrors(errors.New("cannot read environ config"))
	err := upgrades.UpgradeModelConfig(s.reader, s.updater, s.registry)
	c.Assert(err, gc.ErrorMatches, "reading model config: cannot read environ config")
	s.stub.CheckCallNames(c, "ModelConfig")
}