本文整理汇总了Golang中github.com/wallyworld/core/environs/config.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestValidateAcceptsUnchangedConfig
func (*configSuite) TestValidateAcceptsUnchangedConfig(c *gc.C) {
attrs := makeAzureConfigMap(c)
provider := azureEnvironProvider{}
oldConfig, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
newConfig, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
result, err := provider.Validate(newConfig, oldConfig)
c.Assert(err, gc.IsNil)
c.Check(result.Name(), gc.Equals, attrs["name"])
}
示例2: TestValidateChecksConfigChanges
func (*configSuite) TestValidateChecksConfigChanges(c *gc.C) {
provider := azureEnvironProvider{}
oldConfig, err := config.New(config.NoDefaults, makeConfigMap(nil))
c.Assert(err, gc.IsNil)
newAttrs := makeConfigMap(map[string]interface{}{
"name": "different-name",
})
newConfig, err := config.New(config.NoDefaults, newAttrs)
c.Assert(err, gc.IsNil)
_, err = provider.Validate(newConfig, oldConfig)
c.Check(err, gc.NotNil)
}
示例3: TestValidateParsesAzureConfig
func (*configSuite) TestValidateParsesAzureConfig(c *gc.C) {
location := "location"
managementSubscriptionId := "subscription-id"
certificate := "certificate content"
storageAccountName := "account-name"
forceImageName := "force-image-name"
unknownFutureSetting := "preserved"
azureConfig := map[string]interface{}{
"location": location,
"management-subscription-id": managementSubscriptionId,
"management-certificate": certificate,
"storage-account-name": storageAccountName,
"force-image-name": forceImageName,
"unknown-future-setting": unknownFutureSetting,
}
attrs := makeConfigMap(azureConfig)
provider := azureEnvironProvider{}
config, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
azConfig, err := provider.newConfig(config)
c.Assert(err, gc.IsNil)
c.Check(azConfig.Name(), gc.Equals, attrs["name"])
c.Check(azConfig.location(), gc.Equals, location)
c.Check(azConfig.managementSubscriptionId(), gc.Equals, managementSubscriptionId)
c.Check(azConfig.managementCertificate(), gc.Equals, certificate)
c.Check(azConfig.storageAccountName(), gc.Equals, storageAccountName)
c.Check(azConfig.forceImageName(), gc.Equals, forceImageName)
c.Check(azConfig.UnknownAttrs()["unknown-future-setting"], gc.Equals, unknownFutureSetting)
}
示例4: NewFromAttrs
// NewFromAttrs returns a new environment based on the provided configuration
// attributes.
// TODO(rog) remove this function - it's almost always wrong to use it.
func NewFromAttrs(attrs map[string]interface{}) (Environ, error) {
cfg, err := config.New(config.NoDefaults, attrs)
if err != nil {
return nil, err
}
return New(cfg)
}
示例5: assertGetImageMetadataSources
func (t *ProviderSuite) assertGetImageMetadataSources(c *gc.C, stream, officialSourcePath string) {
// Make an env configured with the stream.
envAttrs := localConfigAttrs
if stream != "" {
envAttrs = envAttrs.Merge(coretesting.Attrs{
"image-stream": stream,
})
}
cfg, err := config.New(config.NoDefaults, envAttrs)
c.Assert(err, gc.IsNil)
env, err := environs.Prepare(cfg, coretesting.Context(c), configstore.NewMem())
c.Assert(err, gc.IsNil)
c.Assert(env, gc.NotNil)
sources, err := imagemetadata.GetMetadataSources(env)
c.Assert(err, gc.IsNil)
c.Assert(len(sources), gc.Equals, 2)
var urls = make([]string, len(sources))
for i, source := range sources {
url, err := source.URL("")
c.Assert(err, gc.IsNil)
urls[i] = url
}
// The control bucket URL contains the bucket name.
c.Check(strings.Contains(urls[0], ec2.ControlBucketName(env)+"/images"), jc.IsTrue)
c.Assert(urls[1], gc.Equals, fmt.Sprintf("http://cloud-images.ubuntu.com/%s/", officialSourcePath))
}
示例6: TestFirewallMode
func (s *ConfigSuite) TestFirewallMode(c *gc.C) {
for i, test := range firewallModeTests {
c.Logf("test %d: %s", i, test.configFirewallMode)
attrs := dummy.SampleConfig()
if test.configFirewallMode != "" {
attrs = attrs.Merge(testing.Attrs{
"firewall-mode": test.configFirewallMode,
})
}
cfg, err := config.New(config.NoDefaults, attrs)
if err != nil {
c.Assert(err, gc.ErrorMatches, test.errorMsg)
continue
}
ctx := testing.Context(c)
env, err := environs.Prepare(cfg, ctx, configstore.NewMem())
if test.errorMsg != "" {
c.Assert(err, gc.ErrorMatches, test.errorMsg)
continue
}
c.Assert(err, gc.IsNil)
defer env.Destroy()
firewallMode := env.Config().FirewallMode()
c.Assert(firewallMode, gc.Equals, test.firewallMode)
s.TearDownTest(c)
}
}
示例7: TestSetConfigAllowsEmptyFromNilAgentName
func (*environSuite) TestSetConfigAllowsEmptyFromNilAgentName(c *gc.C) {
// bug #1256179 is that when using an older version of Juju (<1.16.2)
// we didn't include maas-agent-name in the database, so it was 'nil'
// in the OldConfig. However, when setting an environment, we would set
// it to "" (because maasEnvironConfig.Validate ensures it is a 'valid'
// string). We can't create that from NewEnviron or newConfig because
// both of them Validate the contents. 'cmd/juju/environment
// SetEnvironmentCommand' instead uses conn.State.EnvironConfig() which
// just reads the content of the database into a map, so we just create
// the map ourselves.
// Even though we use 'nil' here, it actually stores it as "" because
// 1.16.2 already validates the value
baseCfg := getSimpleTestConfig(c, coretesting.Attrs{"maas-agent-name": ""})
c.Check(baseCfg.UnknownAttrs()["maas-agent-name"], gc.Equals, "")
env, err := maas.NewEnviron(baseCfg)
c.Assert(err, gc.IsNil)
provider := env.Provider()
attrs := coretesting.FakeConfig()
// These are attrs we need to make it a valid Config, but would usually
// be set by other infrastructure
attrs["type"] = "maas"
nilCfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
validatedConfig, err := provider.Validate(baseCfg, nilCfg)
c.Assert(err, gc.IsNil)
c.Check(validatedConfig.UnknownAttrs()["maas-agent-name"], gc.Equals, "")
// However, you can't set it to an actual value if you haven't been using a value
valueCfg := getSimpleTestConfig(c, coretesting.Attrs{"maas-agent-name": "agent-name"})
_, err = provider.Validate(valueCfg, nilCfg)
c.Check(err, gc.ErrorMatches, ".*cannot change maas-agent-name.*")
}
示例8: TestDestroy
func (*OpenSuite) TestDestroy(c *gc.C) {
cfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(
testing.Attrs{
"state-server": false,
"name": "erewhemos",
},
))
c.Assert(err, gc.IsNil)
store := configstore.NewMem()
// Prepare the environment and sanity-check that
// the config storage info has been made.
ctx := testing.Context(c)
e, err := environs.Prepare(cfg, ctx, store)
c.Assert(err, gc.IsNil)
_, err = store.ReadInfo(e.Name())
c.Assert(err, gc.IsNil)
err = environs.Destroy(e, store)
c.Assert(err, gc.IsNil)
// Check that the environment has actually been destroyed
// and that the config info has been destroyed too.
_, _, err = e.StateInfo()
c.Assert(err, gc.ErrorMatches, "environment has been destroyed")
_, err = store.ReadInfo(e.Name())
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
示例9: TestPrepareGeneratesDifferentAdminSecrets
func (*OpenSuite) TestPrepareGeneratesDifferentAdminSecrets(c *gc.C) {
baselineAttrs := dummy.SampleConfig().Merge(testing.Attrs{
"state-server": false,
"name": "erewhemos",
}).Delete(
"admin-secret",
)
cfg, err := config.New(config.NoDefaults, baselineAttrs)
c.Assert(err, gc.IsNil)
ctx := testing.Context(c)
env0, err := environs.Prepare(cfg, ctx, configstore.NewMem())
c.Assert(err, gc.IsNil)
adminSecret0 := env0.Config().AdminSecret()
c.Assert(adminSecret0, gc.HasLen, 32)
c.Assert(adminSecret0, gc.Matches, "^[0-9a-f]*$")
env1, err := environs.Prepare(cfg, ctx, configstore.NewMem())
c.Assert(err, gc.IsNil)
adminSecret1 := env1.Config().AdminSecret()
c.Assert(adminSecret1, gc.HasLen, 32)
c.Assert(adminSecret1, gc.Matches, "^[0-9a-f]*$")
c.Assert(adminSecret1, gc.Not(gc.Equals), adminSecret0)
}
示例10: assertGetImageMetadataSources
func (suite *environSuite) assertGetImageMetadataSources(c *gc.C, stream, officialSourcePath string) {
// Make an env configured with the stream.
testAttrs := maasEnvAttrs
testAttrs = testAttrs.Merge(coretesting.Attrs{
"maas-server": suite.testMAASObject.TestServer.URL,
})
if stream != "" {
testAttrs = testAttrs.Merge(coretesting.Attrs{
"image-stream": stream,
})
}
attrs := coretesting.FakeConfig().Merge(testAttrs)
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
env, err := NewEnviron(cfg)
c.Assert(err, gc.IsNil)
// Add a dummy file to storage so we can use that to check the
// obtained source later.
data := makeRandomBytes(10)
stor := NewStorage(env)
err = stor.Put("images/filename", bytes.NewBuffer([]byte(data)), int64(len(data)))
c.Assert(err, gc.IsNil)
sources, err := imagemetadata.GetMetadataSources(env)
c.Assert(err, gc.IsNil)
c.Assert(len(sources), gc.Equals, 2)
assertSourceContents(c, sources[0], "filename", data)
url, err := sources[1].URL("")
c.Assert(err, gc.IsNil)
c.Assert(url, gc.Equals, fmt.Sprintf("http://cloud-images.ubuntu.com/%s/", officialSourcePath))
}
示例11: TestStartInstanceWithoutPublicIP
// If the environment is configured not to require a public IP address for nodes,
// bootstrapping and starting an instance should occur without any attempt to
// allocate a public address.
func (s *localServerSuite) TestStartInstanceWithoutPublicIP(c *gc.C) {
cleanup := s.srv.Service.Nova.RegisterControlPoint(
"addFloatingIP",
func(sc hook.ServiceControl, args ...interface{}) error {
return fmt.Errorf("add floating IP should not have been called")
},
)
defer cleanup()
cleanup = s.srv.Service.Nova.RegisterControlPoint(
"addServerFloatingIP",
func(sc hook.ServiceControl, args ...interface{}) error {
return fmt.Errorf("add server floating IP should not have been called")
},
)
defer cleanup()
cfg, err := config.New(config.NoDefaults, s.TestConfig.Merge(coretesting.Attrs{
"use-floating-ip": false,
}))
c.Assert(err, gc.IsNil)
env, err := environs.Prepare(cfg, coretesting.Context(c), s.ConfigStore)
c.Assert(err, gc.IsNil)
err = bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
inst, _ := testing.AssertStartInstance(c, env, "100")
err = env.StopInstances([]instance.Instance{inst})
c.Assert(err, gc.IsNil)
}
示例12: TestNewConn
func (*NewAPIConnSuite) TestNewConn(c *gc.C) {
cfg, err := config.New(config.NoDefaults, dummy.SampleConfig())
c.Assert(err, gc.IsNil)
ctx := coretesting.Context(c)
env, err := environs.Prepare(cfg, ctx, configstore.NewMem())
c.Assert(err, gc.IsNil)
envtesting.UploadFakeTools(c, env.Storage())
err = bootstrap.Bootstrap(ctx, env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
cfg = env.Config()
cfg, err = cfg.Apply(map[string]interface{}{
"secret": "fnord",
})
c.Assert(err, gc.IsNil)
err = env.SetConfig(cfg)
c.Assert(err, gc.IsNil)
conn, err := juju.NewAPIConn(env, api.DefaultDialOpts())
c.Assert(err, gc.IsNil)
c.Assert(conn.Environ, gc.Equals, env)
c.Assert(conn.State, gc.NotNil)
// the secrets will not be updated, as they already exist
attrs, err := conn.State.Client().EnvironmentGet()
c.Assert(attrs["secret"], gc.Equals, "pork")
c.Assert(conn.Close(), gc.IsNil)
}
示例13: MakeConfig
// MakeConfig creates a functional environConfig for a test.
func MakeConfig(c *gc.C, attrs testing.Attrs) *environConfig {
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
env, err := environs.Prepare(cfg, testing.Context(c), configstore.NewMem())
c.Assert(err, gc.IsNil)
return env.(*joyentEnviron).Ecfg()
}
示例14: getEnvironConfig
func getEnvironConfig(c *gc.C, attrs map[string]interface{}) *environConfig {
testConfig, err := config.New(config.UseDefaults, attrs)
c.Assert(err, gc.IsNil)
envConfig, err := manualProvider{}.validate(testConfig, nil)
c.Assert(err, gc.IsNil)
return envConfig
}
示例15: loop
func (w *EnvironConfigWatcher) loop() (err error) {
sw := w.st.watchSettings(environGlobalKey)
defer sw.Stop()
out := w.out
out = nil
cfg := &config.Config{}
for {
select {
case <-w.st.watcher.Dead():
return stateWatcherDeadError(w.st.watcher.Err())
case <-w.tomb.Dying():
return tomb.ErrDying
case settings, ok := <-sw.Changes():
if !ok {
return watcher.MustErr(sw)
}
cfg, err = config.New(config.NoDefaults, settings.Map())
if err == nil {
out = w.out
} else {
out = nil
}
case out <- cfg:
out = nil
}
}
}