mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-04-05 06:07:34 +03:00
Fix since=<id>
implementation for multiple topics, closes #336
This commit is contained in:
parent
30c2a67869
commit
d05211648d
4 changed files with 63 additions and 7 deletions
|
@ -437,6 +437,53 @@ func TestServer_PublishAndPollSince(t *testing.T) {
|
|||
require.Equal(t, 40008, toHTTPError(t, response.Body.String()).Code)
|
||||
}
|
||||
|
||||
func newMessageWithTimestamp(topic, message string, timestamp int64) *message {
|
||||
m := newDefaultMessage(topic, message)
|
||||
m.Time = timestamp
|
||||
return m
|
||||
}
|
||||
|
||||
func TestServer_PollSinceID_MultipleTopics(t *testing.T) {
|
||||
s := newTestServer(t, newTestConfig(t))
|
||||
|
||||
require.Nil(t, s.messageCache.AddMessage(newMessageWithTimestamp("mytopic1", "test 1", 1655740277)))
|
||||
markerMessage := newMessageWithTimestamp("mytopic2", "test 2", 1655740283)
|
||||
require.Nil(t, s.messageCache.AddMessage(markerMessage))
|
||||
require.Nil(t, s.messageCache.AddMessage(newMessageWithTimestamp("mytopic1", "test 3", 1655740289)))
|
||||
require.Nil(t, s.messageCache.AddMessage(newMessageWithTimestamp("mytopic2", "test 4", 1655740293)))
|
||||
require.Nil(t, s.messageCache.AddMessage(newMessageWithTimestamp("mytopic1", "test 5", 1655740297)))
|
||||
require.Nil(t, s.messageCache.AddMessage(newMessageWithTimestamp("mytopic2", "test 6", 1655740303)))
|
||||
|
||||
response := request(t, s, "GET", fmt.Sprintf("/mytopic1,mytopic2/json?poll=1&since=%s", markerMessage.ID), "", nil)
|
||||
messages := toMessages(t, response.Body.String())
|
||||
require.Equal(t, 4, len(messages))
|
||||
require.Equal(t, "test 3", messages[0].Message)
|
||||
require.Equal(t, "mytopic1", messages[0].Topic)
|
||||
require.Equal(t, "test 4", messages[1].Message)
|
||||
require.Equal(t, "mytopic2", messages[1].Topic)
|
||||
require.Equal(t, "test 5", messages[2].Message)
|
||||
require.Equal(t, "mytopic1", messages[2].Topic)
|
||||
require.Equal(t, "test 6", messages[3].Message)
|
||||
require.Equal(t, "mytopic2", messages[3].Topic)
|
||||
}
|
||||
|
||||
func TestServer_PollSinceID_MultipleTopics_IDDoesNotMatch(t *testing.T) {
|
||||
s := newTestServer(t, newTestConfig(t))
|
||||
|
||||
require.Nil(t, s.messageCache.AddMessage(newMessageWithTimestamp("mytopic1", "test 3", 1655740289)))
|
||||
require.Nil(t, s.messageCache.AddMessage(newMessageWithTimestamp("mytopic2", "test 4", 1655740293)))
|
||||
require.Nil(t, s.messageCache.AddMessage(newMessageWithTimestamp("mytopic1", "test 5", 1655740297)))
|
||||
require.Nil(t, s.messageCache.AddMessage(newMessageWithTimestamp("mytopic2", "test 6", 1655740303)))
|
||||
|
||||
response := request(t, s, "GET", "/mytopic1,mytopic2/json?poll=1&since=NoMatchForID", "", nil)
|
||||
messages := toMessages(t, response.Body.String())
|
||||
require.Equal(t, 4, len(messages))
|
||||
require.Equal(t, "test 3", messages[0].Message)
|
||||
require.Equal(t, "test 4", messages[1].Message)
|
||||
require.Equal(t, "test 5", messages[2].Message)
|
||||
require.Equal(t, "test 6", messages[3].Message)
|
||||
}
|
||||
|
||||
func TestServer_PublishViaGET(t *testing.T) {
|
||||
s := newTestServer(t, newTestConfig(t))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue