本文整理汇总了Golang中github.com/wallyworld/core/testing.FakeConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang FakeConfig函数的具体用法?Golang FakeConfig怎么用?Golang FakeConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FakeConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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))
}
示例2: registerAmazonTests
func registerAmazonTests() {
// The following attributes hold the environment configuration
// for running the amazon EC2 integration tests.
//
// This is missing keys for security reasons; set the following
// environment variables to make the Amazon testing work:
// access-key: $AWS_ACCESS_KEY_ID
// secret-key: $AWS_SECRET_ACCESS_KEY
attrs := coretesting.FakeConfig().Merge(map[string]interface{}{
"name": "sample-" + uniqueName,
"type": "ec2",
"control-bucket": "juju-test-" + uniqueName,
"admin-secret": "for real",
"firewall-mode": config.FwInstance,
"agent-version": version.Current.Number.String(),
})
gc.Suite(&LiveTests{
LiveTests: jujutest.LiveTests{
TestConfig: attrs,
Attempt: *ec2.ShortAttempt,
CanOpenState: true,
HasProvisioner: true,
},
})
}
示例3: 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.*")
}
示例4: setupEnv
func (s *ConfigDeprecationSuite) setupEnv(c *gc.C, deprecatedKey, value string) {
s.setupEnvCredentials()
attrs := testing.FakeConfig().Merge(testing.Attrs{
"name": "testenv",
"type": "openstack",
"control-bucket": "x",
deprecatedKey: value,
})
_, err := environs.NewFromAttrs(attrs)
c.Assert(err, gc.IsNil)
}
示例5: testConfig
func testConfig(c *gc.C, stateServer bool, vers version.Binary) *config.Config {
testConfig, err := config.New(config.UseDefaults, coretesting.FakeConfig())
c.Assert(err, gc.IsNil)
testConfig, err = testConfig.Apply(map[string]interface{}{
"type": "sshinit_test",
"default-series": vers.Series,
"agent-version": vers.Number.String(),
})
c.Assert(err, gc.IsNil)
return testConfig
}
示例6: newConfig
// newConfig creates a MAAS environment config from attributes.
func newConfig(values map[string]interface{}) (*maasEnvironConfig, error) {
attrs := testing.FakeConfig().Merge(testing.Attrs{
"name": "testenv",
"type": "maas",
}).Merge(values)
env, err := environs.NewFromAttrs(attrs)
if err != nil {
return nil, err
}
return env.(*maasEnviron).ecfg(), nil
}
示例7: dummyConfig
func dummyConfig(c *gc.C) *config.Config {
testConfig, err := config.New(config.UseDefaults, coretesting.FakeConfig())
c.Assert(err, gc.IsNil)
testConfig, err = testConfig.Apply(map[string]interface{}{
"type": "dummy",
"state-server": false,
"agent-version": version.Current.Number.String(),
})
c.Assert(err, gc.IsNil)
return testConfig
}
示例8: getSimpleTestConfig
func getSimpleTestConfig(c *gc.C, extraAttrs coretesting.Attrs) *config.Config {
attrs := coretesting.FakeConfig()
attrs["type"] = "maas"
attrs["maas-server"] = "http://maas.testing.invalid"
attrs["maas-oauth"] = "a:b:c"
for k, v := range extraAttrs {
attrs[k] = v
}
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
return cfg
}
示例9: mockValidCfg
// To test UpdateEnvironConfig updates state, Validate returns a config
// different to both input configs
func mockValidCfg() (valid *config.Config, err error) {
cfg, err := config.New(config.UseDefaults, coretesting.FakeConfig())
if err != nil {
return nil, err
}
valid, err = cfg.Apply(map[string]interface{}{
"arbitrary-key": "cptn-marvel",
})
if err != nil {
return nil, err
}
return valid, nil
}
示例10: TestPrepareDoesNotTouchExistingControlBucket
func (s *ConfigSuite) TestPrepareDoesNotTouchExistingControlBucket(c *gc.C) {
attrs := testing.FakeConfig().Merge(testing.Attrs{
"type": "ec2",
"control-bucket": "burblefoo",
})
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
env, err := providerInstance.Prepare(testing.Context(c), cfg)
c.Assert(err, gc.IsNil)
bucket := env.(*environ).ecfg().controlBucket()
c.Assert(bucket, gc.Equals, "burblefoo")
}
示例11: makeEnviron
// makeEnviron creates a functional maasEnviron for a test.
func (suite *providerSuite) makeEnviron() *maasEnviron {
testAttrs := maasEnvAttrs
testAttrs["maas-server"] = suite.testMAASObject.TestServer.URL
attrs := coretesting.FakeConfig().Merge(maasEnvAttrs)
cfg, err := config.New(config.NoDefaults, attrs)
if err != nil {
panic(err)
}
env, err := NewEnviron(cfg)
if err != nil {
panic(err)
}
return env
}
示例12: validAttrs
func validAttrs() coretesting.Attrs {
return coretesting.FakeConfig().Merge(coretesting.Attrs{
"type": "joyent",
"sdc-user": "juju-test",
"sdc-key-id": "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff",
"sdc-url": "https://test.api.joyentcloud.com",
"manta-user": "juju-test",
"manta-key-id": "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff",
"manta-url": "https://test.manta.joyent.com",
"private-key-path": "~/.ssh/provider_id_rsa",
"algorithm": "rsa-sha256",
"control-dir": "juju-test",
"private-key": "key",
})
}
示例13: TestAgentNameShouldNotBeSetByHand
func (suite *EnvironProviderSuite) TestAgentNameShouldNotBeSetByHand(c *gc.C) {
testJujuHome := c.MkDir()
defer osenv.SetJujuHome(osenv.SetJujuHome(testJujuHome))
attrs := testing.FakeConfig().Merge(testing.Attrs{
"type": "maas",
"maas-oauth": "aa:bb:cc",
"maas-server": "http://maas.testing.invalid/maas/",
"maas-agent-name": "foobar",
})
config, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
ctx := testing.Context(c)
_, err = suite.makeEnviron().Provider().Prepare(ctx, config)
c.Assert(err, gc.Equals, errAgentNameAlreadySet)
}
示例14: GetFakeConfig
func GetFakeConfig(sdcUrl, mantaUrl string) coretesting.Attrs {
return coretesting.FakeConfig().Merge(coretesting.Attrs{
"name": "joyent test environment",
"type": "joyent",
"sdc-user": testUser,
"sdc-key-id": testKeyFingerprint,
"sdc-url": sdcUrl,
"manta-user": testUser,
"manta-key-id": testKeyFingerprint,
"manta-url": mantaUrl,
"private-key-path": fmt.Sprintf("~/.ssh/%s", testKeyFileName),
"algorithm": "rsa-sha256",
"control-dir": "juju-test",
"agent-version": version.Current.Number.String(),
})
}
示例15: TestSecretAttrsReturnsSensitiveMAASAttributes
func (suite *EnvironProviderSuite) TestSecretAttrsReturnsSensitiveMAASAttributes(c *gc.C) {
testJujuHome := c.MkDir()
defer osenv.SetJujuHome(osenv.SetJujuHome(testJujuHome))
const oauth = "aa:bb:cc"
attrs := testing.FakeConfig().Merge(testing.Attrs{
"type": "maas",
"maas-oauth": oauth,
"maas-server": "http://maas.testing.invalid/maas/",
})
config, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
secretAttrs, err := suite.makeEnviron().Provider().SecretAttrs(config)
c.Assert(err, gc.IsNil)
expectedAttrs := map[string]string{"maas-oauth": oauth}
c.Check(secretAttrs, gc.DeepEquals, expectedAttrs)
}