本文整理汇总了Golang中github.com/juju/juju/state.TestingDialOpts函数的典型用法代码示例。如果您正苦于以下问题:Golang TestingDialOpts函数的具体用法?Golang TestingDialOpts怎么用?Golang TestingDialOpts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TestingDialOpts函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestInitialize
func (s *InitializeSuite) TestInitialize(c *gc.C) {
cfg := testing.EnvironConfig(c)
initial := cfg.AllAttrs()
st, err := state.Initialize(state.TestingStateInfo(), cfg, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
c.Assert(st, gc.NotNil)
err = st.Close()
c.Assert(err, gc.IsNil)
s.openState(c)
cfg, err = s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
c.Assert(cfg.AllAttrs(), gc.DeepEquals, initial)
env, err := s.State.Environment()
c.Assert(err, gc.IsNil)
entity, err := s.State.FindEntity("environment-" + env.UUID())
c.Assert(err, gc.IsNil)
annotator := entity.(state.Annotator)
annotations, err := annotator.Annotations()
c.Assert(err, gc.IsNil)
c.Assert(annotations, gc.HasLen, 0)
cons, err := s.State.EnvironConstraints()
c.Assert(err, gc.IsNil)
c.Assert(&cons, jc.Satisfies, constraints.IsEmpty)
addrs, err := s.State.APIHostPorts()
c.Assert(err, gc.IsNil)
c.Assert(addrs, gc.HasLen, 0)
info, err := s.State.StateServerInfo()
c.Assert(err, gc.IsNil)
c.Assert(info, jc.DeepEquals, &state.StateServerInfo{})
}
开发者ID:rogpeppe,项目名称:juju,代码行数:35,代码来源:initialize_test.go
示例2: TestInitialize
func (s *InitializeSuite) TestInitialize(c *gc.C) {
cfg := testing.EnvironConfig(c)
uuid, _ := cfg.UUID()
initial := cfg.AllAttrs()
st, err := state.Initialize(state.TestingMongoInfo(), cfg, state.TestingDialOpts(), nil)
c.Assert(err, gc.IsNil)
c.Assert(st, gc.NotNil)
envTag := st.EnvironTag()
c.Assert(envTag.Id(), gc.Equals, uuid)
err = st.Close()
c.Assert(err, gc.IsNil)
s.openState(c)
cfg, err = s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
c.Assert(cfg.AllAttrs(), gc.DeepEquals, initial)
// Check that the environment has been created.
env, err := s.State.Environment()
c.Assert(err, gc.IsNil)
c.Assert(env.Tag(), gc.Equals, envTag)
// Check that the owner has been created.
owner := names.NewLocalUserTag("admin")
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, gc.IsNil)
c.Assert(entity.Tag(), gc.Equals, owner)
// Check that the owner has an EnvUser created for the bootstrapped environment.
envUser, err := s.State.EnvironmentUser(env.Owner())
c.Assert(err, gc.IsNil)
c.Assert(envUser.UserTag().Username(), gc.Equals, env.Owner().Username())
c.Assert(envUser.EnvironmentTag(), gc.Equals, env.Tag())
// Check that the environment can be found through the tag.
entity, err = s.State.FindEntity(envTag)
c.Assert(err, gc.IsNil)
annotator := entity.(state.Annotator)
annotations, err := annotator.Annotations()
c.Assert(err, gc.IsNil)
c.Assert(annotations, gc.HasLen, 0)
cons, err := s.State.EnvironConstraints()
c.Assert(err, gc.IsNil)
c.Assert(&cons, jc.Satisfies, constraints.IsEmpty)
addrs, err := s.State.APIHostPorts()
c.Assert(err, gc.IsNil)
c.Assert(addrs, gc.HasLen, 0)
info, err := s.State.StateServerInfo()
c.Assert(err, gc.IsNil)
c.Assert(info, jc.DeepEquals, &state.StateServerInfo{EnvironmentTag: envTag})
}
开发者ID:zhouqt,项目名称:juju,代码行数:53,代码来源:initialize_test.go
示例3: TestDoubleInitializeConfig
func (s *InitializeSuite) TestDoubleInitializeConfig(c *gc.C) {
cfg := testing.EnvironConfig(c)
initial := cfg.AllAttrs()
st := TestingInitialize(c, cfg, nil)
st.Close()
// A second initialize returns an open *State, but ignores its params.
// TODO(fwereade) I think this is crazy, but it's what we were testing
// for originally...
cfg, err := cfg.Apply(map[string]interface{}{"authorized-keys": "something-else"})
c.Assert(err, gc.IsNil)
st, err = state.Initialize(state.TestingMongoInfo(), cfg, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
c.Assert(st, gc.NotNil)
st.Close()
s.openState(c)
cfg, err = s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
c.Assert(cfg.AllAttrs(), gc.DeepEquals, initial)
}
开发者ID:kapilt,项目名称:juju,代码行数:21,代码来源:initialize_test.go
示例4: TestEnvironConfigWithAdminSecret
func (s *InitializeSuite) TestEnvironConfigWithAdminSecret(c *gc.C) {
// admin-secret blocks Initialize.
good := testing.EnvironConfig(c)
badUpdateAttrs := map[string]interface{}{"admin-secret": "foo"}
bad, err := good.Apply(badUpdateAttrs)
_, err = state.Initialize(state.TestingMongoInfo(), bad, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.ErrorMatches, "admin-secret should never be written to the state")
// admin-secret blocks UpdateEnvironConfig.
st := TestingInitialize(c, good, nil)
st.Close()
s.openState(c)
err = s.State.UpdateEnvironConfig(badUpdateAttrs, nil, nil)
c.Assert(err, gc.ErrorMatches, "admin-secret should never be written to the state")
// EnvironConfig remains inviolate.
cfg, err := s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
c.Assert(cfg.AllAttrs(), gc.DeepEquals, good.AllAttrs())
}
开发者ID:kapilt,项目名称:juju,代码行数:22,代码来源:initialize_test.go
示例5: TestEnvironConfigWithoutAgentVersion
func (s *InitializeSuite) TestEnvironConfigWithoutAgentVersion(c *gc.C) {
// admin-secret blocks Initialize.
good := testing.EnvironConfig(c)
attrs := good.AllAttrs()
delete(attrs, "agent-version")
bad, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
_, err = state.Initialize(state.TestingStateInfo(), bad, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.ErrorMatches, "agent-version must always be set in state")
st := state.TestingInitialize(c, good, state.Policy(nil))
st.Close()
s.openState(c)
err = s.State.UpdateEnvironConfig(map[string]interface{}{}, []string{"agent-version"}, nil)
c.Assert(err, gc.ErrorMatches, "agent-version must always be set in state")
// EnvironConfig remains inviolate.
cfg, err := s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
c.Assert(cfg.AllAttrs(), gc.DeepEquals, good.AllAttrs())
}
开发者ID:rogpeppe,项目名称:juju,代码行数:23,代码来源:initialize_test.go
示例6: openState
func (s *InitializeSuite) openState(c *gc.C) {
st, err := state.Open(state.TestingMongoInfo(), state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
s.State = st
}
开发者ID:kapilt,项目名称:juju,代码行数:5,代码来源:initialize_test.go
示例7: openState
func (s *InitializeSuite) openState(c *gc.C) {
var err error
s.State, err = state.Open(state.TestingStateInfo(), state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:5,代码来源:initialize_test.go
示例8: TestSetMongoPasswordOnUnitAfterConnectingAsMachineEntity
func (s *UnitSuite) TestSetMongoPasswordOnUnitAfterConnectingAsMachineEntity(c *gc.C) {
// Make a second unit to use later. (Subordinate units can only be created
// as a side-effect of a principal entering relation scope.)
subUnit := s.addSubordinateUnit(c)
info := state.TestingMongoInfo()
st, err := state.Open(info, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
defer st.Close()
// Turn on fully-authenticated mode.
err = st.SetAdminMongoPassword("admin-secret")
c.Assert(err, gc.IsNil)
// Add a new machine, assign the units to it
// and set its password.
m, err := st.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
unit, err := st.Unit(s.unit.Name())
c.Assert(err, gc.IsNil)
subUnit, err = st.Unit(subUnit.Name())
c.Assert(err, gc.IsNil)
err = unit.AssignToMachine(m)
c.Assert(err, gc.IsNil)
err = m.SetMongoPassword("foo")
c.Assert(err, gc.IsNil)
// Sanity check that we cannot connect with the wrong
// password
info.Tag = m.Tag()
info.Password = "foo1"
err = tryOpenState(info)
c.Assert(err, jc.Satisfies, errors.IsUnauthorized)
// Connect as the machine entity.
info.Tag = m.Tag()
info.Password = "foo"
st1, err := state.Open(info, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
defer st1.Close()
// Change the password for a unit derived from
// the machine entity's state.
unit, err = st1.Unit(s.unit.Name())
c.Assert(err, gc.IsNil)
err = unit.SetMongoPassword("bar")
c.Assert(err, gc.IsNil)
// Now connect as the unit entity and, as that
// that entity, change the password for a new unit.
info.Tag = unit.Tag()
info.Password = "bar"
st2, err := state.Open(info, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
defer st2.Close()
// Check that we can set its password.
unit, err = st2.Unit(subUnit.Name())
c.Assert(err, gc.IsNil)
err = unit.SetMongoPassword("bar2")
c.Assert(err, gc.IsNil)
// Clear the admin password, so tests can reset the db.
err = st.SetAdminMongoPassword("")
c.Assert(err, gc.IsNil)
}
开发者ID:jiasir,项目名称:juju,代码行数:65,代码来源:unit_test.go
注:本文中的github.com/juju/juju/state.TestingDialOpts函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论