MCPcopy Create free account
hub / github.com/devfeel/dotweb / TestBinder_Bind_json

Function TestBinder_Bind_json

bind_test.go:17–64  ·  view source on GitHub ↗

json

(t *testing.T)

Source from the content-addressed store, hash-verified

15
16// json
17func TestBinder_Bind_json(t *testing.T) {
18
19 binder := newBinder()
20
21 if binder == nil {
22 t.Error("binder can not be nil!")
23 }
24
25 // init DotServer
26 app := New()
27
28 if app == nil {
29 t.Error("app can not be nil!")
30 }
31
32 // expected
33 expected := &Person{
34 Hair: "Brown",
35 HasGlass: true,
36 Age: 10,
37 Legs: []string{"Left", "Right"},
38 }
39
40 // init param
41 param := &InitContextParam{
42 t,
43 expected,
44 "application/json",
45 test.ToJson,
46 }
47
48 // init param
49 context := initContext(param)
50 // actual
51 person := &Person{}
52
53 err := binder.Bind(person, context)
54
55 // check error must nil
56 test.Nil(t, err)
57
58 // check expected
59 test.Equal(t, expected, person)
60
61 t.Log("person:", person)
62 t.Log("expected:", expected)
63
64}
65
66// json
67func TestBinder_Bind_json_error(t *testing.T) {

Callers

nothing calls this directly

Calls 7

NilFunction · 0.92
EqualFunction · 0.92
newBinderFunction · 0.85
NewFunction · 0.85
initContextFunction · 0.85
ErrorMethod · 0.65
BindMethod · 0.65

Tested by

no test coverage detected