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

Function TestWriteJsonp

context_test.go:130–168  ·  view source on GitHub ↗

normal jsonp

(t *testing.T)

Source from the content-addressed store, hash-verified

128
129// normal jsonp
130func 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}

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected