From f83073b712a0d389492a314eaa01eb7d8d42e94d Mon Sep 17 00:00:00 2001 From: kukymbr Date: Sat, 15 Feb 2025 15:46:46 +0200 Subject: [PATCH 1/2] fix tests for bool returning value --- assertjson/assertjson_test.go | 46 ++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/assertjson/assertjson_test.go b/assertjson/assertjson_test.go index 3d34369..3d52083 100644 --- a/assertjson/assertjson_test.go +++ b/assertjson/assertjson_test.go @@ -2734,17 +2734,6 @@ func TestHas(t *testing.T) { `failed to find JSON node "a.b": [b] not found`, }, }, - // debug helpers - { - name: "print json node", - json: `{"a": {"b": {"c": ["value"]}}}`, - assert: func(json *assertjson.AssertJSON) { - json.Node("a", "b").Print() - }, - wantMessages: []string{ - `JSON node at "a.b"`, - }, - }, // deprecated behaviour: seek by json pointer path { name: "deprecated: json pointer path", @@ -2790,9 +2779,42 @@ func TestHas(t *testing.T) { tester := &mock.Tester{} res := assertjson.Has(tester, []byte(test.json), test.assert) + wantRes := len(test.wantMessages) == 0 + + tester.AssertContains(t, test.wantMessages) + + assert.Equal(t, wantRes, res) + }) + } +} + +func TestPrint(t *testing.T) { + tests := []struct { + name string + json string + assert assertjson.JSONAssertFunc + wantMessages []string + }{ + // debug helpers + { + name: "print json node", + json: `{"a": {"b": {"c": ["value"]}}}`, + assert: func(json *assertjson.AssertJSON) { + json.Node("a", "b").Print() + }, + wantMessages: []string{ + `JSON node at "a.b"`, + }, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + tester := &mock.Tester{} + + assertjson.Has(tester, []byte(test.json), test.assert) tester.AssertContains(t, test.wantMessages) - assert.False(t, res) }) } } From daadc6067a20bc4320f36de53a4e41cfb19f86e1 Mon Sep 17 00:00:00 2001 From: kukymbr Date: Sat, 15 Feb 2025 16:02:41 +0200 Subject: [PATCH 2/2] fix tests for bool returning value --- assertjson/assertjson_test.go | 46 ++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/assertjson/assertjson_test.go b/assertjson/assertjson_test.go index 3d34369..3d52083 100644 --- a/assertjson/assertjson_test.go +++ b/assertjson/assertjson_test.go @@ -2734,17 +2734,6 @@ func TestHas(t *testing.T) { `failed to find JSON node "a.b": [b] not found`, }, }, - // debug helpers - { - name: "print json node", - json: `{"a": {"b": {"c": ["value"]}}}`, - assert: func(json *assertjson.AssertJSON) { - json.Node("a", "b").Print() - }, - wantMessages: []string{ - `JSON node at "a.b"`, - }, - }, // deprecated behaviour: seek by json pointer path { name: "deprecated: json pointer path", @@ -2790,9 +2779,42 @@ func TestHas(t *testing.T) { tester := &mock.Tester{} res := assertjson.Has(tester, []byte(test.json), test.assert) + wantRes := len(test.wantMessages) == 0 + + tester.AssertContains(t, test.wantMessages) + + assert.Equal(t, wantRes, res) + }) + } +} + +func TestPrint(t *testing.T) { + tests := []struct { + name string + json string + assert assertjson.JSONAssertFunc + wantMessages []string + }{ + // debug helpers + { + name: "print json node", + json: `{"a": {"b": {"c": ["value"]}}}`, + assert: func(json *assertjson.AssertJSON) { + json.Node("a", "b").Print() + }, + wantMessages: []string{ + `JSON node at "a.b"`, + }, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + tester := &mock.Tester{} + + assertjson.Has(tester, []byte(test.json), test.assert) tester.AssertContains(t, test.wantMessages) - assert.False(t, res) }) } }