diff --git a/docs/releases.md b/docs/releases.md index e4f78db..022d5f9 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -25,6 +25,7 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release **Documentation**: * [Examples](examples.md) for [Home Assistant](https://www.home-assistant.io/) ([#282](https://github.com/binwiederhier/ntfy/pull/282), thanks to [@poblabs](https://github.com/poblabs)) +* Install instructions for [NixOS/Nix](https://ntfy.sh/docs/install/#nixos-nix) ([#282](https://github.com/binwiederhier/ntfy/pull/282), thanks to [@arjan-s](https://github.com/arjan-s)) --> diff --git a/server/server_firebase_test.go b/server/server_firebase_test.go index 8e08b0d..a458f2e 100644 --- a/server/server_firebase_test.go +++ b/server/server_firebase_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "heckel.io/ntfy/auth" "strings" + "sync" "testing" ) @@ -29,6 +30,7 @@ func (t testAuther) Authorize(_ *auth.User, _ string, _ auth.Permission) error { type testFirebaseSender struct { allowed int messages []*messaging.Message + mu sync.Mutex } func newTestFirebaseSender(allowed int) *testFirebaseSender { @@ -37,7 +39,10 @@ func newTestFirebaseSender(allowed int) *testFirebaseSender { messages: make([]*messaging.Message, 0), } } + func (s *testFirebaseSender) Send(m *messaging.Message) error { + s.mu.Lock() + defer s.mu.Unlock() if len(s.messages)+1 > s.allowed { return errFirebaseQuotaExceeded } @@ -45,6 +50,16 @@ func (s *testFirebaseSender) Send(m *messaging.Message) error { return nil } +func (s *testFirebaseSender) Messages() []*messaging.Message { + s.mu.Lock() + defer s.mu.Unlock() + messages := make([]*messaging.Message, 0) + for _, m := range s.messages { + messages = append(messages, m) + } + return messages +} + func TestToFirebaseMessage_Keepalive(t *testing.T) { m := newKeepaliveMessage("mytopic") fbm, err := toFirebaseMessage(m, nil) @@ -311,15 +326,15 @@ func TestToFirebaseSender_Abuse(t *testing.T) { visitor := newVisitor(newTestConfig(t), newMemTestCache(t), "1.2.3.4") require.Nil(t, client.Send(visitor, &message{Topic: "mytopic"})) - require.Equal(t, 1, len(sender.messages)) + require.Equal(t, 1, len(sender.Messages())) require.Nil(t, client.Send(visitor, &message{Topic: "mytopic"})) - require.Equal(t, 2, len(sender.messages)) + require.Equal(t, 2, len(sender.Messages())) require.Equal(t, errFirebaseQuotaExceeded, client.Send(visitor, &message{Topic: "mytopic"})) - require.Equal(t, 2, len(sender.messages)) + require.Equal(t, 2, len(sender.Messages())) sender.messages = make([]*messaging.Message, 0) // Reset to test that time limit is working require.Equal(t, errFirebaseQuotaExceeded, client.Send(visitor, &message{Topic: "mytopic"})) - require.Equal(t, 0, len(sender.messages)) + require.Equal(t, 0, len(sender.Messages())) } diff --git a/server/server_test.go b/server/server_test.go index d05075f..ce63f27 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -63,10 +63,10 @@ func TestServer_PublishWithFirebase(t *testing.T) { msg1 := toMessage(t, response.Body.String()) require.NotEmpty(t, msg1.ID) require.Equal(t, "my first message", msg1.Message) - require.Equal(t, 1, len(sender.messages)) - require.Equal(t, "my first message", sender.messages[0].Data["message"]) - require.Equal(t, "my first message", sender.messages[0].APNS.Payload.Aps.Alert.Body) - require.Equal(t, "my first message", sender.messages[0].APNS.Payload.CustomData["message"]) + require.Equal(t, 1, len(sender.Messages())) + require.Equal(t, "my first message", sender.Messages()[0].Data["message"]) + require.Equal(t, "my first message", sender.Messages()[0].APNS.Payload.Aps.Alert.Body) + require.Equal(t, "my first message", sender.Messages()[0].APNS.Payload.CustomData["message"]) } func TestServer_SubscribeOpenAndKeepalive(t *testing.T) {