From db51a898b4941088487a8f172d9bf745ad4fee17 Mon Sep 17 00:00:00 2001 From: Victor Agababov Date: Mon, 24 Aug 2020 10:52:47 -0700 Subject: [PATCH] Add a test to verify #542 is not an issue (#1646) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 🤷 --- apis/duck/patch_test.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/apis/duck/patch_test.go b/apis/duck/patch_test.go index f17dfb4ab..69cda2a50 100644 --- a/apis/duck/patch_test.go +++ b/apis/duck/patch_test.go @@ -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))) } }) }