1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

Fixes tests:

- TestClientWithoutPushNotifications: Now expects error instead of nil
- TestClientPushNotificationEdgeCases: Now expects error instead of nil
This commit is contained in:
Nedyalko Dyakov
2025-06-27 16:47:07 +03:00
parent 91805bc506
commit e31987f25e
2 changed files with 20 additions and 9 deletions

View File

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

View File

@ -3,6 +3,7 @@ package redis_test
import (
"context"
"fmt"
"strings"
"testing"
"github.com/redis/go-redis/v9"
@ -207,12 +208,15 @@ func TestClientWithoutPushNotifications(t *testing.T) {
t.Error("VoidPushNotificationProcessor should have nil registry")
}
// Registering handlers should not panic
// Registering handlers should return an error when push notifications are disabled
err := client.RegisterPushNotificationHandler("TEST", newTestHandler(func(ctx context.Context, notification []interface{}) bool {
return true
}), false)
if err != nil {
t.Errorf("Expected nil error when processor is nil, got: %v", err)
if err == nil {
t.Error("Expected error when trying to register handler on client with disabled push notifications")
}
if !strings.Contains(err.Error(), "push notifications are disabled") {
t.Errorf("Expected error message about disabled push notifications, got: %v", err)
}
}
@ -675,19 +679,25 @@ func TestClientPushNotificationEdgeCases(t *testing.T) {
})
defer client.Close()
// These should not panic even when processor is nil and should return nil error
// These should return errors when push notifications are disabled
err := client.RegisterPushNotificationHandler("TEST", newTestHandler(func(ctx context.Context, notification []interface{}) bool {
return true
}), false)
if err != nil {
t.Errorf("Expected nil error when processor is nil, got: %v", err)
if err == nil {
t.Error("Expected error when trying to register handler on client with disabled push notifications")
}
if !strings.Contains(err.Error(), "push notifications are disabled") {
t.Errorf("Expected error message about disabled push notifications, got: %v", err)
}
err = client.RegisterPushNotificationHandler("TEST_FUNC", newTestHandler(func(ctx context.Context, notification []interface{}) bool {
return true
}), false)
if err != nil {
t.Errorf("Expected nil error when processor is nil, got: %v", err)
if err == nil {
t.Error("Expected error when trying to register handler on client with disabled push notifications")
}
if !strings.Contains(err.Error(), "push notifications are disabled") {
t.Errorf("Expected error message about disabled push notifications, got: %v", err)
}
// GetPushNotificationProcessor should return VoidPushNotificationProcessor