|
| 1 | +package jsonhelpers |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/launchdarkly/go-test-helpers/v2/testbox" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +func TestAssertEqual(t *testing.T) { |
| 11 | + AssertEqual(t, `{"a":true,"b":false}`, `{"b":false,"a":true}`) |
| 12 | + |
| 13 | + AssertEqual(t, JValueOf(`{"a":true,"b":false}`), JValueOf(`{"b":false,"a":true}`)) |
| 14 | + |
| 15 | + result := testbox.SandboxTest(func(t testbox.TestingT) { |
| 16 | + AssertEqual(t, `{"a":true,"b":false}`, `{"a":false,"b":false}`) |
| 17 | + }) |
| 18 | + assert.True(t, result.Failed) |
| 19 | + if assert.Len(t, result.Failures, 1) { |
| 20 | + assert.Equal(t, `incorrect JSON value: {"a":false,"b":false} |
| 21 | +at "a": expected = true, actual = false`, result.Failures[0].Message) |
| 22 | + } |
| 23 | + |
| 24 | + result = testbox.SandboxTest(func(t testbox.TestingT) { |
| 25 | + AssertEqual(t, `{"a":true,"b":false}`, `{`) |
| 26 | + }) |
| 27 | + assert.True(t, result.Failed) |
| 28 | + if assert.Len(t, result.Failures, 1) { |
| 29 | + assert.Equal(t, `invalid actual value (JSON unmarshaling error: unexpected end of JSON input): {`, |
| 30 | + result.Failures[0].Message) |
| 31 | + } |
| 32 | + |
| 33 | + result = testbox.SandboxTest(func(t testbox.TestingT) { |
| 34 | + AssertEqual(t, `{`, `{"a":true,"b":false}`) |
| 35 | + }) |
| 36 | + assert.True(t, result.Failed) |
| 37 | + if assert.Len(t, result.Failures, 1) { |
| 38 | + assert.Equal(t, `invalid expected value (JSON unmarshaling error: unexpected end of JSON input): {`, |
| 39 | + result.Failures[0].Message) |
| 40 | + } |
| 41 | +} |
0 commit comments