1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

feat: remove GetRegistry from PushNotificationProcessorInterface for better encapsulation

- Remove GetRegistry() method from PushNotificationProcessorInterface
- Enforce use of GetHandler() method for cleaner API design
- Add GetRegistryForTesting() method for test access only
- Update all tests to use new testing helper methods
- Maintain clean separation between public API and internal implementation

Benefits:
- Better encapsulation - no direct registry access from public interface
- Cleaner API - forces use of GetHandler() for specific handler access
- Consistent interface design across all processor types
- Internal registry access only available for testing purposes
- Prevents misuse of registry in production code
This commit is contained in:
Nedyalko Dyakov
2025-06-27 14:31:36 +03:00
parent e6c5590255
commit 03bfd9ffcc
3 changed files with 91 additions and 44 deletions

View File

@ -112,7 +112,6 @@ func (r *PushNotificationRegistry) GetHandler(pushNotificationName string) PushN
// PushNotificationProcessorInterface defines the interface for push notification processors.
type PushNotificationProcessorInterface interface {
GetHandler(pushNotificationName string) PushNotificationHandler
GetRegistry() *PushNotificationRegistry // For backward compatibility and testing
ProcessPendingNotifications(ctx context.Context, rd *proto.Reader) error
RegisterHandler(pushNotificationName string, handler PushNotificationHandler, protected bool) error
}
@ -135,9 +134,9 @@ func (p *PushNotificationProcessor) GetHandler(pushNotificationName string) Push
return p.registry.GetHandler(pushNotificationName)
}
// GetRegistry returns the push notification registry for internal use.
// This method is primarily for testing and internal operations.
func (p *PushNotificationProcessor) GetRegistry() *PushNotificationRegistry {
// GetRegistryForTesting returns the push notification registry for testing.
// This method should only be used by tests.
func (p *PushNotificationProcessor) GetRegistryForTesting() *PushNotificationRegistry {
return p.registry
}
@ -248,8 +247,9 @@ func (v *VoidPushNotificationProcessor) GetHandler(pushNotificationName string)
return nil
}
// GetRegistry returns nil for void processor since it doesn't maintain handlers.
func (v *VoidPushNotificationProcessor) GetRegistry() *PushNotificationRegistry {
// GetRegistryForTesting returns nil for void processor since it doesn't maintain handlers.
// This method should only be used by tests.
func (v *VoidPushNotificationProcessor) GetRegistryForTesting() *PushNotificationRegistry {
return nil
}