Пример #1
0
func (ses *stateEngineSuite) TestEnsureError(c *C) {
	s := state.New(nil)
	se := overlord.NewStateEngine(s)

	calls := []string{}

	err1 := errors.New("boom1")
	err2 := errors.New("boom2")

	mgr1 := &fakeManager{name: "mgr1", calls: &calls, ensureError: err1}
	mgr2 := &fakeManager{name: "mgr2", calls: &calls, ensureError: err2}

	se.AddManager(mgr1)
	se.AddManager(mgr2)

	err := se.Ensure()
	c.Check(err.Error(), DeepEquals, "state ensure errors: [boom1 boom2]")
	c.Check(calls, DeepEquals, []string{"ensure:mgr1", "ensure:mgr2"})
}
Пример #2
0
func (ses *stateEngineSuite) TestEnsure(c *C) {
	s := state.New(nil)
	se := overlord.NewStateEngine(s)

	calls := []string{}

	mgr1 := &fakeManager{name: "mgr1", calls: &calls}
	mgr2 := &fakeManager{name: "mgr2", calls: &calls}

	se.AddManager(mgr1)
	se.AddManager(mgr2)

	err := se.Ensure()
	c.Assert(err, IsNil)
	c.Check(calls, DeepEquals, []string{"ensure:mgr1", "ensure:mgr2"})

	err = se.Ensure()
	c.Assert(err, IsNil)
	c.Check(calls, DeepEquals, []string{"ensure:mgr1", "ensure:mgr2", "ensure:mgr1", "ensure:mgr2"})
}
Пример #3
0
func (ses *stateEngineSuite) TestStop(c *C) {
	s := state.New(nil)
	se := overlord.NewStateEngine(s)

	calls := []string{}

	mgr1 := &fakeManager{name: "mgr1", calls: &calls}
	mgr2 := &fakeManager{name: "mgr2", calls: &calls}

	se.AddManager(mgr1)
	se.AddManager(mgr2)

	se.Stop()
	c.Check(calls, DeepEquals, []string{"stop:mgr1", "stop:mgr2"})
	se.Stop()
	c.Check(calls, HasLen, 2)

	err := se.Ensure()
	c.Check(err, ErrorMatches, "state engine already stopped")
}
Пример #4
0
func (ses *stateEngineSuite) TestNewAndState(c *C) {
	s := state.New(nil)
	se := overlord.NewStateEngine(s)

	c.Check(se.State(), Equals, s)
}