normal jsonp
(t *testing.T)
| 128 | |
| 129 | // normal jsonp |
| 130 | func TestWriteJsonp(t *testing.T) { |
| 131 | param := &InitContextParam{ |
| 132 | t, |
| 133 | &Animal{}, |
| 134 | "", |
| 135 | test.ToDefault, |
| 136 | } |
| 137 | |
| 138 | // init param |
| 139 | context := initResponseContext(param) |
| 140 | |
| 141 | exceptedObject := &Animal{ |
| 142 | "Black", |
| 143 | true, |
| 144 | } |
| 145 | |
| 146 | callback := "jsonCallBack" |
| 147 | |
| 148 | // call function |
| 149 | err := context.WriteJsonp(callback, exceptedObject) |
| 150 | test.Nil(t, err) |
| 151 | |
| 152 | // check result |
| 153 | |
| 154 | // header |
| 155 | contentType := context.response.header.Get(HeaderContentType) |
| 156 | test.Equal(t, MIMEApplicationJavaScriptCharsetUTF8, contentType) |
| 157 | test.Equal(t, defaultHttpCode, context.response.Status) |
| 158 | |
| 159 | // body |
| 160 | body := string(context.response.body) |
| 161 | |
| 162 | animalJson, err := json.Marshal(exceptedObject) |
| 163 | test.Nil(t, err) |
| 164 | |
| 165 | excepted := fmt.Sprint(callback, "(", string(animalJson), ");") |
| 166 | |
| 167 | test.Equal(t, excepted, body) |
| 168 | } |
nothing calls this directly
no test coverage detected