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

Function TestMiddlewareNoMethodEnabled

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

Source from the content-addressed store, hash-verified

79}
80
81func TestMiddlewareNoMethodEnabled(t *testing.T) {
82 signature := ""
83 router := New()
84 router.HandleMethodNotAllowed = true
85 router.Use(func(c *Context) {
86 signature += "A"
87 c.Next()
88 signature += "B"
89 })
90 router.Use(func(c *Context) {
91 signature += "C"
92 c.Next()
93 signature += "D"
94 })
95 router.NoMethod(func(c *Context) {
96 signature += "E"
97 c.Next()
98 signature += "F"
99 }, func(c *Context) {
100 signature += "G"
101 c.Next()
102 signature += "H"
103 })
104 router.NoRoute(func(c *Context) {
105 signature += " X "
106 })
107 router.POST("/", func(c *Context) {
108 signature += " XX "
109 })
110 // RUN
111 w := PerformRequest(router, http.MethodGet, "/")
112
113 // TEST
114 assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
115 assert.Equal(t, "ACEGHFDB", signature)
116}
117
118func TestMiddlewareNoMethodDisabled(t *testing.T) {
119 signature := ""

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
PerformRequestFunction · 0.85
NextMethod · 0.80
NoMethodMethod · 0.80
NoRouteMethod · 0.80
UseMethod · 0.65
POSTMethod · 0.65

Tested by

no test coverage detected