MCPcopy
hub / github.com/gin-gonic/gin / TestMiddlewareWrite

Function TestMiddlewareWrite

middleware_test.go:229–253  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

227}
228
229func TestMiddlewareWrite(t *testing.T) {
230 router := New()
231 router.Use(func(c *Context) {
232 c.String(http.StatusBadRequest, "hola\n")
233 })
234 router.Use(func(c *Context) {
235 c.XML(http.StatusBadRequest, H{"foo": "bar"})
236 })
237 router.Use(func(c *Context) {
238 c.JSON(http.StatusBadRequest, H{"foo": "bar"})
239 })
240 router.GET("/", func(c *Context) {
241 c.JSON(http.StatusBadRequest, H{"foo": "bar"})
242 }, func(c *Context) {
243 c.Render(http.StatusBadRequest, sse.Event{
244 Event: "test",
245 Data: "message",
246 })
247 })
248
249 w := PerformRequest(router, http.MethodGet, "/")
250
251 assert.Equal(t, http.StatusBadRequest, w.Code)
252 assert.Equal(t, strings.ReplaceAll("hola\n<map><foo>bar</foo></map>{\"foo\":\"bar\"}{\"foo\":\"bar\"}event:test\ndata:message\n\n", " ", ""), strings.ReplaceAll(w.Body.String(), " ", ""))
253}

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
PerformRequestFunction · 0.85
XMLMethod · 0.80
UseMethod · 0.65
StringMethod · 0.65
GETMethod · 0.65
RenderMethod · 0.65
JSONMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…