1
0
Fork 0
forked from forgejo/forgejo

[TESTS] testMiddlewareHook, dependency injection in integration tests

(cherry picked from commit 6623630d10)
(cherry picked from commit d30b9dc5b4)
(cherry picked from commit 8e790a65ba)
(cherry picked from commit 9d98ba7e5c)
(cherry picked from commit 07fc55a3a7)
This commit is contained in:
Earl Warren 2023-06-05 11:04:47 +02:00
parent 94a458835a
commit f9d054d17f
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
6 changed files with 28 additions and 19 deletions

View file

@ -40,7 +40,19 @@ import (
"github.com/xeipuuv/gojsonschema"
)
var c *web.Route
var (
c *web.Route
testMiddlewareHook func(*gitea_context.Context)
)
func setNormalRoutes() {
middlewareHook := func(ctx *gitea_context.Context) {
if testMiddlewareHook != nil {
testMiddlewareHook(ctx)
}
}
c = routers.NormalRoutes(middlewareHook)
}
type NilResponseRecorder struct {
httptest.ResponseRecorder
@ -87,8 +99,7 @@ func TestMain(m *testing.M) {
defer cancel()
tests.InitTest(true)
c = routers.NormalRoutes()
setNormalRoutes()
// integration test settings...
if setting.CfgProvider != nil {
testingCfg := setting.CfgProvider.Section("integration-tests")