Skip to content

Commit

Permalink
o/state: add notice types for request prompts and request rules (cano…
Browse files Browse the repository at this point in the history
…nical#14269)

* o/state: added notice types for prompting

Signed-off-by: Oliver Calder <[email protected]>

* o/state: rename prompting notice types

Rename "interfaces-prompting-request" to "interfaces-requests-prompt".
Rename "interfaces-prompting-rule-update" to "interfaces-requests-rule-update".

Signed-off-by: Oliver Calder <[email protected]>

* o/state: adjust prompting notice type variable names

Signed-off-by: Oliver Calder <[email protected]>

---------

Signed-off-by: Oliver Calder <[email protected]>
  • Loading branch information
olivercalder authored Aug 1, 2024
1 parent b1f5167 commit 265b25a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
11 changes: 10 additions & 1 deletion overlord/state/notices.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,20 @@ const (
// Recorded by "snap run" command when it is inhibited from running a
// a snap due an ongoing refresh.
SnapRunInhibitNotice NoticeType = "snap-run-inhibit"

// Recorded whenever a request prompt is created or resolved. The key for
// interfaces-requests-prompt notices is the request prompt ID.
InterfacesRequestsPromptNotice NoticeType = "interfaces-requests-prompt"

// Recorded whenever a request rule is created, modified, deleted, or
// expired. The key for interfaces-requests-rule-update notices is the
// rule ID.
InterfacesRequestsRuleUpdateNotice NoticeType = "interfaces-requests-rule-update"
)

func (t NoticeType) Valid() bool {
switch t {
case ChangeUpdateNotice, WarningNotice, RefreshInhibitNotice, SnapRunInhibitNotice:
case ChangeUpdateNotice, WarningNotice, RefreshInhibitNotice, SnapRunInhibitNotice, InterfacesRequestsPromptNotice, InterfacesRequestsRuleUpdateNotice:
return true
}
return false
Expand Down
20 changes: 7 additions & 13 deletions overlord/state/notices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ func (s *noticesSuite) TestNoticesFilterType(c *C) {

addNotice(c, st, nil, state.RefreshInhibitNotice, "-", nil)
time.Sleep(time.Microsecond)
addNotice(c, st, nil, state.InterfacesRequestsPromptNotice, "443", nil)
time.Sleep(time.Microsecond)
addNotice(c, st, nil, state.ChangeUpdateNotice, "123", nil)
time.Sleep(time.Microsecond)
addNotice(c, st, nil, state.WarningNotice, "Warning 1!", nil)
Expand All @@ -292,11 +294,11 @@ func (s *noticesSuite) TestNoticesFilterType(c *C) {

// No filter
notices := st.Notices(nil)
c.Assert(notices, HasLen, 5)
c.Assert(notices, HasLen, 6)

// No types
notices = st.Notices(&state.NoticeFilter{})
c.Assert(notices, HasLen, 5)
c.Assert(notices, HasLen, 6)

// One type
notices = st.Notices(&state.NoticeFilter{Types: []state.NoticeType{state.WarningNotice}})
Expand All @@ -310,14 +312,6 @@ func (s *noticesSuite) TestNoticesFilterType(c *C) {
c.Check(n["type"], Equals, "warning")
c.Check(n["key"], Equals, "Warning 2!")

// Another type
notices = st.Notices(&state.NoticeFilter{Types: []state.NoticeType{state.ChangeUpdateNotice}})
c.Assert(notices, HasLen, 1)
n = noticeToMap(c, notices[0])
c.Check(n["user-id"], Equals, nil)
c.Check(n["type"], Equals, "change-update")
c.Check(n["key"], Equals, "123")

// Another type
notices = st.Notices(&state.NoticeFilter{Types: []state.NoticeType{state.RefreshInhibitNotice}})
c.Assert(notices, HasLen, 1)
Expand All @@ -337,13 +331,13 @@ func (s *noticesSuite) TestNoticesFilterType(c *C) {
// Multiple types
notices = st.Notices(&state.NoticeFilter{Types: []state.NoticeType{
state.ChangeUpdateNotice,
state.RefreshInhibitNotice,
state.InterfacesRequestsPromptNotice,
}})
c.Assert(notices, HasLen, 2)
n = noticeToMap(c, notices[0])
c.Check(n["user-id"], Equals, nil)
c.Check(n["type"], Equals, "refresh-inhibit")
c.Check(n["key"], Equals, "-")
c.Check(n["type"], Equals, "interfaces-requests-prompt")
c.Check(n["key"], Equals, "443")
n = noticeToMap(c, notices[1])
c.Check(n["user-id"], Equals, nil)
c.Check(n["type"], Equals, "change-update")
Expand Down

0 comments on commit 265b25a

Please sign in to comment.