Skip to content

Commit

Permalink
Fix getValue function when map is empty (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 authored Apr 24, 2023
1 parent 63e3ee9 commit 7a4b08b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/factsengine/entities/fact_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func getValue(fact FactValue, values []string) (FactValue, error) {
}
return getValue(value.Value[listIndex], values[1:])
default:
return value, nil
return nil, fmt.Errorf("requested field value not found")
}
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/factsengine/entities/fact_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (suite *FactValueTestSuite) TestFactValueMapGetValue() {
"value": &entities.FactValueString{Value: "other_value"},
},
},
"empty_entry": &entities.FactValueString{},
},
}

Expand Down Expand Up @@ -252,6 +253,15 @@ func (suite *FactValueTestSuite) TestFactValueMapGetValue() {
Message: "error getting value: requested field value not found: map_value.other_value",
},
},
{
description: "Should return ValueNotFoundError when value does not exist because the entry is empty",
key: "empty_entry.some_value",
expected: nil,
err: &entities.FactGatheringError{
Type: "value-not-found",
Message: "error getting value: requested field value not found: empty_entry.some_value",
},
},
{
description: "Should return ValueNotFoundError when given list index does not exist",
key: "list_value.3",
Expand Down

0 comments on commit 7a4b08b

Please sign in to comment.