Skip to content

Commit

Permalink
support for n nested fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sidhant92 committed Dec 20, 2023
1 parent b261973 commit 62f72a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/util/value_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func GetValueFromMap(key string, data map[string]interface{}) interface{} {
}
nestedMap, ok := value.(map[string]interface{})
if ok {
return GetValueFromMap(keys[1], nestedMap)
newKey := strings.Join(keys[1:], ".")
return GetValueFromMap(newKey, nestedMap)
}
log.Printf("could not find key %s for the data %s", key, data)
return nil
Expand Down
13 changes: 13 additions & 0 deletions pkg/application/boolean_expression_evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ func TestNestedField(t *testing.T) {
assert.True(t, res)
}

func TestTwoNestedField(t *testing.T) {
data := map[string]interface{}{
"person": map[string]interface{}{
"details": map[string]interface{}{
"age": 24,
},
},
}
res, err := evaluator.Evaluate("person.details.age > 20", data)
assert.Nil(t, err)
assert.True(t, res)
}

func TestMissingNestedField(t *testing.T) {
data := map[string]interface{}{
"person": map[string]interface{}{
Expand Down

0 comments on commit 62f72a1

Please sign in to comment.