1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-05-23 15:27:38 +02:00

Fix panic in manager when attachment-cache-dir is not set, fixes

This commit is contained in:
binwiederhier 2023-02-17 15:56:48 -05:00
parent 7fb6f794e5
commit 38e7801b41
5 changed files with 68 additions and 30 deletions

View file

@ -0,0 +1,28 @@
package server
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestServer_Manager_Prune_Messages_Without_Attachments_DoesNotPanic(t *testing.T) {
// Tests that the manager runs without attachment-cache-dir set, see #617
c := newTestConfig(t)
c.AttachmentCacheDir = ""
s := newTestServer(t, c)
// Publish a message
rr := request(t, s, "POST", "/mytopic", "hi", nil)
require.Equal(t, 200, rr.Code)
m := toMessage(t, rr.Body.String())
// Expire message
require.Nil(t, s.messageCache.ExpireMessages("mytopic"))
// Does not panic
s.pruneMessages()
// Actually deleted
_, err := s.messageCache.Message(m.ID)
require.Equal(t, errMessageNotFound, err)
}