...
1
2
3
4
5 package binding
6
7 import (
8 "testing"
9
10 "github.com/stretchr/testify/assert"
11 "github.com/stretchr/testify/require"
12 )
13
14 func TestJSONBindingBindBody(t *testing.T) {
15 var s struct {
16 Foo string `json:"foo"`
17 }
18 err := jsonBinding{}.BindBody([]byte(`{"foo": "FOO"}`), &s)
19 require.NoError(t, err)
20 assert.Equal(t, "FOO", s.Foo)
21 }
22
23 func TestJSONBindingBindBodyMap(t *testing.T) {
24 s := make(map[string]string)
25 err := jsonBinding{}.BindBody([]byte(`{"foo": "FOO","hello":"world"}`), &s)
26 require.NoError(t, err)
27 assert.Len(t, s, 2)
28 assert.Equal(t, "FOO", s["foo"])
29 assert.Equal(t, "world", s["hello"])
30 }
31
View as plain text