Skip to content

Commit

Permalink
fix: Fix nested struct bug (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria authored Nov 22, 2023
1 parent 9c56b9f commit 5fb769f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
28 changes: 26 additions & 2 deletions pkg/provider/provider_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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",
Expand All @@ -222,7 +237,16 @@ func templateResponseWithFlagName(flagName string) resolveResponse {
},
"integer-key": {
"intSchema": {}
}
},
"nested-struct-key": {
"structSchema": {
"schema": {
"nested-boolean-key": {
"boolSchema": {}
}
}
}
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 5fb769f

Please sign in to comment.