Commit 96064570 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #49834 from guoshimin/fixprematurerturn

Automatic merge from submit-queue Fix premature return **What this PR does / why we need it**: Fixes a bug where the loop is prematurely terminated. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #50040 **Special notes for your reviewer**: **Release note**: NONE
parents 0967f956 aa1d47a3
...@@ -1138,7 +1138,7 @@ func mergePatchIntoOriginal(original, patch map[string]interface{}, t reflect.Ty ...@@ -1138,7 +1138,7 @@ func mergePatchIntoOriginal(original, patch map[string]interface{}, t reflect.Ty
return err return err
} }
case !foundOriginal && !foundPatch: case !foundOriginal && !foundPatch:
return nil continue
} }
// Split all items into patch items and server-only items and then enforce the order. // Split all items into patch items and server-only items and then enforce the order.
......
...@@ -5969,6 +5969,75 @@ retainKeysMergingList: ...@@ -5969,6 +5969,75 @@ retainKeysMergingList:
`), `),
}, },
}, },
{
Description: "delete and reorder in one list, reorder in another",
StrategicMergePatchRawTestCaseData: StrategicMergePatchRawTestCaseData{
Original: []byte(`
mergingList:
- name: a
value: a
- name: b
value: b
mergeItemPtr:
- name: c
value: c
- name: d
value: d
`),
Current: []byte(`
mergingList:
- name: a
value: a
- name: b
value: b
mergeItemPtr:
- name: c
value: c
- name: d
value: d
`),
Modified: []byte(`
mergingList:
- name: b
value: b
mergeItemPtr:
- name: d
value: d
- name: c
value: c
`),
TwoWay: []byte(`
$setElementOrder/mergingList:
- name: b
$setElementOrder/mergeItemPtr:
- name: d
- name: c
mergingList:
- $patch: delete
name: a
`),
ThreeWay: []byte(`
$setElementOrder/mergingList:
- name: b
$setElementOrder/mergeItemPtr:
- name: d
- name: c
mergingList:
- $patch: delete
name: a
`),
Result: []byte(`
mergingList:
- name: b
value: b
mergeItemPtr:
- name: d
value: d
- name: c
value: c
`),
},
},
} }
func TestStrategicMergePatch(t *testing.T) { func TestStrategicMergePatch(t *testing.T) {
...@@ -5993,9 +6062,12 @@ func TestStrategicMergePatch(t *testing.T) { ...@@ -5993,9 +6062,12 @@ func TestStrategicMergePatch(t *testing.T) {
testThreeWayPatch(t, c) testThreeWayPatch(t, c)
} }
for _, c := range strategicMergePatchRawTestCases { // run multiple times to exercise different map traversal orders
testTwoWayPatchForRawTestCase(t, c) for i := 0; i < 10; i++ {
testThreeWayPatchForRawTestCase(t, c) for _, c := range strategicMergePatchRawTestCases {
testTwoWayPatchForRawTestCase(t, c)
testThreeWayPatchForRawTestCase(t, c)
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment