From 5fb769f3db4c00376ea4e34b510d4391f29003c5 Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Wed, 22 Nov 2023 10:37:22 +0100 Subject: [PATCH] fix: Fix nested struct bug (#37) --- pkg/provider/provider_internal_test.go | 28 ++++++++++++++++++++++++-- pkg/provider/utils.go | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/pkg/provider/provider_internal_test.go b/pkg/provider/provider_internal_test.go index 1462d1e..f3100cc 100644 --- a/pkg/provider/provider_internal_test.go +++ b/pkg/provider/provider_internal_test.go @@ -98,6 +98,18 @@ func TestResolveNestedValue(t *testing.T) { assert.Equal(t, false, evalDetails.Value) } +func TestResolveDoubleNestedValue(t *testing.T) { + client := client(templateResponse(), nil) + attributes := make(map[string]interface{}) + + evalDetails, _ := client.BooleanValueDetails( + context.Background(), "test-flag.struct-key.nested-struct-key.nested-boolean-key", true, openfeature.NewEvaluationContext( + "dennis", + attributes)) + + assert.Equal(t, false, evalDetails.Value) +} + func TestResolveWholeFlagAsObject(t *testing.T) { client := client(templateResponse(), nil) attributes := make(map[string]interface{}) @@ -199,7 +211,10 @@ func templateResponseWithFlagName(flagName string) resolveResponse { "boolean-key": false, "string-key": "treatment-struct", "double-key": 123.23, - "integer-key": 23 + "integer-key": 23, + "nested-struct-key": { + "nested-boolean-key": false + } }, "boolean-key": true, "string-key": "treatment", @@ -222,7 +237,16 @@ func templateResponseWithFlagName(flagName string) resolveResponse { }, "integer-key": { "intSchema": {} - } + }, + "nested-struct-key": { + "structSchema": { + "schema": { + "nested-boolean-key": { + "boolSchema": {} + } + } + } + } } } }, diff --git a/pkg/provider/utils.go b/pkg/provider/utils.go index 8c23d00..08dbb8c 100644 --- a/pkg/provider/utils.go +++ b/pkg/provider/utils.go @@ -163,7 +163,7 @@ func replaceNumbers(basePath string, input map[string]interface{}, return updatedMap, fmt.Errorf("unable to convert map") } - childMap, err := replaceNumbers(fmt.Sprintf("%s.", key), asMap, schema) + childMap, err := replaceNumbers(fmt.Sprintf("%s%s.", basePath, key), asMap, schema) if err != nil { return updatedMap, fmt.Errorf("unable to convert map") }