Add a test to verify #542 is not an issue (#1646)

Reading #542 I see we miss a test for that use case.
So I added one and the test passes as expected.
Perhaps there was a bug in the jsonpatch library we're using at the time
🤷
This commit is contained in:
Victor Agababov 2020-08-24 10:52:47 -07:00 committed by GitHub
parent 8ae0132790
commit db51a898b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 3 deletions

View File

@ -70,7 +70,7 @@ func TestCreateMergePatch(t *testing.T) {
},
want: []byte(`{"status":{"patchable":{"field1":42,"field2":null}}}`),
}, {
name: "patch array",
name: "patch slice bigger",
before: &Patch{
Spec: PatchSpec{
Patchable: &Patchable{
@ -86,6 +86,23 @@ func TestCreateMergePatch(t *testing.T) {
},
},
want: []byte(`{"status":{"patchable":{"array":["foo","bar","baz"]}}}`),
}, {
name: "patch array smaller",
before: &Patch{
Spec: PatchSpec{
Patchable: &Patchable{
Array: []string{"foo", "bar", "baz", "jimmy"},
},
},
},
after: &Patch{
Spec: PatchSpec{
Patchable: &Patchable{
Array: []string{"foo", "baz"},
},
},
},
want: []byte(`{"status":{"patchable":{"array":["foo","baz"]}}}`),
}, {
name: "before doesn't marshal",
before: &DoesntMarshal{},
@ -111,8 +128,8 @@ func TestCreateMergePatch(t *testing.T) {
return
}
if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("CreatePatch (-want, +got) = %v, %s", diff, got)
if !cmp.Equal(test.want, got) {
t.Errorf("CreatePatch = ->%s<-, diff: (-want, +got) =\n%s", string(got), cmp.Diff(string(test.want), string(got)))
}
})
}