func (s *statusSuite) TestPruneStatusHistory(c *gc.C) { var oldDoc state.StatusDoc var err error st := s.State globalKey := "BogusKey" for changeno := 1; changeno <= 200; changeno++ { oldDoc = state.StatusDoc{ Status: "AGivenStatus", StatusInfo: fmt.Sprintf("Status change %d", changeno), StatusData: nil, } timestamp := state.NowToTheSecond() oldDoc.Updated = ×tamp hDoc := state.NewHistoricalStatusDoc(oldDoc, globalKey) h := txn.Op{ C: state.StatusesHistoryC, Id: changeno, Insert: hDoc, } err = state.RunTransaction(st, []txn.Op{h}) c.Logf("Adding a history entry attempt n: %d", changeno) c.Assert(err, jc.ErrorIsNil) } history, err := state.StatusHistory(500, globalKey, st) c.Assert(history, gc.HasLen, 200) c.Assert(history[0].Message, gc.Equals, "Status change 200") c.Assert(history[199].Message, gc.Equals, "Status change 1") err = state.PruneStatusHistory(st, 100) c.Assert(err, jc.ErrorIsNil) history, err = state.StatusHistory(500, globalKey, st) c.Assert(err, jc.ErrorIsNil) c.Assert(history, gc.HasLen, 100) c.Assert(history[0].Message, gc.Equals, "Status change 200") c.Assert(history[99].Message, gc.Equals, "Status change 101") }
func (s *statusSuite) TestPruneStatusHistory(c *gc.C) { var oldDoc state.StatusDoc var err error st := s.State globalKey := "BogusKey" for changeno := 1; changeno <= 200; changeno++ { oldDoc = state.StatusDoc{ EnvUUID: st.EnvironUUID(), Status: "AGivenStatus", StatusInfo: fmt.Sprintf("Status change %d", changeno), StatusData: nil, } timestamp := state.NowToTheSecond() oldDoc.Updated = ×tamp hDoc := state.NewHistoricalStatusDoc(changeno, oldDoc, globalKey) history, closer := state.GetCollection(st, state.StatusesHistoryC) historyW := history.Writeable() err = historyW.Insert(hDoc) closer() c.Logf("Adding a history entry attempt n: %d", changeno) c.Assert(err, jc.ErrorIsNil) } history, err := state.StatusHistory(500, globalKey, st) c.Assert(history, gc.HasLen, 200) c.Assert(history[0].Message, gc.Equals, "Status change 200") c.Assert(history[199].Message, gc.Equals, "Status change 1") err = state.PruneStatusHistory(st, 100) c.Assert(err, jc.ErrorIsNil) history, err = state.StatusHistory(500, globalKey, st) c.Assert(err, jc.ErrorIsNil) c.Assert(history, gc.HasLen, 100) c.Assert(history[0].Message, gc.Equals, "Status change 200") c.Assert(history[99].Message, gc.Equals, "Status change 101") }