Skip to content

Commit

Permalink
added support for domains
Browse files Browse the repository at this point in the history
Signed-off-by: gunishmatta <gunishmatta@gmail.com>
  • Loading branch information
gunishmatta committed Mar 30, 2024
1 parent 9c129d9 commit 8e80626
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion openfeature/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (api *evaluationAPI) initNewAndShutdownOld(newProvider FeatureProvider, old
// It also returns an error if the initialization resulted in an error
func initializer(provider FeatureProvider, apiCtx EvaluationContext) (Event, error) {
var event = Event{
ProviderName: provider.Metadata().Name,
ProviderName: provider.Metadata().Domain,
EventType: ProviderReady,
ProviderEventDetails: ProviderEventDetails{
Message: "Provider initialization successful",
Expand Down
4 changes: 2 additions & 2 deletions openfeature/event_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (e *eventExecutor) emitOnRegistration(

if message != "" {
(*callback)(EventDetails{
ProviderName: providerReference.featureProvider.Metadata().Name,
ProviderName: providerReference.featureProvider.Metadata().Domain,
ProviderEventDetails: ProviderEventDetails{
Message: message,
},
Expand Down Expand Up @@ -290,7 +290,7 @@ func (e *eventExecutor) startListeningAndShutdownOld(newProvider providerReferen
return nil
case <-time.After(200 * time.Millisecond):
return fmt.Errorf("old event handler %s timeout waiting for handler shutdown",
oldReference.featureProvider.Metadata().Name)
oldReference.featureProvider.Metadata().Domain)

Check warning on line 293 in openfeature/event_executor.go

View check run for this annotation

Codecov / codecov/patch

openfeature/event_executor.go#L293

Added line #L293 was not covered by tests
}
}

Expand Down
8 changes: 4 additions & 4 deletions openfeature/event_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestEventHandler_Eventing(t *testing.T) {

// trigger event from provider implementation
eventingImpl.Invoke(Event{
ProviderName: eventingProvider.Metadata().Name,
ProviderName: eventingProvider.Metadata().Domain,
EventType: ProviderReady,
ProviderEventDetails: ProviderEventDetails{
Message: "ReadyMessage",
Expand All @@ -178,8 +178,8 @@ func TestEventHandler_Eventing(t *testing.T) {
t.Fatalf("timeout - event did not trigger")
}

if result.ProviderName != eventingProvider.Metadata().Name {
t.Errorf("expected %s, but got %s", eventingProvider.Metadata().Name, result.ProviderName)
if result.ProviderName != eventingProvider.Metadata().Domain {
t.Errorf("expected %s, but got %s", eventingProvider.Metadata().Domain, result.ProviderName)
}

if result.Message != "ReadyMessage" {
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestEventHandler_clientAssociation(t *testing.T) {

// invoke default provider
eventingImpl.Invoke(Event{
ProviderName: defaultProvider.Metadata().Name,
ProviderName: defaultProvider.Metadata().Domain,
EventType: event,
ProviderEventDetails: ProviderEventDetails{},
})
Expand Down
2 changes: 1 addition & 1 deletion openfeature/memprovider/in_memory_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewInMemoryProvider(from map[string]InMemoryFlag) InMemoryProvider {

func (i InMemoryProvider) Metadata() openfeature.Metadata {
return openfeature.Metadata{
Name: "InMemoryProvider",
Domain: "InMemoryProvider",
}
}

Expand Down
4 changes: 2 additions & 2 deletions openfeature/memprovider/in_memory_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@ func TestInMemoryProvider_Metadata(t *testing.T) {

metadata := memoryProvider.Metadata()

if metadata.Name == "" {
if metadata.Domain == "" {
t.Errorf("expected non-empty name for in-memory provider")
}

if metadata.Name != "InMemoryProvider" {
if metadata.Domain != "InMemoryProvider" {
t.Errorf("incorrect name for in-memory provider")
}
}
2 changes: 1 addition & 1 deletion openfeature/noop_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type NoopProvider struct {

// Metadata returns the metadata of the provider
func (e NoopProvider) Metadata() Metadata {
return Metadata{Name: "NoopProvider"}
return Metadata{Domain: "NoopProvider"}
}

// BooleanEvaluation returns a boolean flag.
Expand Down
2 changes: 1 addition & 1 deletion openfeature/noop_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestNoopProvider_Metadata(t *testing.T) {
want openfeature.Metadata
}{
"Given a NOOP provider, then Metadata() will return NoopProvider": {
want: openfeature.Metadata{Name: "NoopProvider"},
want: openfeature.Metadata{Domain: "NoopProvider"},
},
}
for name, tt := range tests {
Expand Down
26 changes: 13 additions & 13 deletions openfeature/openfeature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestRequirement_1_1_2_1(t *testing.T) {

mockProvider := NewMockFeatureProvider(ctrl)
mockProviderName := "mock-provider"
mockProvider.EXPECT().Metadata().Return(Metadata{Name: mockProviderName}).AnyTimes()
mockProvider.EXPECT().Metadata().Return(Metadata{Domain: mockProviderName}).AnyTimes()

err := SetProvider(mockProvider)
if err != nil {
Expand Down Expand Up @@ -402,10 +402,10 @@ func TestRequirement_1_1_3(t *testing.T) {

ctrl := gomock.NewController(t)
providerA := NewMockFeatureProvider(ctrl)
providerA.EXPECT().Metadata().Return(Metadata{Name: "providerA"}).AnyTimes()
providerA.EXPECT().Metadata().Return(Metadata{Domain: "providerA"}).AnyTimes()

providerB := NewMockFeatureProvider(ctrl)
providerB.EXPECT().Metadata().Return(Metadata{Name: "providerB"}).AnyTimes()
providerB.EXPECT().Metadata().Return(Metadata{Domain: "providerB"}).AnyTimes()

err := SetNamedProvider("clientA", providerA)
if err != nil {
Expand Down Expand Up @@ -436,19 +436,19 @@ func TestRequirement_1_1_3(t *testing.T) {
// Validate provider retrieval by client evaluation. This uses forTransaction("clientName")

provider, _, _ := forTransaction("clientA")
if provider.Metadata().Name != "providerA" {
t.Errorf("expected %s, but got %s", "providerA", providerA.Metadata().Name)
if provider.Metadata().Domain != "providerA" {
t.Errorf("expected %s, but got %s", "providerA", providerA.Metadata().Domain)
}

provider, _, _ = forTransaction("clientB")
if provider.Metadata().Name != "providerB" {
t.Errorf("expected %s, but got %s", "providerB", providerA.Metadata().Name)
if provider.Metadata().Domain != "providerB" {
t.Errorf("expected %s, but got %s", "providerB", providerA.Metadata().Domain)
}

// Validate overriding: If the client-domain already has a bound provider, it is overwritten with the new mapping.

providerB2 := NewMockFeatureProvider(ctrl)
providerB2.EXPECT().Metadata().Return(Metadata{Name: "providerB2"}).AnyTimes()
providerB2.EXPECT().Metadata().Return(Metadata{Domain: "providerB2"}).AnyTimes()

err = SetNamedProvider("clientB", providerB2)
if err != nil {
Expand All @@ -463,8 +463,8 @@ func TestRequirement_1_1_3(t *testing.T) {
// Validate provider retrieval by client evaluation. This uses forTransaction("clientName")

provider, _, _ = forTransaction("clientB")
if provider.Metadata().Name != "providerB2" {
t.Errorf("expected %s, but got %s", "providerB2", providerA.Metadata().Name)
if provider.Metadata().Domain != "providerB2" {
t.Errorf("expected %s, but got %s", "providerB2", providerA.Metadata().Domain)
}
}

Expand Down Expand Up @@ -667,7 +667,7 @@ func TestDefaultClientUsage(t *testing.T) {

ctrl := gomock.NewController(t)
defaultProvider := NewMockFeatureProvider(ctrl)
defaultProvider.EXPECT().Metadata().Return(Metadata{Name: "defaultClientReplacement"}).AnyTimes()
defaultProvider.EXPECT().Metadata().Return(Metadata{Domain: "defaultClientReplacement"}).AnyTimes()

err := SetProvider(defaultProvider)
if err != nil {
Expand All @@ -677,8 +677,8 @@ func TestDefaultClientUsage(t *testing.T) {
// Validate provider retrieval by client evaluation
provider, _, _ := forTransaction("ClientName")

if provider.Metadata().Name != "defaultClientReplacement" {
t.Errorf("expected %s, but got %s", "defaultClientReplacement", provider.Metadata().Name)
if provider.Metadata().Domain != "defaultClientReplacement" {
t.Errorf("expected %s, but got %s", "defaultClientReplacement", provider.Metadata().Domain)
}
}

Expand Down
2 changes: 1 addition & 1 deletion openfeature/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,5 @@ type InterfaceResolutionDetail struct {

// Metadata provides provider domain
type Metadata struct {
Name string
Domain string
}

0 comments on commit 8e80626

Please sign in to comment.