-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
55 lines (50 loc) · 1.06 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package payload_test
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
"github.com/amarin/payload"
)
func TestExtendJSON(t *testing.T) {
for _, tt := range []struct {
name string
origJSON string
data payload.DataMap
wantResult string
wantErr bool
}{
{
"add_single_key",
payload.EmptyJSONObject,
payload.DataMap{"one": 1},
`{"one":1}`,
false},
{
"add_couple_of_key",
payload.EmptyJSONObject,
payload.DataMap{"one": 1, "two": "два"},
`{"two":"два","one":1}`,
false},
{
"add_empty_map_changes_nothing",
`{"one":1, "two":"два"}`,
payload.DataMap{},
`{"two":"два","one":1}`,
false},
{
"add_nil_map_is_not_error",
`{"one":1, "two":"два"}`,
nil,
`{"two":"два","one":1}`,
false},
} {
t.Run(tt.name, func(t *testing.T) {
gotResult, err := payload.ExtendJSON(json.RawMessage(tt.origJSON), tt.data)
require.Equal(t, err != nil, tt.wantErr)
if err != nil {
return
}
require.JSONEq(t, tt.wantResult, string(gotResult))
})
}
}