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

Function TestMultipleGroupsWithNotFoundHandle

group_test.go:117–147  ·  view source on GitHub ↗

TestMultipleGroupsWithNotFoundHandle tests multiple groups with different handlers

(t *testing.T)

Source from the content-addressed store, hash-verified

115
116// TestMultipleGroupsWithNotFoundHandle tests multiple groups with different handlers
117func TestMultipleGroupsWithNotFoundHandle(t *testing.T) {
118 app := New()
119
120 // Set global handler
121 app.SetNotFoundHandle(func(ctx Context) {
122 ctx.WriteString("Global 404")
123 })
124
125 // Create API group
126 apiGroup := app.HttpServer.Group("/api")
127 apiGroup.SetNotFoundHandle(func(ctx Context) {
128 ctx.WriteString(`{"code": 404, "message": "API not found"}`)
129 })
130
131 // Create Web group
132 webGroup := app.HttpServer.Group("/web")
133 webGroup.SetNotFoundHandle(func(ctx Context) {
134 ctx.WriteString("<h1>404 - Page Not Found</h1>")
135 })
136
137 // Verify both groups have handlers
138 apiXg := apiGroup.(*xGroup)
139 webXg := webGroup.(*xGroup)
140
141 if apiXg.notFoundHandler == nil {
142 t.Error("API group should have notFoundHandler set")
143 }
144 if webXg.notFoundHandler == nil {
145 t.Error("Web group should have notFoundHandler set")
146 }
147}
148
149// TestGroupSetNotFoundHandleReturnsGroup tests that SetNotFoundHandle returns the Group for chaining
150func TestGroupSetNotFoundHandleReturnsGroup(t *testing.T) {

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
SetNotFoundHandleMethod · 0.65
WriteStringMethod · 0.65
GroupMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected