@@ -11,6 +11,20 @@ import (
11
11
"github.com/redis/go-redis/v9/internal/proto"
12
12
)
13
13
14
+ // testHandler is a simple implementation of PushNotificationHandler for testing
15
+ type testHandler struct {
16
+ handlerFunc func (ctx context.Context , notification []interface {}) bool
17
+ }
18
+
19
+ func (h * testHandler ) HandlePushNotification (ctx context.Context , notification []interface {}) bool {
20
+ return h .handlerFunc (ctx , notification )
21
+ }
22
+
23
+ // newTestHandler creates a test handler from a function
24
+ func newTestHandler (f func (ctx context.Context , notification []interface {}) bool ) * testHandler {
25
+ return & testHandler {handlerFunc : f }
26
+ }
27
+
14
28
// TestConnectionPoolPushNotificationIntegration tests the connection pool's
15
29
// integration with push notifications for 100% coverage.
16
30
func TestConnectionPoolPushNotificationIntegration (t * testing.T ) {
@@ -102,9 +116,9 @@ func TestConnectionHealthCheckWithPushNotifications(t *testing.T) {
102
116
defer client .Close ()
103
117
104
118
// Register a handler to ensure processor is active
105
- err := client .RegisterPushNotificationHandlerFunc ("TEST_HEALTH" , func (ctx context.Context , notification []interface {}) bool {
119
+ err := client .RegisterPushNotificationHandler ("TEST_HEALTH" , newTestHandler ( func (ctx context.Context , notification []interface {}) bool {
106
120
return true
107
- })
121
+ }))
108
122
if err != nil {
109
123
t .Fatalf ("Failed to register handler: %v" , err )
110
124
}
@@ -147,7 +161,7 @@ func TestConnPushNotificationMethods(t *testing.T) {
147
161
}
148
162
149
163
// Test RegisterPushNotificationHandler
150
- handler := PushNotificationHandlerFunc (func (ctx context.Context , notification []interface {}) bool {
164
+ handler := newTestHandler (func (ctx context.Context , notification []interface {}) bool {
151
165
return true
152
166
})
153
167
@@ -156,10 +170,10 @@ func TestConnPushNotificationMethods(t *testing.T) {
156
170
t .Errorf ("Failed to register handler on Conn: %v" , err )
157
171
}
158
172
159
- // Test RegisterPushNotificationHandlerFunc
160
- err = conn .RegisterPushNotificationHandlerFunc ("TEST_CONN_FUNC" , func (ctx context.Context , notification []interface {}) bool {
173
+ // Test RegisterPushNotificationHandler with function wrapper
174
+ err = conn .RegisterPushNotificationHandler ("TEST_CONN_FUNC" , newTestHandler ( func (ctx context.Context , notification []interface {}) bool {
161
175
return true
162
- })
176
+ }))
163
177
if err != nil {
164
178
t .Errorf ("Failed to register handler func on Conn: %v" , err )
165
179
}
@@ -206,17 +220,17 @@ func TestConnWithoutPushNotifications(t *testing.T) {
206
220
}
207
221
208
222
// Test RegisterPushNotificationHandler returns nil (no error)
209
- err := conn .RegisterPushNotificationHandler ("TEST" , PushNotificationHandlerFunc (func (ctx context.Context , notification []interface {}) bool {
223
+ err := conn .RegisterPushNotificationHandler ("TEST" , newTestHandler (func (ctx context.Context , notification []interface {}) bool {
210
224
return true
211
225
}))
212
226
if err != nil {
213
227
t .Errorf ("Should return nil error when no processor: %v" , err )
214
228
}
215
229
216
- // Test RegisterPushNotificationHandlerFunc returns nil (no error)
217
- err = conn .RegisterPushNotificationHandlerFunc ("TEST" , func (ctx context.Context , notification []interface {}) bool {
230
+ // Test RegisterPushNotificationHandler returns nil (no error)
231
+ err = conn .RegisterPushNotificationHandler ("TEST" , newTestHandler ( func (ctx context.Context , notification []interface {}) bool {
218
232
return true
219
- })
233
+ }))
220
234
if err != nil {
221
235
t .Errorf ("Should return nil error when no processor: %v" , err )
222
236
}
@@ -263,9 +277,9 @@ func TestClonedClientPushNotifications(t *testing.T) {
263
277
}
264
278
265
279
// Register handler on original
266
- err := client .RegisterPushNotificationHandlerFunc ("TEST_CLONE" , func (ctx context.Context , notification []interface {}) bool {
280
+ err := client .RegisterPushNotificationHandler ("TEST_CLONE" , newTestHandler ( func (ctx context.Context , notification []interface {}) bool {
267
281
return true
268
- })
282
+ }))
269
283
if err != nil {
270
284
t .Fatalf ("Failed to register handler: %v" , err )
271
285
}
@@ -289,9 +303,9 @@ func TestClonedClientPushNotifications(t *testing.T) {
289
303
}
290
304
291
305
// Test registering new handler on cloned client
292
- err = clonedClient .RegisterPushNotificationHandlerFunc ("TEST_CLONE_NEW" , func (ctx context.Context , notification []interface {}) bool {
306
+ err = clonedClient .RegisterPushNotificationHandler ("TEST_CLONE_NEW" , newTestHandler ( func (ctx context.Context , notification []interface {}) bool {
293
307
return true
294
- })
308
+ }))
295
309
if err != nil {
296
310
t .Errorf ("Failed to register handler on cloned client: %v" , err )
297
311
}
0 commit comments