MCPcopy Create free account
hub / github.com/devfeel/dotweb / TestWriteJson

Function TestWriteJson

context_test.go:94–127  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

92}
93
94func 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
130func TestWriteJsonp(t *testing.T) {

Callers

nothing calls this directly

Calls 5

NilFunction · 0.92
EqualFunction · 0.92
initResponseContextFunction · 0.85
WriteJsonMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected