本文整理汇总了Golang中github.com/juju/juju/environs.ReadEnvironsBytes函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadEnvironsBytes函数的具体用法?Golang ReadEnvironsBytes怎么用?Golang ReadEnvironsBytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadEnvironsBytes函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestInvalidConfig
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)
}
}
示例2: TestConfig
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)
}
}
示例3: TestInvalidEnv
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)
}
}
示例4: TestNoHomeBeforeConfig
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)
}
示例5: TestDisallowedInBootstrap
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")
}
}
示例6: checkDeprecationWarning
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)
}
示例7: TestNoWarningForDeprecatedButUnusedEnv
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)
}
示例8: checkDeprecationWarning
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)
}
示例9: TestBoilerPlateGeneration
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)
}