Skip to content

Commit f45dba0

Browse files
fix: allow nil value for object evaluation (#118)
fix: allow nil value for object evaluation Signed-off-by: Thomas Poignant <[email protected]>
1 parent 0a7a643 commit f45dba0

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

pkg/openfeature/client.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,8 @@ func (c *Client) evaluate(
639639
evalDetails.Reason = ErrorReason
640640
return evalDetails, err
641641
}
642-
if resolution.Value != nil {
643-
evalDetails.Value = resolution.Value
644-
evalDetails.ResolutionDetail = resolution.ResolutionDetail()
645-
}
642+
evalDetails.Value = resolution.Value
643+
evalDetails.ResolutionDetail = resolution.ResolutionDetail()
646644

647645
if err := c.afterHooks(hookCtx, providerInvocationClientApiHooks, evalDetails, options); err != nil {
648646
c.logger().Error(

pkg/openfeature/client_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,3 +866,46 @@ func TestClientProviderLock(t *testing.T) {
866866
t.Error(err)
867867
}
868868
}
869+
870+
func TestObjectEvaluationShouldSupportNilValue(t *testing.T) {
871+
defer t.Cleanup(initSingleton)
872+
ctrl := gomock.NewController(t)
873+
874+
variant := "variant1"
875+
reason := TargetingMatchReason
876+
var value interface{} = nil
877+
878+
mockProvider := NewMockFeatureProvider(ctrl)
879+
mockProvider.EXPECT().Metadata().AnyTimes()
880+
mockProvider.EXPECT().Hooks().AnyTimes()
881+
SetProvider(mockProvider)
882+
mockProvider.EXPECT().ObjectEvaluation(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
883+
Return(InterfaceResolutionDetail{
884+
Value: value,
885+
ProviderResolutionDetail: ProviderResolutionDetail{
886+
Variant: variant,
887+
Reason: reason,
888+
},
889+
})
890+
891+
client := NewClient("test")
892+
evDetails, err := client.ObjectValueDetails(context.Background(), "foo", nil, EvaluationContext{})
893+
if err != nil {
894+
t.Errorf("should not return an error: %s", err.Error())
895+
}
896+
if evDetails.Value != value {
897+
t.Errorf("unexpected value returned (expected: %s, value: %s)", value, evDetails.Value)
898+
}
899+
if evDetails.Variant != variant {
900+
t.Errorf("unexpected variant returned (expected: %s, value: %s)", variant, evDetails.Variant)
901+
}
902+
if evDetails.Reason != reason {
903+
t.Errorf("unexpected reason returned (expected: %s, value: %s)", reason, evDetails.Reason)
904+
}
905+
if evDetails.ErrorMessage != "" {
906+
t.Error("not supposed to have an error message")
907+
}
908+
if evDetails.ErrorCode != "" {
909+
t.Error("not supposed to have an error code")
910+
}
911+
}

0 commit comments

Comments
 (0)