Exemplo n.º 1
0
func (s *UnitAgentSuite) TestGetUnitAgentStatusHistory(c *gc.C) {
	err := state.EraseUnitHistory(s.unit)
	c.Assert(err, jc.ErrorIsNil)
	agent := s.unit.Agent().(*state.UnitAgent)
	globalKey := state.UnitAgentGlobalKey(agent)
	history := func(i int) ([]state.StatusInfo, error) {
		return agent.StatusHistory(i)
	}
	testGetUnitStatusHistory(c, history, s.State, globalKey)
}
Exemplo n.º 2
0
func (s *UnitAgentSuite) TestSetUnitAgentStatusHistory(c *gc.C) {
	err := state.EraseUnitHistory(s.unit)
	c.Assert(err, jc.ErrorIsNil)

	agent := s.unit.Agent().(*state.UnitAgent)
	globalKey := state.UnitAgentGlobalKey(agent)
	err = agent.SetStatus(state.StatusIdle, "to push something to history", nil)
	c.Assert(err, jc.ErrorIsNil)
	statusInfo, err := agent.Status()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(statusInfo.Status, gc.Equals, state.StatusIdle)

	h, err := state.StatusHistory(10, globalKey, s.State)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(h, gc.HasLen, 1)
	c.Assert(h[0].Status, gc.Equals, state.StatusAllocating)
	c.Assert(h[0].Message, gc.Equals, "")

	err = agent.SetStatus(state.StatusExecuting, "executing first thing", nil)
	c.Assert(err, jc.ErrorIsNil)
	statusInfo, err = agent.Status()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(statusInfo.Status, gc.Equals, state.StatusExecuting)

	err = agent.SetStatus(state.StatusExecuting, "wow executing again", nil)
	c.Assert(err, jc.ErrorIsNil)
	statusInfo, err = agent.Status()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(statusInfo.Status, gc.Equals, state.StatusExecuting)

	h, err = state.StatusHistory(10, globalKey, s.State)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(h, gc.HasLen, 3)
	var message string
	for i := 0; i < 3; i++ {
		c.Logf("checking status %q", h[i].Status)
		switch h[i].Status {
		case state.StatusAllocating:
			message = ""
		case state.StatusExecuting:
			message = "executing first thing"
		case state.StatusIdle:
			message = "to push something to history"
		}
		c.Assert(h[i].Message, gc.Equals, message)
	}
}