Remove int support from json patches

This commit is contained in:
Mikhail Mazurskiy 2018-05-08 10:01:44 +10:00
parent e59ae29fbc
commit 433b448e8d
No known key found for this signature in database
GPG Key ID: 93551ECC96E2F568
4 changed files with 32 additions and 34 deletions

View File

@ -136,7 +136,7 @@ func keepOrDeleteNullInObj(m map[string]interface{}, keepNull bool) (map[string]
filteredMap[key] = filteredSubMap filteredMap[key] = filteredSubMap
} }
case []interface{}, string, float64, bool, int, int64, nil: case []interface{}, string, float64, bool, int64, nil:
// Lists are always replaced in Json, no need to check each entry in the list. // Lists are always replaced in Json, no need to check each entry in the list.
if !keepNull { if !keepNull {
filteredMap[key] = val filteredMap[key] = val

View File

@ -125,7 +125,7 @@ func HasConflicts(left, right interface{}) (bool, error) {
default: default:
return true, nil return true, nil
} }
case string, float64, bool, int, int64, nil: case string, float64, bool, int64, nil:
return !reflect.DeepEqual(left, right), nil return !reflect.DeepEqual(left, right), nil
default: default:
return true, fmt.Errorf("unknown type: %v", reflect.TypeOf(left)) return true, fmt.Errorf("unknown type: %v", reflect.TypeOf(left))

View File

@ -30,82 +30,80 @@ func TestHasConflicts(t *testing.T) {
{A: "hello", B: "hello", Ret: false}, {A: "hello", B: "hello", Ret: false},
{A: "hello", B: "hell", Ret: true}, {A: "hello", B: "hell", Ret: true},
{A: "hello", B: nil, Ret: true}, {A: "hello", B: nil, Ret: true},
{A: "hello", B: 1, Ret: true}, {A: "hello", B: int64(1), Ret: true},
{A: "hello", B: float64(1.0), Ret: true}, {A: "hello", B: float64(1.0), Ret: true},
{A: "hello", B: false, Ret: true}, {A: "hello", B: false, Ret: true},
{A: 1, B: 1, Ret: false}, {A: int64(1), B: int64(1), Ret: false},
{A: nil, B: nil, Ret: false}, {A: nil, B: nil, Ret: false},
{A: false, B: false, Ret: false}, {A: false, B: false, Ret: false},
{A: float64(3), B: float64(3), Ret: false}, {A: float64(3), B: float64(3), Ret: false},
{A: "hello", B: []interface{}{}, Ret: true}, {A: "hello", B: []interface{}{}, Ret: true},
{A: []interface{}{1}, B: []interface{}{}, Ret: true}, {A: []interface{}{int64(1)}, B: []interface{}{}, Ret: true},
{A: []interface{}{}, B: []interface{}{}, Ret: false}, {A: []interface{}{}, B: []interface{}{}, Ret: false},
{A: []interface{}{1}, B: []interface{}{1}, Ret: false}, {A: []interface{}{int64(1)}, B: []interface{}{int64(1)}, Ret: false},
{A: map[string]interface{}{}, B: []interface{}{1}, Ret: true}, {A: map[string]interface{}{}, B: []interface{}{int64(1)}, Ret: true},
{A: map[string]interface{}{}, B: map[string]interface{}{"a": 1}, Ret: false}, {A: map[string]interface{}{}, B: map[string]interface{}{"a": int64(1)}, Ret: false},
{A: map[string]interface{}{"a": 1}, B: map[string]interface{}{"a": 1}, Ret: false}, {A: map[string]interface{}{"a": int64(1)}, B: map[string]interface{}{"a": int64(1)}, Ret: false},
{A: map[string]interface{}{"a": 1}, B: map[string]interface{}{"a": 2}, Ret: true}, {A: map[string]interface{}{"a": int64(1)}, B: map[string]interface{}{"a": int64(2)}, Ret: true},
{A: map[string]interface{}{"a": 1}, B: map[string]interface{}{"b": 2}, Ret: false}, {A: map[string]interface{}{"a": int64(1)}, B: map[string]interface{}{"b": int64(2)}, Ret: false},
{ {
A: map[string]interface{}{"a": []interface{}{1}}, A: map[string]interface{}{"a": []interface{}{int64(1)}},
B: map[string]interface{}{"a": []interface{}{1}}, B: map[string]interface{}{"a": []interface{}{int64(1)}},
Ret: false, Ret: false,
}, },
{ {
A: map[string]interface{}{"a": []interface{}{1}}, A: map[string]interface{}{"a": []interface{}{int64(1)}},
B: map[string]interface{}{"a": []interface{}{}}, B: map[string]interface{}{"a": []interface{}{}},
Ret: true, Ret: true,
}, },
{ {
A: map[string]interface{}{"a": []interface{}{1}}, A: map[string]interface{}{"a": []interface{}{int64(1)}},
B: map[string]interface{}{"a": 1}, B: map[string]interface{}{"a": int64(1)},
Ret: true, Ret: true,
}, },
// Maps and lists with multiple entries. // Maps and lists with multiple entries.
{ {
A: map[string]interface{}{"a": 1, "b": 2}, A: map[string]interface{}{"a": int64(1), "b": int64(2)},
B: map[string]interface{}{"a": 1, "b": 0}, B: map[string]interface{}{"a": int64(1), "b": int64(0)},
Ret: true, Ret: true,
}, },
{ {
A: map[string]interface{}{"a": 1, "b": 2}, A: map[string]interface{}{"a": int64(1), "b": int64(2)},
B: map[string]interface{}{"a": 1, "b": 2}, B: map[string]interface{}{"a": int64(1), "b": int64(2)},
Ret: false, Ret: false,
}, },
{ {
A: map[string]interface{}{"a": 1, "b": 2}, A: map[string]interface{}{"a": int64(1), "b": int64(2)},
B: map[string]interface{}{"a": 1, "b": 0, "c": 3}, B: map[string]interface{}{"a": int64(1), "b": int64(0), "c": int64(3)},
Ret: true, Ret: true,
}, },
{ {
A: map[string]interface{}{"a": 1, "b": 2}, A: map[string]interface{}{"a": int64(1), "b": int64(2)},
B: map[string]interface{}{"a": 1, "b": 2, "c": 3}, B: map[string]interface{}{"a": int64(1), "b": int64(2), "c": int64(3)},
Ret: false, Ret: false,
}, },
{ {
A: map[string]interface{}{"a": []interface{}{1, 2}}, A: map[string]interface{}{"a": []interface{}{int64(1), int64(2)}},
B: map[string]interface{}{"a": []interface{}{1, 0}}, B: map[string]interface{}{"a": []interface{}{int64(1), int64(0)}},
Ret: true, Ret: true,
}, },
{ {
A: map[string]interface{}{"a": []interface{}{1, 2}}, A: map[string]interface{}{"a": []interface{}{int64(1), int64(2)}},
B: map[string]interface{}{"a": []interface{}{1, 2}}, B: map[string]interface{}{"a": []interface{}{int64(1), int64(2)}},
Ret: false, Ret: false,
}, },
// Numeric types are not interchangeable. // Numeric types are not interchangeable.
// Callers are expected to ensure numeric types are consistent in 'left' and 'right'. // Callers are expected to ensure numeric types are consistent in 'left' and 'right'.
{A: int(0), B: int64(0), Ret: true},
{A: int(0), B: float64(0), Ret: true},
{A: int64(0), B: float64(0), Ret: true}, {A: int64(0), B: float64(0), Ret: true},
// Other types are not interchangeable. // Other types are not interchangeable.
{A: int(0), B: "0", Ret: true}, {A: int64(0), B: "0", Ret: true},
{A: int(0), B: nil, Ret: true}, {A: int64(0), B: nil, Ret: true},
{A: int(0), B: false, Ret: true}, {A: int64(0), B: false, Ret: true},
{A: "true", B: true, Ret: true}, {A: "true", B: true, Ret: true},
{A: "null", B: nil, Ret: true}, {A: "null", B: nil, Ret: true},
} }

View File

@ -1876,7 +1876,7 @@ func mergingMapFieldsHaveConflicts(
return true, nil return true, nil
} }
return slicesHaveConflicts(leftType, rightType, schema, fieldPatchStrategy, fieldPatchMergeKey) return slicesHaveConflicts(leftType, rightType, schema, fieldPatchStrategy, fieldPatchMergeKey)
case string, float64, bool, int, int64, nil: case string, float64, bool, int64, nil:
return !reflect.DeepEqual(left, right), nil return !reflect.DeepEqual(left, right), nil
default: default:
return true, fmt.Errorf("unknown type: %v", reflect.TypeOf(left)) return true, fmt.Errorf("unknown type: %v", reflect.TypeOf(left))