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

Revert "Conform to RFC6902 replacement semantics" for v4.x #111

Merged
merged 4 commits into from
Aug 8, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,13 @@ func (d *partialDoc) add(key string, val *lazyNode) error {
}

func (d *partialDoc) get(key string) (*lazyNode, error) {
v, ok := (*d)[key]
if !ok {
return v, errors.Wrapf(ErrMissing, "unable to get nonexistent key: %s", key)
}
return v, nil
return (*d)[key], nil
}

func (d *partialDoc) remove(key string) error {
_, ok := (*d)[key]
if !ok {
return errors.Wrapf(ErrMissing, "unable to remove nonexistent key: %s", key)
return errors.Wrapf(ErrMissing, "Unable to remove nonexistent key: %s", key)
}

delete(*d, key)
Expand Down Expand Up @@ -624,7 +620,7 @@ func (p Patch) test(doc *container, op Operation) error {
}

val, err := con.get(key)
if err != nil && errors.Cause(err) != ErrMissing {
if err != nil {
return errors.Wrapf(err, "error in test for path: '%s'", path)
}

Expand Down
26 changes: 0 additions & 26 deletions patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ var Cases = []Case{
`[{"op": "copy", "path": "/foo/0", "from": "/foo"}]`,
`{ "foo": [["bar"], "bar"]}`,
},
{
`{ "foo": null}`,
`[{"op": "copy", "path": "/bar", "from": "/foo"}]`,
`{ "foo": null, "bar": null}`,
},
{
`{ "foo": ["bar","qux","baz"]}`,
`[ { "op": "remove", "path": "/foo/-2"}]`,
Expand Down Expand Up @@ -337,15 +332,6 @@ var BadCases = []BadCase{
`{ "foo": [ "all", "grass", "cows", "eat" ] }`,
`[ { "op": "move", "from": "/foo/1", "path": "/foo/4" } ]`,
},
{
`{ "baz": "qux" }`,
`[ { "op": "replace", "path": "/foo", "value": "bar" } ]`,
},
// Can't copy from non-existent "from" key.
{
`{ "foo": "bar"}`,
`[{"op": "copy", "path": "/qux", "from": "/baz"}]`,
},
}

// This is not thread safe, so we cannot run patch tests in parallel.
Expand Down Expand Up @@ -473,18 +459,6 @@ var TestCases = []TestCase{
false,
"/foo",
},
{
`{ "foo": "bar" }`,
`[ { "op": "test", "path": "/baz", "value": "bar" } ]`,
false,
"/baz",
},
{
`{ "foo": "bar" }`,
`[ { "op": "test", "path": "/baz", "value": null } ]`,
true,
"/baz",
},
}

func TestAllTest(t *testing.T) {
Expand Down