Skip to content

Commit

Permalink
feat(state): add core support for Pebble Notices (#295)
Browse files Browse the repository at this point in the history
This implements the core state aspects of Pebble Notices -- spec JU048.

The key user-visible methods are State.AddNotice to add a new notices, State.Notices and State.Notice to fetch and filter existing notices, and State.WaitNotices to wait (or long-poll) for notices as they occur.
  • Loading branch information
benhoyt authored Oct 6, 2023
1 parent 9decf59 commit d3a4c78
Show file tree
Hide file tree
Showing 5 changed files with 955 additions and 3 deletions.
10 changes: 9 additions & 1 deletion internals/overlord/overlord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ func (ovs *overlordSuite) TestNew(c *C) {
}

func (ovs *overlordSuite) TestNewWithGoodState(c *C) {
fakeState := []byte(fmt.Sprintf(`{"data":{"patch-level":%d,"patch-sublevel":%d,"patch-sublevel-last-version":%q,"some":"data"},"changes":null,"tasks":null,"last-change-id":0,"last-task-id":0,"last-lane-id":0}`, patch.Level, patch.Sublevel, cmd.Version))
fakeState := []byte(fmt.Sprintf(`{
"data": {"patch-level": %d, "patch-sublevel": %d, "patch-sublevel-last-version": %q, "some": "data"},
"changes": null,
"tasks": null,
"last-change-id": 0,
"last-task-id": 0,
"last-lane-id": 0,
"last-notice-id": 0
}`, patch.Level, patch.Sublevel, cmd.Version))
err := ioutil.WriteFile(ovs.statePath, fakeState, 0600)
c.Assert(err, IsNil)

Expand Down
6 changes: 6 additions & 0 deletions internals/overlord/state/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ var (
ErrNoWarningExpireAfter = errNoWarningExpireAfter
ErrNoWarningRepeatAfter = errNoWarningRepeatAfter
)

// NumNotices returns the total number of notices, including expired ones that
// haven't yet been pruned.
func (s *State) NumNotices() int {
return len(s.notices)
}
Loading

0 comments on commit d3a4c78

Please sign in to comment.