func (suite) TestCheckNoDataDir(c *C) { conf := agent.Conf{ StateInfo: &state.Info{ Addrs: []string{"x:4"}, CACert: []byte("xxx"), EntityName: "bar", Password: "******", }, } c.Assert(conf.Check(), ErrorMatches, "data directory not found in configuration") }
func (s *openSuite) TestOpenStateNormal(c *C) { conf := agent.Conf{ StateInfo: s.StateInfo(c), } conf.OldPassword = "******" st, changed, err := conf.OpenState() c.Assert(err, IsNil) defer st.Close() c.Assert(changed, Equals, false) c.Assert(st, NotNil) }
func (suite) TestConfFile(c *C) { conf := agent.Conf{ DataDir: "/foo", StateInfo: &state.Info{ Addrs: []string{"x:4"}, CACert: []byte("xxx"), EntityName: "bar", Password: "******", }, } c.Assert(conf.File("x/y"), Equals, "/foo/agents/bar/x/y") }
func (s *openSuite) TestOpenStateNoPassword(c *C) { conf := agent.Conf{ StateInfo: s.StateInfo(c), } conf.OldPassword = conf.StateInfo.Password conf.StateInfo.Password = "" st, changed, err := conf.OpenState() c.Assert(err, IsNil) defer st.Close() c.Assert(changed, Equals, true) c.Assert(st, NotNil) p, err := trivial.RandomPassword() c.Assert(err, IsNil) c.Assert(conf.StateInfo.Password, HasLen, len(p)) c.Assert(conf.OldPassword, Equals, s.StateInfo(c).Password) }
func runOnce(c *agent.Conf, a Agent) error { st, passwordChanged, err := c.OpenState() if err != nil { return err } defer st.Close() entity, err := a.Entity(st) if state.IsNotFound(err) || err == nil && entity.Life() == state.Dead { return worker.ErrDead } if err != nil { return err } if passwordChanged { if err := c.Write(); err != nil { return err } if err := entity.SetMongoPassword(c.StateInfo.Password); err != nil { return err } } return a.RunOnce(st, entity) }