本文整理汇总了Golang中github.com/juju/juju/mongo/mongotest.DialOpts函数的典型用法代码示例。如果您正苦于以下问题:Golang DialOpts函数的具体用法?Golang DialOpts怎么用?Golang DialOpts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DialOpts函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestInitializeWithInvalidCredentialType
func (s *InitializeSuite) TestInitializeWithInvalidCredentialType(c *gc.C) {
owner := names.NewLocalUserTag("initialize-admin")
modelCfg := testing.ModelConfig(c)
controllerCfg := testing.FakeControllerConfig()
credentialTag := names.NewCloudCredentialTag("dummy/" + owner.Canonical() + "/borken")
_, err := state.Initialize(state.InitializeParams{
Clock: clock.WallClock,
ControllerConfig: controllerCfg,
ControllerModelArgs: state.ModelArgs{
CloudName: "dummy",
Owner: owner,
Config: modelCfg,
StorageProviderRegistry: storage.StaticProviderRegistry{},
},
CloudName: "dummy",
Cloud: cloud.Cloud{
Type: "dummy",
AuthTypes: []cloud.AuthType{
cloud.AccessKeyAuthType, cloud.OAuth1AuthType,
},
},
CloudCredentials: map[names.CloudCredentialTag]cloud.Credential{
credentialTag: cloud.NewCredential(cloud.UserPassAuthType, nil),
},
MongoInfo: statetesting.NewMongoInfo(),
MongoDialOpts: mongotest.DialOpts(),
})
c.Assert(err, gc.ErrorMatches,
`validating initialization args: validating cloud credentials: credential "dummy/[email protected]/borken" with auth-type "userpass" is not supported \(expected one of \["access-key" "oauth1"\]\)`,
)
}
示例2: TestModelConfigWithoutAgentVersion
func (s *InitializeSuite) TestModelConfigWithoutAgentVersion(c *gc.C) {
// admin-secret blocks Initialize.
good := testing.ModelConfig(c)
attrs := good.AllAttrs()
delete(attrs, "agent-version")
bad, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
owner := names.NewLocalUserTag("initialize-admin")
_, err = state.Initialize(owner, statetesting.NewMongoInfo(), bad, mongotest.DialOpts(), state.Policy(nil))
c.Assert(err, gc.ErrorMatches, "agent-version must always be set in state")
st := statetesting.Initialize(c, owner, good, nil)
// yay side effects
st.Close()
s.openState(c, st.ModelTag())
err = s.State.UpdateModelConfig(map[string]interface{}{}, []string{"agent-version"}, nil)
c.Assert(err, gc.ErrorMatches, "agent-version must always be set in state")
// ModelConfig remains inviolate.
cfg, err := s.State.ModelConfig()
c.Assert(err, jc.ErrorIsNil)
c.Assert(cfg.AllAttrs(), gc.DeepEquals, good.AllAttrs())
}
示例3: openStateForUpgrade
func (s *UpgradeSuite) openStateForUpgrade() (*state.State, error) {
mongoInfo := s.State.MongoConnectionInfo()
st, err := state.Open(s.State.ModelTag(), mongoInfo, mongotest.DialOpts(), environs.NewStatePolicy())
if err != nil {
return nil, err
}
return st, nil
}
示例4: openState
func (s *InitializeSuite) openState(c *gc.C, modelTag names.ModelTag) {
st, err := state.Open(
modelTag,
statetesting.NewMongoInfo(),
mongotest.DialOpts(),
state.Policy(nil),
)
c.Assert(err, jc.ErrorIsNil)
s.State = st
}
示例5: TestInitializeWithCloudRegionConfig
func (s *InitializeSuite) TestInitializeWithCloudRegionConfig(c *gc.C) {
cfg := testing.ModelConfig(c)
uuid := cfg.UUID()
// Phony region-config
regionInheritedConfigIn := cloud.RegionConfig{
"a-region": cloud.Attrs{
"a-key": "a-value",
},
"b-region": cloud.Attrs{
"b-key": "b-value",
},
}
owner := names.NewLocalUserTag("initialize-admin")
controllerCfg := testing.FakeControllerConfig()
st, err := state.Initialize(state.InitializeParams{
Clock: clock.WallClock,
ControllerConfig: controllerCfg,
ControllerModelArgs: state.ModelArgs{
CloudName: "dummy",
Owner: owner,
Config: cfg,
StorageProviderRegistry: storage.StaticProviderRegistry{},
},
CloudName: "dummy",
Cloud: cloud.Cloud{
Type: "dummy",
AuthTypes: []cloud.AuthType{cloud.EmptyAuthType},
RegionConfig: regionInheritedConfigIn, // Init with phony region-config
},
MongoInfo: statetesting.NewMongoInfo(),
MongoDialOpts: mongotest.DialOpts(),
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(st, gc.NotNil)
modelTag := st.ModelTag()
c.Assert(modelTag.Id(), gc.Equals, uuid)
err = st.Close()
c.Assert(err, jc.ErrorIsNil)
s.openState(c, modelTag)
for k := range regionInheritedConfigIn {
// Query for config for each region
regionInheritedConfig, err := state.ReadSettings(
s.State, state.GlobalSettingsC,
"dummy#"+k)
c.Assert(err, jc.ErrorIsNil)
c.Assert(
cloud.Attrs(regionInheritedConfig.Map()),
jc.DeepEquals,
regionInheritedConfigIn[k])
}
}
示例6: TestInitializeWithCloudRegionHits
func (s *InitializeSuite) TestInitializeWithCloudRegionHits(c *gc.C) {
cfg := testing.ModelConfig(c)
uuid := cfg.UUID()
controllerInheritedConfigIn := map[string]interface{}{
"no-proxy": "local",
}
// Phony region-config
regionInheritedConfigIn := cloud.RegionConfig{
"a-region": cloud.Attrs{
"no-proxy": "a-value",
},
"b-region": cloud.Attrs{
"no-proxy": "b-value",
},
}
owner := names.NewLocalUserTag("initialize-admin")
controllerCfg := testing.FakeControllerConfig()
st, err := state.Initialize(state.InitializeParams{
Clock: clock.WallClock,
ControllerConfig: controllerCfg,
ControllerModelArgs: state.ModelArgs{
CloudName: "dummy",
Owner: owner,
Config: cfg,
StorageProviderRegistry: storage.StaticProviderRegistry{},
},
CloudName: "dummy",
Cloud: cloud.Cloud{
Type: "dummy",
AuthTypes: []cloud.AuthType{cloud.EmptyAuthType},
RegionConfig: regionInheritedConfigIn, // Init with phony region-config
},
ControllerInheritedConfig: controllerInheritedConfigIn,
MongoInfo: statetesting.NewMongoInfo(),
MongoDialOpts: mongotest.DialOpts(),
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(st, gc.NotNil)
modelTag := st.ModelTag()
c.Assert(modelTag.Id(), gc.Equals, uuid)
err = st.Close()
c.Assert(err, jc.ErrorIsNil)
s.openState(c, modelTag)
var attrs map[string]interface{}
for r := range regionInheritedConfigIn {
rspec := &environs.RegionSpec{Cloud: "dummy", Region: r}
got, err := s.State.ComposeNewModelConfig(attrs, rspec)
c.Check(err, jc.ErrorIsNil)
c.Assert(got["no-proxy"], gc.Equals, regionInheritedConfigIn[r]["no-proxy"])
}
}
示例7: openStateForUpgrade
func (s *UpgradeSuite) openStateForUpgrade() (*state.State, error) {
mongoInfo := s.State.MongoConnectionInfo()
newPolicy := stateenvirons.GetNewPolicyFunc(
stateenvirons.GetNewEnvironFunc(environs.New),
)
st, err := state.Open(s.State.ModelTag(), s.State.ControllerTag(), mongoInfo, mongotest.DialOpts(), newPolicy)
if err != nil {
return nil, err
}
return st, nil
}
示例8: Initialize
// Initialize initializes the state and returns it. If state was not
// already initialized, and cfg is nil, the minimal default model
// configuration will be used.
func Initialize(c *gc.C, owner names.UserTag, cfg *config.Config, policy state.Policy) *state.State {
if cfg == nil {
cfg = testing.ModelConfig(c)
}
mgoInfo := NewMongoInfo()
dialOpts := mongotest.DialOpts()
st, err := state.Initialize(owner, mgoInfo, cfg, dialOpts, policy)
c.Assert(err, jc.ErrorIsNil)
return st
}
示例9: TestInitializeWithControllerInheritedConfig
func (s *InitializeSuite) TestInitializeWithControllerInheritedConfig(c *gc.C) {
cfg := testing.ModelConfig(c)
uuid := cfg.UUID()
initial := cfg.AllAttrs()
controllerInheritedConfigIn := map[string]interface{}{
"default-series": initial["default-series"],
}
owner := names.NewLocalUserTag("initialize-admin")
controllerCfg := testing.FakeControllerConfig()
st, err := state.Initialize(state.InitializeParams{
Clock: clock.WallClock,
ControllerConfig: controllerCfg,
ControllerModelArgs: state.ModelArgs{
CloudName: "dummy",
Owner: owner,
Config: cfg,
StorageProviderRegistry: storage.StaticProviderRegistry{},
},
CloudName: "dummy",
Cloud: cloud.Cloud{
Type: "dummy",
AuthTypes: []cloud.AuthType{cloud.EmptyAuthType},
},
ControllerInheritedConfig: controllerInheritedConfigIn,
MongoInfo: statetesting.NewMongoInfo(),
MongoDialOpts: mongotest.DialOpts(),
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(st, gc.NotNil)
modelTag := st.ModelTag()
c.Assert(modelTag.Id(), gc.Equals, uuid)
err = st.Close()
c.Assert(err, jc.ErrorIsNil)
s.openState(c, modelTag)
controllerInheritedConfig, err := state.ReadSettings(s.State, state.GlobalSettingsC, state.ControllerInheritedSettingsGlobalKey)
c.Assert(err, jc.ErrorIsNil)
c.Assert(controllerInheritedConfig.Map(), jc.DeepEquals, controllerInheritedConfigIn)
expected := cfg.AllAttrs()
for k, v := range config.ConfigDefaults() {
if _, ok := expected[k]; !ok {
expected[k] = v
}
}
// Config as read from state has resources tags coerced to a map.
expected["resource-tags"] = map[string]string{}
cfg, err = s.State.ModelConfig()
c.Assert(err, jc.ErrorIsNil)
c.Assert(cfg.AllAttrs(), jc.DeepEquals, expected)
}
示例10: InitializeWithArgs
// InitializeWithArgs initializes the state and returns it. If state was not
// already initialized, and args.Config is nil, the minimal default model
// configuration will be used.
func InitializeWithArgs(c *gc.C, args InitializeArgs) *state.State {
if args.InitialConfig == nil {
args.InitialConfig = testing.ModelConfig(c)
}
mgoInfo := NewMongoInfo()
dialOpts := mongotest.DialOpts()
controllerCfg := testing.FakeControllerConfig()
st, err := state.Initialize(state.InitializeParams{
Clock: args.Clock,
ControllerConfig: controllerCfg,
ControllerModelArgs: state.ModelArgs{
CloudName: "dummy",
CloudRegion: "dummy-region",
Config: args.InitialConfig,
Owner: args.Owner,
StorageProviderRegistry: StorageProviders(),
},
ControllerInheritedConfig: args.ControllerInheritedConfig,
CloudName: "dummy",
Cloud: cloud.Cloud{
Type: "dummy",
AuthTypes: []cloud.AuthType{cloud.EmptyAuthType},
Regions: []cloud.Region{
cloud.Region{
Name: "dummy-region",
Endpoint: "dummy-endpoint",
IdentityEndpoint: "dummy-identity-endpoint",
StorageEndpoint: "dummy-storage-endpoint",
},
cloud.Region{
Name: "nether-region",
Endpoint: "nether-endpoint",
IdentityEndpoint: "nether-identity-endpoint",
StorageEndpoint: "nether-storage-endpoint",
},
cloud.Region{
Name: "unused-region",
Endpoint: "unused-endpoint",
IdentityEndpoint: "unused-identity-endpoint",
StorageEndpoint: "unused-storage-endpoint",
},
},
RegionConfig: args.RegionConfig,
},
MongoInfo: mgoInfo,
MongoDialOpts: dialOpts,
NewPolicy: args.NewPolicy,
})
c.Assert(err, jc.ErrorIsNil)
return st
}
示例11: TestInitialize
func (s *InitializeSuite) TestInitialize(c *gc.C) {
cfg := testing.ModelConfig(c)
uuid := cfg.UUID()
initial := cfg.AllAttrs()
owner := names.NewLocalUserTag("initialize-admin")
st, err := state.Initialize(owner, statetesting.NewMongoInfo(), cfg, mongotest.DialOpts(), nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(st, gc.NotNil)
modelTag := st.ModelTag()
c.Assert(modelTag.Id(), gc.Equals, uuid)
err = st.Close()
c.Assert(err, jc.ErrorIsNil)
s.openState(c, modelTag)
cfg, err = s.State.ModelConfig()
c.Assert(err, jc.ErrorIsNil)
c.Assert(cfg.AllAttrs(), gc.DeepEquals, initial)
// Check that the model has been created.
env, err := s.State.Model()
c.Assert(err, jc.ErrorIsNil)
c.Assert(env.Tag(), gc.Equals, modelTag)
// Check that the owner has been created.
c.Assert(env.Owner(), gc.Equals, owner)
// Check that the owner can be retrieved by the tag.
entity, err := s.State.FindEntity(env.Owner())
c.Assert(err, jc.ErrorIsNil)
c.Assert(entity.Tag(), gc.Equals, owner)
// Check that the owner has an ModelUser created for the bootstrapped model.
modelUser, err := s.State.ModelUser(env.Owner())
c.Assert(err, jc.ErrorIsNil)
c.Assert(modelUser.UserTag(), gc.Equals, owner)
c.Assert(modelUser.ModelTag(), gc.Equals, env.Tag())
// Check that the model can be found through the tag.
entity, err = s.State.FindEntity(modelTag)
c.Assert(err, jc.ErrorIsNil)
cons, err := s.State.ModelConstraints()
c.Assert(err, jc.ErrorIsNil)
c.Assert(&cons, jc.Satisfies, constraints.IsEmpty)
addrs, err := s.State.APIHostPorts()
c.Assert(err, jc.ErrorIsNil)
c.Assert(addrs, gc.HasLen, 0)
info, err := s.State.ControllerInfo()
c.Assert(err, jc.ErrorIsNil)
c.Assert(info, jc.DeepEquals, &state.ControllerInfo{ModelTag: modelTag})
}
示例12: testBadModelConfig
func (s *InitializeSuite) testBadModelConfig(c *gc.C, update map[string]interface{}, remove []string, expect string) {
good := testing.CustomModelConfig(c, testing.Attrs{"uuid": testing.ModelTag.Id()})
bad, err := good.Apply(update)
c.Assert(err, jc.ErrorIsNil)
bad, err = bad.Remove(remove)
c.Assert(err, jc.ErrorIsNil)
owner := names.NewLocalUserTag("initialize-admin")
controllerCfg := testing.FakeControllerConfig()
args := state.InitializeParams{
Clock: clock.WallClock,
ControllerConfig: controllerCfg,
ControllerModelArgs: state.ModelArgs{
CloudName: "dummy",
CloudRegion: "dummy-region",
Owner: owner,
Config: bad,
StorageProviderRegistry: storage.StaticProviderRegistry{},
},
CloudName: "dummy",
Cloud: cloud.Cloud{
Type: "dummy",
AuthTypes: []cloud.AuthType{cloud.EmptyAuthType},
Regions: []cloud.Region{{Name: "dummy-region"}},
},
MongoInfo: statetesting.NewMongoInfo(),
MongoDialOpts: mongotest.DialOpts(),
}
_, err = state.Initialize(args)
c.Assert(err, gc.ErrorMatches, expect)
args.ControllerModelArgs.Config = good
st, err := state.Initialize(args)
c.Assert(err, jc.ErrorIsNil)
st.Close()
s.openState(c, st.ModelTag())
err = s.State.UpdateModelConfig(update, remove, nil)
c.Assert(err, gc.ErrorMatches, expect)
// ModelConfig remains inviolate.
cfg, err := s.State.ModelConfig()
c.Assert(err, jc.ErrorIsNil)
goodWithDefaults, err := config.New(config.UseDefaults, good.AllAttrs())
c.Assert(err, jc.ErrorIsNil)
c.Assert(cfg.AllAttrs(), jc.DeepEquals, goodWithDefaults.AllAttrs())
}
示例13: Initialize
// Initialize initializes the state and returns it. If state was not
// already initialized, and cfg is nil, the minimal default model
// configuration will be used.
func Initialize(c *gc.C, owner names.UserTag, cfg *config.Config, controllerInheritedConfig map[string]interface{}, regionConfig cloud.RegionConfig, newPolicy state.NewPolicyFunc) *state.State {
if cfg == nil {
cfg = testing.ModelConfig(c)
}
mgoInfo := NewMongoInfo()
dialOpts := mongotest.DialOpts()
controllerCfg := testing.FakeControllerConfig()
st, err := state.Initialize(state.InitializeParams{
Clock: clock.WallClock,
ControllerConfig: controllerCfg,
ControllerModelArgs: state.ModelArgs{
CloudName: "dummy",
CloudRegion: "dummy-region",
Config: cfg,
Owner: owner,
StorageProviderRegistry: StorageProviders(),
},
ControllerInheritedConfig: controllerInheritedConfig,
CloudName: "dummy",
Cloud: cloud.Cloud{
Type: "dummy",
AuthTypes: []cloud.AuthType{cloud.EmptyAuthType},
Regions: []cloud.Region{
cloud.Region{
Name: "dummy-region",
Endpoint: "dummy-endpoint",
IdentityEndpoint: "dummy-identity-endpoint",
StorageEndpoint: "dummy-storage-endpoint",
},
cloud.Region{
Name: "nether-region",
Endpoint: "nether-endpoint",
IdentityEndpoint: "nether-identity-endpoint",
StorageEndpoint: "nether-storage-endpoint",
},
},
RegionConfig: regionConfig,
},
MongoInfo: mgoInfo,
MongoDialOpts: dialOpts,
NewPolicy: newPolicy,
})
c.Assert(err, jc.ErrorIsNil)
return st
}
示例14: TestUpdateModelConfigDefaults
func (s *ModelConfigSourceSuite) TestUpdateModelConfigDefaults(c *gc.C) {
// Set up values that will be removed.
attrs := map[string]interface{}{
"http-proxy": "http://http-proxy",
"https-proxy": "https://https-proxy",
}
err := s.State.UpdateModelConfigDefaultValues(attrs, nil, nil)
c.Assert(err, jc.ErrorIsNil)
attrs = map[string]interface{}{
"apt-mirror": "http://different-mirror",
}
err = s.State.UpdateModelConfigDefaultValues(attrs, []string{"http-proxy", "https-proxy"}, nil)
c.Assert(err, jc.ErrorIsNil)
info := statetesting.NewMongoInfo()
anotherState, err := state.Open(s.modelTag, s.State.ControllerTag(), info, mongotest.DialOpts(), state.NewPolicyFunc(nil))
c.Assert(err, jc.ErrorIsNil)
defer anotherState.Close()
cfg, err := anotherState.ModelConfigDefaultValues()
c.Assert(err, jc.ErrorIsNil)
expectedValues := make(config.ModelDefaultAttributes)
for attr, val := range config.ConfigDefaults() {
expectedValues[attr] = config.AttributeDefaultValues{
Default: val,
}
}
delete(expectedValues, "http-mirror")
delete(expectedValues, "https-mirror")
expectedValues["apt-mirror"] = config.AttributeDefaultValues{
Controller: "http://different-mirror",
Default: "",
Regions: []config.RegionDefaultValue{{
Name: "dummy-region",
Value: "http://dummy-mirror",
}}}
expectedValues["no-proxy"] = config.AttributeDefaultValues{
Default: "",
Regions: []config.RegionDefaultValue{{
Name: "dummy-region",
Value: "dummy-proxy",
}}}
c.Assert(cfg, jc.DeepEquals, expectedValues)
}
示例15: TestDoubleInitializeConfig
func (s *InitializeSuite) TestDoubleInitializeConfig(c *gc.C) {
cfg := testing.ModelConfig(c)
owner := names.NewLocalUserTag("initialize-admin")
mgoInfo := statetesting.NewMongoInfo()
dialOpts := mongotest.DialOpts()
st, err := state.Initialize(owner, mgoInfo, cfg, dialOpts, state.Policy(nil))
c.Assert(err, jc.ErrorIsNil)
err = st.Close()
c.Check(err, jc.ErrorIsNil)
st, err = state.Initialize(owner, mgoInfo, cfg, dialOpts, state.Policy(nil))
c.Check(err, gc.ErrorMatches, "already initialized")
if !c.Check(st, gc.IsNil) {
err = st.Close()
c.Check(err, jc.ErrorIsNil)
}
}