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

Function TestMiddlewareNoRoute

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

Source from the content-addressed store, hash-verified

43}
44
45func TestMiddlewareNoRoute(t *testing.T) {
46 signature := ""
47 router := New()
48 router.Use(func(c *Context) {
49 signature += "A"
50 c.Next()
51 signature += "B"
52 })
53 router.Use(func(c *Context) {
54 signature += "C"
55 c.Next()
56 c.Next()
57 c.Next()
58 c.Next()
59 signature += "D"
60 })
61 router.NoRoute(func(c *Context) {
62 signature += "E"
63 c.Next()
64 signature += "F"
65 }, func(c *Context) {
66 signature += "G"
67 c.Next()
68 signature += "H"
69 })
70 router.NoMethod(func(c *Context) {
71 signature += " X "
72 })
73 // RUN
74 w := PerformRequest(router, http.MethodGet, "/")
75
76 // TEST
77 assert.Equal(t, http.StatusNotFound, w.Code)
78 assert.Equal(t, "ACEGHFDB", signature)
79}
80
81func TestMiddlewareNoMethodEnabled(t *testing.T) {
82 signature := ""

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected