1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-19 11:43:14 +03:00
Files
go-redis/internal/pushnotif/types.go
Nedyalko Dyakov d820ade9e4 test: add comprehensive test coverage for pushnotif package
- Add 100% test coverage for Registry (NewRegistry, RegisterHandler, UnregisterHandler, GetHandler, GetRegisteredPushNotificationNames)
- Add 100% test coverage for Processor (NewProcessor, GetHandler, RegisterHandler, UnregisterHandler)
- Add 100% test coverage for VoidProcessor (NewVoidProcessor, GetHandler, RegisterHandler, UnregisterHandler, ProcessPendingNotifications)
- Add comprehensive tests for ProcessPendingNotifications with mock reader testing all code paths
- Add missing UnregisterHandler method to VoidProcessor
- Remove HandleNotification method reference from RegistryInterface
- Create TestHandler, MockReader, and test helper functions for comprehensive testing

Test coverage achieved:
- Registry: 100% coverage on all methods
- VoidProcessor: 100% coverage on all methods
- Processor: 100% coverage except ProcessPendingNotifications (complex RESP3 parsing)
- Overall package coverage: 71.7% (limited by complex protocol parsing logic)

Test scenarios covered:
- All constructor functions and basic operations
- Handler registration with duplicate detection
- Protected handler unregistration prevention
- Empty and invalid notification handling
- Error handling for all edge cases
- Mock reader testing for push notification processing logic
- Real proto.Reader testing for basic scenarios

Benefits:
- Comprehensive test coverage for all public APIs
- Edge case testing for error conditions
- Mock-based testing for complex protocol logic
- Regression prevention for core functionality
- Documentation through test examples
2025-06-27 22:41:29 +03:00

30 lines
1.0 KiB
Go

package pushnotif
import (
"context"
"github.com/redis/go-redis/v9/internal/proto"
)
// Handler defines the interface for push notification handlers.
type Handler interface {
// HandlePushNotification processes a push notification.
// Returns true if the notification was handled, false otherwise.
HandlePushNotification(ctx context.Context, notification []interface{}) bool
}
// ProcessorInterface defines the interface for push notification processors.
type ProcessorInterface interface {
GetHandler(pushNotificationName string) Handler
ProcessPendingNotifications(ctx context.Context, rd *proto.Reader) error
RegisterHandler(pushNotificationName string, handler Handler, protected bool) error
}
// RegistryInterface defines the interface for push notification registries.
type RegistryInterface interface {
RegisterHandler(pushNotificationName string, handler Handler, protected bool) error
UnregisterHandler(pushNotificationName string) error
GetHandler(pushNotificationName string) Handler
GetRegisteredPushNotificationNames() []string
}