make StrategicPatch delete all matching maps in a merging list

This commit is contained in:
ymqytw 2016-12-07 16:44:36 -08:00
parent 8ef6902516
commit 03081a0003
2 changed files with 28 additions and 5 deletions

View File

@ -656,12 +656,16 @@ func mergeSlice(original, patch []interface{}, elemType reflect.Type, mergeKey s
if patchType == deleteDirective {
mergeValue, ok := typedV[mergeKey]
if ok {
_, originalKey, found, err := findMapInSliceBasedOnKeyValue(original, mergeKey, mergeValue)
if err != nil {
return nil, err
}
// delete all matching entries (based on merge key) from a merging list
for {
_, originalKey, found, err := findMapInSliceBasedOnKeyValue(original, mergeKey, mergeValue)
if err != nil {
return nil, err
}
if found {
if !found {
break
}
// Delete the element at originalKey.
original = append(original[:originalKey], original[originalKey+1:]...)
}

View File

@ -308,6 +308,25 @@ testCases:
$patch: replace
modified:
other: a
- description: delete all duplicate entries in a merging list
original:
mergingList:
- name: 1
- name: 1
- name: 2
value: a
- name: 3
- name: 3
twoWay:
mergingList:
- name: 1
$patch: delete
- name: 3
$patch: delete
modified:
mergingList:
- name: 2
value: a
`)
func TestCustomStrategicMergePatch(t *testing.T) {