json
(t *testing.T)
| 15 | |
| 16 | // json |
| 17 | func 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 |
| 67 | func TestBinder_Bind_json_error(t *testing.T) { |