Skip to content

Commit

Permalink
make scopedCallback internal
Browse files Browse the repository at this point in the history
Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
  • Loading branch information
Kavindu-Dodan committed May 8, 2024
1 parent e5fc666 commit 64f0598
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
22 changes: 9 additions & 13 deletions openfeature/event_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type eventingImpl interface {
IEventing
GetAPIRegistry() map[EventType][]EventCallback
GetClientRegistry(client string) ScopedCallback
GetClientRegistry(client string) scopedCallback

clientEvent
}
Expand All @@ -36,7 +36,7 @@ type eventExecutor struct {
namedProviderReference map[string]providerReference
activeSubscriptions []providerReference
apiRegistry map[EventType][]EventCallback
scopedRegistry map[string]ScopedCallback
scopedRegistry map[string]scopedCallback
logger logr.Logger
eventChan chan eventPayload
once sync.Once
Expand All @@ -48,7 +48,7 @@ func newEventExecutor(logger logr.Logger) *eventExecutor {
namedProviderReference: map[string]providerReference{},
activeSubscriptions: []providerReference{},
apiRegistry: map[EventType][]EventCallback{},
scopedRegistry: map[string]ScopedCallback{},
scopedRegistry: map[string]scopedCallback{},
logger: logger,
eventChan: make(chan eventPayload, 5),
}
Expand All @@ -57,23 +57,19 @@ func newEventExecutor(logger logr.Logger) *eventExecutor {
return &executor
}

// ScopedCallback is a helper struct to hold client name associated callbacks.
// scopedCallback is a helper struct to hold client name associated callbacks.
// Here, the scope correlates to the client and provider name
type ScopedCallback struct {
type scopedCallback struct {
scope string
callbacks map[EventType][]EventCallback
}

func (s *ScopedCallback) Callbacks() map[EventType][]EventCallback {
func (s *scopedCallback) eventCallbacks() map[EventType][]EventCallback {
return s.callbacks
}

func (s *ScopedCallback) Scope() string {
return s.scope
}

func newScopedCallback(client string) ScopedCallback {
return ScopedCallback{
func newScopedCallback(client string) scopedCallback {
return scopedCallback{
scope: client,
callbacks: map[EventType][]EventCallback{},
}
Expand Down Expand Up @@ -190,7 +186,7 @@ func (e *eventExecutor) GetAPIRegistry() map[EventType][]EventCallback {
return e.apiRegistry
}

func (e *eventExecutor) GetClientRegistry(client string) ScopedCallback {
func (e *eventExecutor) GetClientRegistry(client string) scopedCallback {
return e.scopedRegistry[client]
}

Expand Down
16 changes: 8 additions & 8 deletions openfeature/openfeature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,19 +604,19 @@ func TestRequirement_EventCompliance(t *testing.T) {

registry := eventing.GetClientRegistry(clientName)

if len(registry.Callbacks()[ProviderReady]) < 1 {
if len(registry.eventCallbacks()[ProviderReady]) < 1 {
t.Errorf("expected a registry regiration, but got none")
}

if len(registry.Callbacks()[ProviderError]) < 1 {
if len(registry.eventCallbacks()[ProviderError]) < 1 {
t.Errorf("expected a registry regiration, but got none")
}

if len(registry.Callbacks()[ProviderStale]) < 1 {
if len(registry.eventCallbacks()[ProviderStale]) < 1 {
t.Errorf("expected a registry regiration, but got none")
}

if len(registry.Callbacks()[ProviderConfigChange]) < 1 {
if len(registry.eventCallbacks()[ProviderConfigChange]) < 1 {
t.Errorf("expected a registry regiration, but got none")
}

Expand All @@ -626,19 +626,19 @@ func TestRequirement_EventCompliance(t *testing.T) {
client.RemoveHandler(ProviderStale, &h1)
client.RemoveHandler(ProviderConfigChange, &h1)

if len(registry.Callbacks()[ProviderReady]) > 0 {
if len(registry.eventCallbacks()[ProviderReady]) > 0 {
t.Errorf("expected empty registrations")
}

if len(registry.Callbacks()[ProviderError]) > 0 {
if len(registry.eventCallbacks()[ProviderError]) > 0 {
t.Errorf("expected empty registrations")
}

if len(registry.Callbacks()[ProviderStale]) > 0 {
if len(registry.eventCallbacks()[ProviderStale]) > 0 {
t.Errorf("expected empty registrations")
}

if len(registry.Callbacks()[ProviderConfigChange]) > 0 {
if len(registry.eventCallbacks()[ProviderConfigChange]) > 0 {
t.Errorf("expected empty registrations")
}
})
Expand Down

0 comments on commit 64f0598

Please sign in to comment.