mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #43880 from ymqytw/refactor_SMP
Automatic merge from submit-queue (batch tested with PRs 44097, 42772, 43880, 44031, 44066) Refactor Strategic Merge Patch Refactor Strategic Merge Patch ```release-note None ```
This commit is contained in:
commit
f797abc28d
@ -21,9 +21,23 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrBadJSONDoc = errors.New("Invalid JSON document")
|
var (
|
||||||
var ErrNoListOfLists = errors.New("Lists of lists are not supported")
|
ErrBadJSONDoc = errors.New("Invalid JSON document")
|
||||||
var ErrBadPatchFormatForPrimitiveList = errors.New("Invalid patch format of primitive list")
|
ErrNoListOfLists = errors.New("Lists of lists are not supported")
|
||||||
|
ErrBadPatchFormatForPrimitiveList = errors.New("Invalid patch format of primitive list")
|
||||||
|
)
|
||||||
|
|
||||||
|
func ErrNoMergeKey(m map[string]interface{}, k string) error {
|
||||||
|
return fmt.Errorf("map: %v does not contain declared merge key: %s", m, k)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ErrBadArgType(expected, actual string) error {
|
||||||
|
return fmt.Errorf("expected a %s, but received a %s", expected, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ErrBadPatchType(t interface{}, m map[string]interface{}) error {
|
||||||
|
return fmt.Errorf("unknown patch type: %s in map: %v", t, m)
|
||||||
|
}
|
||||||
|
|
||||||
// IsPreconditionFailed returns true if the provided error indicates
|
// IsPreconditionFailed returns true if the provided error indicates
|
||||||
// a precondition failed.
|
// a precondition failed.
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1998,9 +1998,9 @@ func TestStrategicMergePatch(t *testing.T) {
|
|||||||
testStrategicMergePatchWithCustomArguments(t, "bad patch",
|
testStrategicMergePatchWithCustomArguments(t, "bad patch",
|
||||||
"{}", "<THIS IS NOT JSON>", mergeItem, mergepatch.ErrBadJSONDoc)
|
"{}", "<THIS IS NOT JSON>", mergeItem, mergepatch.ErrBadJSONDoc)
|
||||||
testStrategicMergePatchWithCustomArguments(t, "bad struct",
|
testStrategicMergePatchWithCustomArguments(t, "bad struct",
|
||||||
"{}", "{}", []byte("<THIS IS NOT A STRUCT>"), fmt.Errorf(errBadArgTypeFmt, "struct", "slice"))
|
"{}", "{}", []byte("<THIS IS NOT A STRUCT>"), mergepatch.ErrBadArgType("struct", "slice"))
|
||||||
testStrategicMergePatchWithCustomArguments(t, "nil struct",
|
testStrategicMergePatchWithCustomArguments(t, "nil struct",
|
||||||
"{}", "{}", nil, fmt.Errorf(errBadArgTypeFmt, "struct", "nil"))
|
"{}", "{}", nil, mergepatch.ErrBadArgType("struct", "nil"))
|
||||||
|
|
||||||
tc := StrategicMergePatchTestCases{}
|
tc := StrategicMergePatchTestCases{}
|
||||||
err := yaml.Unmarshal(createStrategicMergePatchTestCaseData, &tc)
|
err := yaml.Unmarshal(createStrategicMergePatchTestCaseData, &tc)
|
||||||
|
Loading…
Reference in New Issue
Block a user