Skip to content

Commit e31987f

Browse files
committed
Fixes tests:
- TestClientWithoutPushNotifications: Now expects error instead of nil - TestClientPushNotificationEdgeCases: Now expects error instead of nil
1 parent 91805bc commit e31987f

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

internal/pushnotif/processor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ func (v *VoidProcessor) GetHandler(pushNotificationName string) Handler {
103103
}
104104

105105
// RegisterHandler returns an error for void processor since it doesn't maintain handlers.
106+
// This helps developers identify when they're trying to register handlers on disabled push notifications.
106107
func (v *VoidProcessor) RegisterHandler(pushNotificationName string, handler Handler, protected bool) error {
107-
return fmt.Errorf("void push notification processor does not support handler registration")
108+
return fmt.Errorf("cannot register push notification handler '%s': push notifications are disabled (using void processor)", pushNotificationName)
108109
}
109110

110111
// GetRegistryForTesting returns nil for void processor since it doesn't maintain handlers.

push_notifications_test.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package redis_test
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"testing"
78

89
"github.com/redis/go-redis/v9"
@@ -207,12 +208,15 @@ func TestClientWithoutPushNotifications(t *testing.T) {
207208
t.Error("VoidPushNotificationProcessor should have nil registry")
208209
}
209210

210-
// Registering handlers should not panic
211+
// Registering handlers should return an error when push notifications are disabled
211212
err := client.RegisterPushNotificationHandler("TEST", newTestHandler(func(ctx context.Context, notification []interface{}) bool {
212213
return true
213214
}), false)
214-
if err != nil {
215-
t.Errorf("Expected nil error when processor is nil, got: %v", err)
215+
if err == nil {
216+
t.Error("Expected error when trying to register handler on client with disabled push notifications")
217+
}
218+
if !strings.Contains(err.Error(), "push notifications are disabled") {
219+
t.Errorf("Expected error message about disabled push notifications, got: %v", err)
216220
}
217221
}
218222

@@ -675,19 +679,25 @@ func TestClientPushNotificationEdgeCases(t *testing.T) {
675679
})
676680
defer client.Close()
677681

678-
// These should not panic even when processor is nil and should return nil error
682+
// These should return errors when push notifications are disabled
679683
err := client.RegisterPushNotificationHandler("TEST", newTestHandler(func(ctx context.Context, notification []interface{}) bool {
680684
return true
681685
}), false)
682-
if err != nil {
683-
t.Errorf("Expected nil error when processor is nil, got: %v", err)
686+
if err == nil {
687+
t.Error("Expected error when trying to register handler on client with disabled push notifications")
688+
}
689+
if !strings.Contains(err.Error(), "push notifications are disabled") {
690+
t.Errorf("Expected error message about disabled push notifications, got: %v", err)
684691
}
685692

686693
err = client.RegisterPushNotificationHandler("TEST_FUNC", newTestHandler(func(ctx context.Context, notification []interface{}) bool {
687694
return true
688695
}), false)
689-
if err != nil {
690-
t.Errorf("Expected nil error when processor is nil, got: %v", err)
696+
if err == nil {
697+
t.Error("Expected error when trying to register handler on client with disabled push notifications")
698+
}
699+
if !strings.Contains(err.Error(), "push notifications are disabled") {
700+
t.Errorf("Expected error message about disabled push notifications, got: %v", err)
691701
}
692702

693703
// GetPushNotificationProcessor should return VoidPushNotificationProcessor

0 commit comments

Comments
 (0)