func (*suite) TestInvalidConfig(c *gc.C) { for i, t := range invalidConfigTests { c.Logf("running test %v", i) _, err := environs.ReadEnvironsBytes([]byte(t.env)) c.Check(err, gc.ErrorMatches, t.err) } }
func (*suite) TestConfig(c *gc.C) { for i, t := range configTests { c.Logf("running test %v", i) envs, err := environs.ReadEnvironsBytes([]byte(t.env)) c.Assert(err, jc.ErrorIsNil) t.check(c, envs) } }
func (*suite) TestInvalidEnv(c *gc.C) { for i, t := range invalidEnvTests { c.Logf("running test %v", i) es, err := environs.ReadEnvironsBytes([]byte(t.env)) c.Check(err, jc.ErrorIsNil) cfg, err := es.Config(t.name) c.Check(err, gc.ErrorMatches, t.err) c.Check(cfg, gc.IsNil) } }
func (*suite) TestNoHomeBeforeConfig(c *gc.C) { // Test that we don't actually need HOME set until we call envs.Config() os.Setenv("HOME", "") content := ` environments: valid: type: dummy amazon: type: ec2 ` _, err := environs.ReadEnvironsBytes([]byte(content)) c.Check(err, jc.ErrorIsNil) }
func (s *suite) TestDisallowedInBootstrap(c *gc.C) { content := ` environments: dummy: type: dummy state-server: false ` for key, value := range map[string]interface{}{ "storage-default-block-source": "loop", } { envContent := fmt.Sprintf("%s\n %s: %s", content, key, value) envs, err := environs.ReadEnvironsBytes([]byte(envContent)) c.Check(err, jc.ErrorIsNil) _, err = envs.Config("dummy") c.Assert(err, gc.ErrorMatches, "attribute .* is not allowed in bootstrap configurations") } }
func (s *ConfigDeprecationSuite) checkDeprecationWarning(c *gc.C, attrs testing.Attrs, expectedMsg string) { content := ` environments: deprecated: type: dummy state-server: false ` restore := s.setupLogger(c) defer restore() envs, err := environs.ReadEnvironsBytes([]byte(content)) c.Check(err, gc.IsNil) environs.UpdateEnvironAttrs(envs, "deprecated", attrs) _, err = envs.Config("deprecated") c.Check(err, gc.IsNil) c.Assert(s.writer.Log, gc.HasLen, 1) stripped := strings.Replace(s.writer.Log[0].Message, "\n", "", -1) c.Assert(stripped, gc.Matches, expectedMsg) }
func (*suite) TestNoWarningForDeprecatedButUnusedEnv(c *gc.C) { // This tests that a config that has a deprecated field doesn't // generate a Warning if we don't actually ask for that environment. // However, we can only really trigger that when we have a deprecated // field. If support for the field is removed entirely, another // mechanism will need to be used content := ` environments: valid: type: dummy state-server: false deprecated: type: dummy state-server: false tools-metadata-url: aknowndeprecatedfield lxc-use-clone: true ` var tw loggo.TestWriter // we only capture Warning or above c.Assert(loggo.RegisterWriter("invalid-env-tester", &tw, loggo.WARNING), gc.IsNil) defer loggo.RemoveWriter("invalid-env-tester") envs, err := environs.ReadEnvironsBytes([]byte(content)) c.Check(err, jc.ErrorIsNil) names := envs.Names() sort.Strings(names) c.Check(names, gc.DeepEquals, []string{"deprecated", "valid"}) // There should be no warning in the log c.Check(tw.Log(), gc.HasLen, 0) // Now we actually grab the 'valid' entry _, err = envs.Config("valid") c.Check(err, jc.ErrorIsNil) // And still we have no warnings c.Check(tw.Log(), gc.HasLen, 0) // Only once we grab the deprecated one do we see any warnings _, err = envs.Config("deprecated") c.Check(err, jc.ErrorIsNil) c.Check(tw.Log(), gc.HasLen, 2) }
func (s *ConfigDeprecationSuite) checkDeprecationWarning(c *gc.C, attrs testing.Attrs, expectedMsg string) { content := ` environments: deprecated: type: dummy controller: false ` restore := s.setupLogger(c) defer restore() envs, err := environs.ReadEnvironsBytes([]byte(content)) c.Assert(err, jc.ErrorIsNil) environs.UpdateEnvironAttrs(envs, "deprecated", attrs) _, err = envs.Config("deprecated") c.Assert(err, jc.ErrorIsNil) var stripped string if log := s.writer.Log(); len(log) == 1 { stripped = strings.Replace(log[0].Message, "\n", "", -1) } c.Check(stripped, gc.Matches, expectedMsg) }
func (*BoilerplateConfigSuite) TestBoilerPlateGeneration(c *gc.C) { defer osenv.SetJujuHome(osenv.SetJujuHome(c.MkDir())) boilerplate_text := environs.BoilerplateConfig() _, err := environs.ReadEnvironsBytes([]byte(boilerplate_text)) c.Assert(err, gc.IsNil) }