TestMultipleGroupsWithNotFoundHandle tests multiple groups with different handlers
(t *testing.T)
| 115 | |
| 116 | // TestMultipleGroupsWithNotFoundHandle tests multiple groups with different handlers |
| 117 | func 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 |
| 150 | func TestGroupSetNotFoundHandleReturnsGroup(t *testing.T) { |
nothing calls this directly
no test coverage detected