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
This commit is contained in:
Kubernetes Submit Queue 2017-08-07 18:26:29 -07:00 committed by GitHub
commit 96064570d2
2 changed files with 76 additions and 4 deletions

View File

@ -1138,7 +1138,7 @@ func mergePatchIntoOriginal(original, patch map[string]interface{}, t reflect.Ty
return err
}
case !foundOriginal && !foundPatch:
return nil
continue
}
// Split all items into patch items and server-only items and then enforce the order.

View File

@ -5966,6 +5966,75 @@ retainKeysMergingList:
retainKeysMergingList:
- name: bar
- name: foo
`),
},
},
{
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
`),
},
},
@ -5993,9 +6062,12 @@ func TestStrategicMergePatch(t *testing.T) {
testThreeWayPatch(t, c)
}
for _, c := range strategicMergePatchRawTestCases {
testTwoWayPatchForRawTestCase(t, c)
testThreeWayPatchForRawTestCase(t, c)
// run multiple times to exercise different map traversal orders
for i := 0; i < 10; i++ {
for _, c := range strategicMergePatchRawTestCases {
testTwoWayPatchForRawTestCase(t, c)
testThreeWayPatchForRawTestCase(t, c)
}
}
}