Skip to content

Commit

Permalink
plugins/discovery: Update comparison logic for overrides
Browse files Browse the repository at this point in the history
Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
  • Loading branch information
ashutosh-narkar committed Apr 26, 2024
1 parent 2971592 commit bd969f3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugins/discovery/discovery.go
Expand Up @@ -13,6 +13,7 @@ import (
"io"
"os"
"path/filepath"
"reflect"
"strings"
"sync"

Expand Down Expand Up @@ -751,7 +752,7 @@ func mergeValuesAndListOverrides(dest map[string]interface{}, src map[string]int
nextMap, ok := v.(map[string]interface{})
// If it isn't another map, overwrite the value
if !ok {
if dest[k] != v {
if !reflect.DeepEqual(dest[k], v) {
overriddenKeys = append(overriddenKeys, fullKey)
}
dest[k] = v
Expand Down
63 changes: 63 additions & 0 deletions plugins/discovery/discovery_test.go
Expand Up @@ -1988,6 +1988,69 @@ func TestMergeValuesAndListOverrides(t *testing.T) {
},
override: []string{},
},
{
name: "Simple Non-map override -1",
dest: map[string]interface{}{
"a": []interface{}{"bar"},
"b": 2,
},
src: map[string]interface{}{
"a": 3,
},
expected: map[string]interface{}{
"a": 3,
"b": 2,
},
override: []string{"a"},
},
{
name: "Simple Non-map override -2",
dest: map[string]interface{}{
"a": 3,
"b": 2,
},
src: map[string]interface{}{
"a": []interface{}{"bar"},
},
expected: map[string]interface{}{
"a": []interface{}{"bar"},
"b": 2,
},
override: []string{"a"},
},
{
name: "Non-map override -1",
dest: map[string]interface{}{
"a": []interface{}{"bar"},
"b": 2,
},
src: map[string]interface{}{
"a": []string{"foo"},
},
expected: map[string]interface{}{
"a": []string{"foo"},
"b": 2,
},
override: []string{"a"},
},
{
name: "Non-map override -2",
dest: map[string]interface{}{
"a": map[string]interface{}{
"aa": 10,
"ab": 20,
},
"b": 2,
},
src: map[string]interface{}{
"a": []interface{}{"foo"},
},
expected: map[string]interface{}{
"a": []interface{}{"foo"},
"b": 2,
},
override: []string{"a"},
},
{
name: "Simple overridden keys",
dest: map[string]interface{}{
Expand Down

0 comments on commit bd969f3

Please sign in to comment.