normal write string
(t *testing.T)
| 56 | |
| 57 | // normal write string |
| 58 | func TestWriteString(t *testing.T) { |
| 59 | param := &InitContextParam{ |
| 60 | t, |
| 61 | &Animal{}, |
| 62 | "", |
| 63 | test.ToDefault, |
| 64 | } |
| 65 | |
| 66 | // init param |
| 67 | context := initResponseContext(param) |
| 68 | |
| 69 | exceptedObject := &Animal{ |
| 70 | "Black", |
| 71 | true, |
| 72 | } |
| 73 | |
| 74 | animalJson, err := json.Marshal(exceptedObject) |
| 75 | test.Nil(t, err) |
| 76 | |
| 77 | // call function |
| 78 | // 这里是一个interface数组,用例需要小心. |
| 79 | contextErr := context.WriteString(string(animalJson)) |
| 80 | test.Nil(t, contextErr) |
| 81 | |
| 82 | // header |
| 83 | contentType := context.response.header.Get(HeaderContentType) |
| 84 | // 因writer中的header方法调用过http.Header默认设置 |
| 85 | test.Contains(t, CharsetUTF8, contentType) |
| 86 | test.Equal(t, defaultHttpCode, context.response.Status) |
| 87 | |
| 88 | // body |
| 89 | body := string(context.response.body) |
| 90 | |
| 91 | test.Equal(t, string(animalJson), body) |
| 92 | } |
| 93 | |
| 94 | func TestWriteJson(t *testing.T) { |
| 95 | param := &InitContextParam{ |
nothing calls this directly
no test coverage detected