(t *testing.T)
| 92 | } |
| 93 | |
| 94 | func TestWriteJson(t *testing.T) { |
| 95 | param := &InitContextParam{ |
| 96 | t, |
| 97 | &Animal{}, |
| 98 | "", |
| 99 | test.ToDefault, |
| 100 | } |
| 101 | |
| 102 | // init param |
| 103 | context := initResponseContext(param) |
| 104 | |
| 105 | exceptedObject := &Animal{ |
| 106 | "Black", |
| 107 | true, |
| 108 | } |
| 109 | |
| 110 | animalJson, err := json.Marshal(exceptedObject) |
| 111 | test.Nil(t, err) |
| 112 | |
| 113 | // call function |
| 114 | contextErr := context.WriteJson(exceptedObject) |
| 115 | test.Nil(t, contextErr) |
| 116 | |
| 117 | // header |
| 118 | contentType := context.response.header.Get(HeaderContentType) |
| 119 | // 因writer中的header方法调用过http.Header默认设置 |
| 120 | test.Equal(t, MIMEApplicationJSONCharsetUTF8, contentType) |
| 121 | test.Equal(t, defaultHttpCode, context.response.Status) |
| 122 | |
| 123 | // body |
| 124 | body := string(context.response.body) |
| 125 | |
| 126 | test.Equal(t, string(animalJson), body) |
| 127 | } |
| 128 | |
| 129 | // normal jsonp |
| 130 | func TestWriteJsonp(t *testing.T) { |
nothing calls this directly
no test coverage detected