mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-10-24 11:02:42 +00:00
To mock a handler:
```go
web.RouteMock(web.MockAfterMiddlewares, func(ctx *context.Context) {
// ...
})
defer web.RouteMockReset()
```
It helps:
* Test the middleware's behavior (assert the ctx.Data, etc)
* Mock the middleware's behavior (prepare some context data for handler)
* Mock the handler's response for some test cases, especially for some
integration tests and e2e tests.
|
||
|---|---|---|
| .. | ||
| middleware | ||
| routing | ||
| types | ||
| handler.go | ||
| route.go | ||
| route_test.go | ||
| routemock.go | ||
| routemock_test.go | ||