]> source.dussan.org Git - gitea.git/commit
Make route middleware/handler mockable (#25766)
authorwxiaoguang <wxiaoguang@gmail.com>
Sun, 9 Jul 2023 12:25:53 +0000 (20:25 +0800)
committerGitHub <noreply@github.com>
Sun, 9 Jul 2023 12:25:53 +0000 (12:25 +0000)
commit819aed35bff81574920c2a87eddbebed5ddfda1f
tree8a4bb78dc6de7ca05340e972281f5b3fd01a023a
parent887a683af97b570a0fb117068c980f3086133ae4
Make route middleware/handler mockable (#25766)

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.
modules/web/route.go
modules/web/routemock.go [new file with mode: 0644]
modules/web/routemock_test.go [new file with mode: 0644]