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

Function TestWrap

utils_test.go:40–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestWrap(t *testing.T) {
41 router := New()
42 router.POST("/path", WrapH(&testStruct{t}))
43 router.GET("/path2", WrapF(func(w http.ResponseWriter, req *http.Request) {
44 assert.Equal(t, http.MethodGet, req.Method)
45 assert.Equal(t, "/path2", req.URL.Path)
46 w.WriteHeader(http.StatusBadRequest)
47 fmt.Fprint(w, "hola!")
48 }))
49
50 w := PerformRequest(router, http.MethodPost, "/path")
51 assert.Equal(t, http.StatusInternalServerError, w.Code)
52 assert.Equal(t, "hello", w.Body.String())
53
54 w = PerformRequest(router, http.MethodGet, "/path2")
55 assert.Equal(t, http.StatusBadRequest, w.Code)
56 assert.Equal(t, "hola!", w.Body.String())
57}
58
59func TestLastChar(t *testing.T) {
60 assert.Equal(t, uint8('a'), lastChar("hola"))

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
WrapHFunction · 0.85
WrapFFunction · 0.85
PerformRequestFunction · 0.85
POSTMethod · 0.65
GETMethod · 0.65
StringMethod · 0.65
WriteHeaderMethod · 0.45

Tested by

no test coverage detected