本文整理匯總了Golang中github.com/juju/juju/testing.FakeConfig函數的典型用法代碼示例。如果您正苦於以下問題:Golang FakeConfig函數的具體用法?Golang FakeConfig怎麽用?Golang FakeConfig使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了FakeConfig函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestUpdateToolsAvailabilityNoMatches
func (s *AgentToolsSuite) TestUpdateToolsAvailabilityNoMatches(c *gc.C) {
fakeModelConfig := func(_ *state.Model) (*config.Config, error) {
sConfig := coretesting.FakeConfig()
sConfig = sConfig.Merge(coretesting.Attrs{
"agent-version": "2.5.0",
})
return config.New(config.NoDefaults, sConfig)
}
s.PatchValue(&modelConfig, fakeModelConfig)
// No new tools available.
fakeToolFinder := func(_ environs.Environ, _ int, _ int, _ string, _ coretools.Filter) (coretools.List, error) {
return nil, errors.NotFoundf("tools")
}
// Update should never be called.
fakeUpdate := func(_ *state.Model, v version.Number) error {
c.Fail()
return nil
}
cfg, err := config.New(config.NoDefaults, coretesting.FakeConfig())
c.Assert(err, jc.ErrorIsNil)
err = updateToolsAvailability(&mockState{configGetter{cfg}}, getDummyEnviron, fakeToolFinder, fakeUpdate)
c.Assert(err, jc.ErrorIsNil)
}
示例2: TestUpdateToolsAvailability
func (s *AgentToolsSuite) TestUpdateToolsAvailability(c *gc.C) {
fakeModelConfig := func(_ *state.Model) (*config.Config, error) {
sConfig := coretesting.FakeConfig()
sConfig = sConfig.Merge(coretesting.Attrs{
"agent-version": "2.5.0",
})
return config.New(config.NoDefaults, sConfig)
}
s.PatchValue(&modelConfig, fakeModelConfig)
fakeToolFinder := func(_ environs.Environ, _ int, _ int, _ string, _ coretools.Filter) (coretools.List, error) {
ver := version.Binary{Number: version.Number{Major: 2, Minor: 5, Patch: 2}}
olderVer := version.Binary{Number: version.Number{Major: 2, Minor: 5, Patch: 1}}
t := coretools.Tools{Version: ver, URL: "http://example.com", Size: 1}
tOld := coretools.Tools{Version: olderVer, URL: "http://example.com", Size: 1}
return coretools.List{&t, &tOld}, nil
}
var ver version.Number
fakeUpdate := func(_ *state.Model, v version.Number) error {
ver = v
return nil
}
cfg, err := config.New(config.NoDefaults, coretesting.FakeConfig())
c.Assert(err, jc.ErrorIsNil)
err = updateToolsAvailability(&mockState{configGetter{cfg}}, getDummyEnviron, fakeToolFinder, fakeUpdate)
c.Assert(err, jc.ErrorIsNil)
c.Assert(ver, gc.Not(gc.Equals), version.Zero)
c.Assert(ver, gc.Equals, version.Number{Major: 2, Minor: 5, Patch: 2})
}
示例3: TestCredentialsSetup
func (suite *EnvironProviderSuite) TestCredentialsSetup(c *gc.C) {
attrs := testing.FakeConfig().Merge(testing.Attrs{
"type": "maas",
})
config, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
cfg, err := providerInstance.BootstrapConfig(environs.BootstrapConfigParams{
Config: config,
CloudEndpoint: "http://maas.testing.invalid/maas/",
Credentials: cloud.NewCredential(
cloud.OAuth1AuthType,
map[string]string{
"maas-oauth": "aa:bb:cc",
},
),
})
c.Assert(err, jc.ErrorIsNil)
attrs = cfg.UnknownAttrs()
server, ok := attrs["maas-server"]
c.Assert(ok, jc.IsTrue)
c.Assert(server, gc.Equals, "http://maas.testing.invalid/maas/")
oauth, ok := attrs["maas-oauth"]
c.Assert(ok, jc.IsTrue)
c.Assert(oauth, gc.Equals, "aa:bb:cc")
}
示例4: TestCheckTools
func (s *AgentToolsSuite) TestCheckTools(c *gc.C) {
sConfig := coretesting.FakeConfig()
sConfig = sConfig.Merge(coretesting.Attrs{
"agent-version": "2.5.0",
})
cfg, err := config.New(config.NoDefaults, sConfig)
c.Assert(err, jc.ErrorIsNil)
var (
calledWithMajor, calledWithMinor int
)
fakeToolFinder := func(e environs.Environ, maj int, min int, stream string, filter coretools.Filter) (coretools.List, error) {
calledWithMajor = maj
calledWithMinor = min
ver := version.Binary{Number: version.Number{Major: maj, Minor: min}}
t := coretools.Tools{Version: ver, URL: "http://example.com", Size: 1}
c.Assert(calledWithMajor, gc.Equals, 2)
c.Assert(calledWithMinor, gc.Equals, 5)
c.Assert(stream, gc.Equals, "released")
return coretools.List{&t}, nil
}
ver, err := checkToolsAvailability(getDummyEnviron, cfg, fakeToolFinder)
c.Assert(err, jc.ErrorIsNil)
c.Assert(ver, gc.Not(gc.Equals), version.Zero)
c.Assert(ver, gc.Equals, version.Number{Major: 2, Minor: 5, Patch: 0})
}
示例5: TestUnknownAttrsContainAgentName
func (suite *EnvironProviderSuite) TestUnknownAttrsContainAgentName(c *gc.C) {
attrs := testing.FakeConfig().Merge(testing.Attrs{
"type": "maas",
})
config, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
cfg, err := providerInstance.BootstrapConfig(environs.BootstrapConfigParams{
Config: config,
CloudEndpoint: "http://maas.testing.invalid/maas/",
Credentials: cloud.NewCredential(
cloud.OAuth1AuthType,
map[string]string{
"maas-oauth": "aa:bb:cc",
},
),
})
c.Assert(err, jc.ErrorIsNil)
unknownAttrs := cfg.UnknownAttrs()
c.Assert(unknownAttrs["maas-server"], gc.Equals, "http://maas.testing.invalid/maas/")
uuid, ok := unknownAttrs["maas-agent-name"]
c.Assert(ok, jc.IsTrue)
c.Assert(uuid, jc.Satisfies, utils.IsValidUUIDString)
}
示例6: GetFakeConfig
func GetFakeConfig() coretesting.Attrs {
return coretesting.FakeConfig().Merge(coretesting.Attrs{
"name": "joyent-test-model",
"type": "joyent",
"agent-version": coretesting.FakeVersionNumber.String(),
})
}
示例7: TestPrepareSetsDefaultBlockSource
func (s *ConfigSuite) TestPrepareSetsDefaultBlockSource(c *gc.C) {
s.PatchValue(&verifyCredentials, func(*environ) error { return nil })
attrs := testing.FakeConfig().Merge(testing.Attrs{
"type": "ec2",
})
config, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
cfg, err := providerInstance.BootstrapConfig(environs.BootstrapConfigParams{
Config: config,
CloudRegion: "test",
Credentials: cloud.NewCredential(
cloud.AccessKeyAuthType,
map[string]string{
"access-key": "x",
"secret-key": "y",
},
),
})
c.Assert(err, jc.ErrorIsNil)
source, ok := cfg.StorageDefaultBlockSource()
c.Assert(ok, jc.IsTrue)
c.Assert(source, gc.Equals, "ebs")
}
示例8: 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 maasModelConfig.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/model
// SetEnvironmentCommand' instead uses conn.State.ModelConfig() 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, jc.ErrorIsNil)
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, jc.ErrorIsNil)
validatedConfig, err := provider.Validate(baseCfg, nilCfg)
c.Assert(err, jc.ErrorIsNil)
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.*")
}
示例9: TestCheckToolsNonReleasedStream
func (s *AgentToolsSuite) TestCheckToolsNonReleasedStream(c *gc.C) {
sConfig := coretesting.FakeConfig()
sConfig = sConfig.Merge(coretesting.Attrs{
"agent-version": "2.5-alpha1",
"agent-stream": "proposed",
})
cfg, err := config.New(config.NoDefaults, sConfig)
c.Assert(err, jc.ErrorIsNil)
fakeNewEnvirons := func(*config.Config) (environs.Environ, error) {
return dummyEnviron{}, nil
}
s.PatchValue(&newEnvirons, fakeNewEnvirons)
var (
calledWithMajor, calledWithMinor int
calledWithStreams []string
)
fakeToolFinder := func(e environs.Environ, maj int, min int, stream string, filter coretools.Filter) (coretools.List, error) {
calledWithMajor = maj
calledWithMinor = min
calledWithStreams = append(calledWithStreams, stream)
if stream == "released" {
return nil, coretools.ErrNoMatches
}
ver := version.Binary{Number: version.Number{Major: maj, Minor: min}}
t := coretools.Tools{Version: ver, URL: "http://example.com", Size: 1}
c.Assert(calledWithMajor, gc.Equals, 2)
c.Assert(calledWithMinor, gc.Equals, 5)
return coretools.List{&t}, nil
}
ver, err := checkToolsAvailability(cfg, fakeToolFinder)
c.Assert(err, jc.ErrorIsNil)
c.Assert(calledWithStreams, gc.DeepEquals, []string{"released", "proposed"})
c.Assert(ver, gc.Not(gc.Equals), version.Zero)
c.Assert(ver, gc.Equals, version.Number{Major: 2, Minor: 5, Patch: 0})
}
示例10: TestStartInstanceOpensAPIPort
func (s *environBrokerSuite) TestStartInstanceOpensAPIPort(c *gc.C) {
s.FakeEnviron.Spec = s.spec
s.FakeEnviron.Inst = s.BaseInstance
s.FakeEnviron.Hwc = s.hardware
// Get the API port from the fake environment config used to
// "bootstrap".
envConfig := testing.FakeConfig()
apiPort, ok := envConfig["api-port"].(int)
c.Assert(ok, jc.IsTrue)
c.Assert(apiPort, gc.Not(gc.Equals), 0)
// When StateServingInfo is not nil, verify OpenPorts was called
// for the API port.
s.StartInstArgs.InstanceConfig.StateServingInfo = ¶ms.StateServingInfo{
APIPort: apiPort,
}
result, err := s.Env.StartInstance(s.StartInstArgs)
c.Assert(err, jc.ErrorIsNil)
c.Check(result.Instance, gc.DeepEquals, s.Instance)
c.Check(result.Hardware, gc.DeepEquals, s.hardware)
called, calls := s.FakeConn.WasCalled("OpenPorts")
c.Check(called, gc.Equals, true)
c.Check(calls, gc.HasLen, 1)
c.Check(calls[0].FirewallName, gc.Equals, gce.GlobalFirewallName(s.Env))
expectPorts := []network.PortRange{{
FromPort: apiPort,
ToPort: apiPort,
Protocol: "tcp",
}}
c.Check(calls[0].PortRanges, jc.DeepEquals, expectPorts)
}
示例11: makeEnviron
func (suite *maas2Suite) makeEnviron(c *gc.C, controller gomaasapi.Controller) *maasEnviron {
if controller != nil {
suite.injectController(controller)
}
testAttrs := coretesting.Attrs{}
for k, v := range maasEnvAttrs {
testAttrs[k] = v
}
testAttrs["agent-version"] = version.Current.String()
cred := cloud.NewCredential(cloud.OAuth1AuthType, map[string]string{
"maas-oauth": "a:b:c",
})
cloud := environs.CloudSpec{
Type: "maas",
Name: "maas",
Endpoint: "http://any-old-junk.invalid/",
Credential: &cred,
}
attrs := coretesting.FakeConfig().Merge(testAttrs)
suite.controllerUUID = coretesting.FakeControllerConfig().ControllerUUID()
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
env, err := NewEnviron(cloud, cfg)
c.Assert(err, jc.ErrorIsNil)
c.Assert(env, gc.NotNil)
return env
}
示例12: ConfigAttrs
func ConfigAttrs() testing.Attrs {
return testing.FakeConfig().Merge(testing.Attrs{
"type": "vsphere",
"uuid": "2d02eeac-9dbb-11e4-89d3-123b93f75cba",
"external-network": "",
})
}
示例13: testConfig
func testConfig(c *gc.C) *config.Config {
cfg, err := config.New(config.UseDefaults, coretesting.FakeConfig().Merge(coretesting.Attrs{
"type": "mock",
}))
c.Assert(err, jc.ErrorIsNil)
return cfg
}
示例14: TestCheckTools
func (s *updaterSuite) TestCheckTools(c *gc.C) {
sConfig := coretesting.FakeConfig()
sConfig = sConfig.Merge(coretesting.Attrs{
"agent-version": "2.5.0",
})
cfg, err := config.New(config.NoDefaults, sConfig)
c.Assert(err, jc.ErrorIsNil)
fakeNewEnvirons := func(*config.Config) (environs.Environ, error) {
return dummyEnviron{}, nil
}
s.PatchValue(&newEnvirons, fakeNewEnvirons)
var (
calledWithEnviron environs.Environ
calledWithMajor, calledWithMinor int
calledWithFilter coretools.Filter
)
fakeToolFinder := func(e environs.Environ, maj int, min int, _ string, filter coretools.Filter) (coretools.List, error) {
calledWithEnviron = e
calledWithMajor = maj
calledWithMinor = min
calledWithFilter = filter
ver := version.Binary{Number: version.Number{Major: maj, Minor: min}}
t := coretools.Tools{Version: ver, URL: "http://example.com", Size: 1}
c.Assert(calledWithMajor, gc.Equals, 2)
c.Assert(calledWithMinor, gc.Equals, 5)
return coretools.List{&t}, nil
}
ver, err := checkToolsAvailability(cfg, fakeToolFinder)
c.Assert(err, jc.ErrorIsNil)
c.Assert(ver, gc.Not(gc.Equals), version.Zero)
c.Assert(ver, gc.Equals, version.Number{Major: 2, Minor: 5, Patch: 0})
}
示例15: 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))
}