Skip to content

Commit

Permalink
daemon: remove custom notice type from notices API
Browse files Browse the repository at this point in the history
In snapd, there are no user-defined notices, so there is no need for a
custom notice type.

Signed-off-by: Oliver Calder <[email protected]>
  • Loading branch information
olivercalder committed Nov 15, 2023
1 parent 9f7c29d commit 8a529f9
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions daemon/api_notices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ type noticesSuite struct {

func (s *noticesSuite) TestNoticesFilterType(c *C) {
s.testNoticesFilter(c, func(after time.Time) url.Values {
return url.Values{"types": {"custom"}}
return url.Values{"types": {"change-update"}}
})
}

func (s *noticesSuite) TestNoticesFilterKey(c *C) {
s.testNoticesFilter(c, func(after time.Time) url.Values {
return url.Values{"keys": {"a.b/2"}}
return url.Values{"keys": {"123"}}
})
}

Expand All @@ -53,8 +53,8 @@ func (s *noticesSuite) TestNoticesFilterAfter(c *C) {
func (s *noticesSuite) TestNoticesFilterAll(c *C) {
s.testNoticesFilter(c, func(after time.Time) url.Values {
return url.Values{
"types": {"custom"},
"keys": {"a.b/2"},
"types": {"change-update"},
"keys": {"123"},
"after": {after.UTC().Format(time.RFC3339Nano)},
}
})
Expand All @@ -68,7 +68,7 @@ func (s *noticesSuite) testNoticesFilter(c *C, makeQuery func(after time.Time) u
addNotice(c, st, state.WarningNotice, "warning", nil)
after := time.Now()
time.Sleep(time.Microsecond)
noticeId, err := st.AddNotice(state.CustomNotice, "a.b/2", &state.AddNoticeOptions{
noticeId, err := st.AddNotice(state.ChangeUpdateNotice, "123", &state.AddNoticeOptions{
Data: map[string]string{"k": "v"},
})
c.Assert(err, IsNil)
Expand Down Expand Up @@ -100,8 +100,8 @@ func (s *noticesSuite) testNoticesFilter(c *C, makeQuery func(after time.Time) u
delete(n, "last-repeated")
c.Assert(n, DeepEquals, map[string]any{
"id": noticeId,
"type": "custom",
"key": "a.b/2",
"type": "change-update",
"key": "123",
"occurrences": 1.0,
"last-data": map[string]any{"k": "v"},
"expire-after": "168h0m0s",
Expand All @@ -115,8 +115,6 @@ func (s *noticesSuite) TestNoticesFilterMultipleTypes(c *C) {
st.Lock()
addNotice(c, st, state.ChangeUpdateNotice, "123", nil)
time.Sleep(time.Microsecond)
addNotice(c, st, state.CustomNotice, "a.b/x", nil)
time.Sleep(time.Microsecond)
addNotice(c, st, state.WarningNotice, "danger", nil)
st.Unlock()

Expand All @@ -141,12 +139,12 @@ func (s *noticesSuite) TestNoticesFilterMultipleKeys(c *C) {
st.Lock()
addNotice(c, st, state.ChangeUpdateNotice, "123", nil)
time.Sleep(time.Microsecond)
addNotice(c, st, state.CustomNotice, "a.b/x", nil)
addNotice(c, st, state.ChangeUpdateNotice, "456", nil)
time.Sleep(time.Microsecond)
addNotice(c, st, state.WarningNotice, "danger", nil)
st.Unlock()

req, err := http.NewRequest("GET", "/v2/notices?keys=a.b/x&keys=danger", nil)
req, err := http.NewRequest("GET", "/v2/notices?keys=456&keys=danger", nil)
c.Assert(err, IsNil)
rsp := s.syncReq(c, req, nil)
c.Check(rsp.Status, Equals, 200)
Expand All @@ -155,7 +153,7 @@ func (s *noticesSuite) TestNoticesFilterMultipleKeys(c *C) {
c.Assert(ok, Equals, true)
c.Assert(notices, HasLen, 2)
n := noticeToMap(c, notices[0])
c.Assert(n["key"], Equals, "a.b/x")
c.Assert(n["key"], Equals, "456")
n = noticeToMap(c, notices[1])
c.Assert(n["key"], Equals, "danger")
}
Expand All @@ -167,7 +165,7 @@ func (s *noticesSuite) TestNoticesWait(c *C) {
go func() {
time.Sleep(10 * time.Millisecond)
st.Lock()
addNotice(c, st, state.CustomNotice, "a.b/1", nil)
addNotice(c, st, state.WarningNotice, "foo", nil)
st.Unlock()
}()

Expand All @@ -180,8 +178,8 @@ func (s *noticesSuite) TestNoticesWait(c *C) {
c.Assert(ok, Equals, true)
c.Assert(notices, HasLen, 1)
n := noticeToMap(c, notices[0])
c.Check(n["type"], Equals, "custom")
c.Check(n["key"], Equals, "a.b/1")
c.Check(n["type"], Equals, "warning")
c.Check(n["key"], Equals, "foo")
}

func (s *noticesSuite) TestNoticesTimeout(c *C) {
Expand Down Expand Up @@ -242,10 +240,10 @@ func (s *noticesSuite) TestNotice(c *C) {

st := s.d.Overlord().State()
st.Lock()
addNotice(c, st, state.CustomNotice, "a.b/1", nil)
noticeId, err := st.AddNotice(state.CustomNotice, "a.b/2", nil)
addNotice(c, st, state.WarningNotice, "foo", nil)
noticeId, err := st.AddNotice(state.WarningNotice, "bar", nil)
c.Assert(err, IsNil)
addNotice(c, st, state.CustomNotice, "a.b/3", nil)
addNotice(c, st, state.WarningNotice, "baz", nil)
st.Unlock()

req, err := http.NewRequest("GET", "/v2/notices/"+noticeId, nil)
Expand All @@ -257,8 +255,8 @@ func (s *noticesSuite) TestNotice(c *C) {
notice, ok := rsp.Result.(*state.Notice)
c.Assert(ok, Equals, true)
n := noticeToMap(c, notice)
c.Check(n["type"], Equals, "custom")
c.Check(n["key"], Equals, "a.b/2")
c.Check(n["type"], Equals, "warning")
c.Check(n["key"], Equals, "bar")
}

func (s *noticesSuite) TestNoticeNotFound(c *C) {
Expand Down

0 comments on commit 8a529f9

Please sign in to comment.