Skip to content

Commit

Permalink
Fix bug where only one list item was being checked
Browse files Browse the repository at this point in the history
Refs:
 - https://issues.redhat.com/browse/ACM-7889

Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
  • Loading branch information
JustinKuli authored and openshift-ci[bot] committed Oct 12, 2023
1 parent 43de3c0 commit eafaef3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions controllers/configurationpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,32 @@ func TestCheckListsMatch(t *testing.T) {

assert.False(t, checkListsMatch(twoFullItems, twoSmallItems))
assert.False(t, checkListsMatch(twoSmallItems, twoFullItems))

oneSmallOneBig := []interface{}{
map[string]interface{}{
"a": "apple",
},
map[string]interface{}{
"c": "candy",
"d": "dog",
},
}

assert.False(t, checkListsMatch(twoFullItems, oneSmallOneBig))
assert.False(t, checkListsMatch(oneSmallOneBig, twoFullItems))

oneBigOneSmall := []interface{}{
map[string]interface{}{
"a": "apple",
"b": "boy",
},
map[string]interface{}{
"c": "candy",
},
}

assert.False(t, checkListsMatch(twoFullItems, oneBigOneSmall))
assert.False(t, checkListsMatch(oneBigOneSmall, twoFullItems))
}

func TestAddRelatedObject(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion controllers/configurationpolicy_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,11 @@ func checkListsMatch(oldVal []interface{}, mergedVal []interface{}) (m bool) {
case map[string]interface{}:
// if list contains maps, recurse on those maps to check for a match
if mVal, ok := mVal[idx].(map[string]interface{}); ok {
return len(mVal) == len(oNestedVal) && checkFieldsWithSort(mVal, oNestedVal)
if len(mVal) != len(oNestedVal) || !checkFieldsWithSort(mVal, oNestedVal) {
return false
}

continue
}

return false
Expand Down

0 comments on commit eafaef3

Please sign in to comment.