normal write
(t *testing.T)
| 16 | |
| 17 | // normal write |
| 18 | func TestWrite(t *testing.T) { |
| 19 | param := &InitContextParam{ |
| 20 | t, |
| 21 | &Animal{}, |
| 22 | "", |
| 23 | test.ToDefault, |
| 24 | } |
| 25 | |
| 26 | // init param |
| 27 | context := initResponseContext(param) |
| 28 | |
| 29 | exceptedObject := &Animal{ |
| 30 | "Black", |
| 31 | true, |
| 32 | } |
| 33 | |
| 34 | animalJson, err := json.Marshal(exceptedObject) |
| 35 | test.Nil(t, err) |
| 36 | |
| 37 | // call function |
| 38 | status := http.StatusNotFound |
| 39 | _, contextErr := context.Write(status, animalJson) |
| 40 | test.Nil(t, contextErr) |
| 41 | |
| 42 | // check result |
| 43 | |
| 44 | // header |
| 45 | contentType := context.response.header.Get(HeaderContentType) |
| 46 | |
| 47 | // check the default value |
| 48 | test.Contains(t, CharsetUTF8, contentType) |
| 49 | test.Equal(t, status, context.response.Status) |
| 50 | |
| 51 | // body |
| 52 | body := string(context.response.body) |
| 53 | |
| 54 | test.Equal(t, string(animalJson), body) |
| 55 | } |
| 56 | |
| 57 | // normal write string |
| 58 | func TestWriteString(t *testing.T) { |