Skip to content

Commit

Permalink
Fix adding appended list directly causing changing previous value
Browse files Browse the repository at this point in the history
* Added new unit test to cover this case, original this test case would fail.
  • Loading branch information
yongxiu committed Nov 16, 2021
1 parent 536feb4 commit d5f7500
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ func paths(path []string, diff map[string]interface{}) [][]string {
for key, m := range diff {
nested, ok := m.(map[string]interface{})
if !ok {
allPaths = append(allPaths, append(path, key))
tmp := make([]string, len(path))
copy(tmp, path)
allPaths = append(allPaths, append(tmp, key))
continue
}
allPaths = append(allPaths, paths(append(path, key), nested)...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,23 @@ func TestPaths(t *testing.T) {
diff: map[string]interface{}{},
expected: [][]string{},
},
{
name: "long recursive check with two keys",
diff: map[string]interface{}{
"spec": map[string]interface{}{
"kubeadmConfigSpec": map[string]interface{}{
"clusterConfiguration": map[string]interface{}{
"version": "v2.0.1",
"abc": "d",
},
},
},
},
expected: [][]string{
{"spec", "kubeadmConfigSpec", "clusterConfiguration", "version"},
{"spec", "kubeadmConfigSpec", "clusterConfiguration", "abc"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit d5f7500

Please sign in to comment.