mirror of https://github.com/k3s-io/k3s
refactor Strategic Merge Patch
parent
176eb0e509
commit
325f506c5c
|
@ -21,9 +21,23 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
var ErrBadJSONDoc = errors.New("Invalid JSON document")
|
||||
var ErrNoListOfLists = errors.New("Lists of lists are not supported")
|
||||
var ErrBadPatchFormatForPrimitiveList = errors.New("Invalid patch format of primitive list")
|
||||
var (
|
||||
ErrBadJSONDoc = errors.New("Invalid JSON document")
|
||||
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
|
||||
// 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",
|
||||
"{}", "<THIS IS NOT JSON>", mergeItem, mergepatch.ErrBadJSONDoc)
|
||||
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",
|
||||
"{}", "{}", nil, fmt.Errorf(errBadArgTypeFmt, "struct", "nil"))
|
||||
"{}", "{}", nil, mergepatch.ErrBadArgType("struct", "nil"))
|
||||
|
||||
tc := StrategicMergePatchTestCases{}
|
||||
err := yaml.Unmarshal(createStrategicMergePatchTestCaseData, &tc)
|
||||
|
|
Loading…
Reference in New Issue