Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #49834 upstream release 1.7 #50862

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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.
Expand Down
Expand Up @@ -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
`),
},
},
Expand Down Expand Up @@ -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)
}
}
}

Expand Down