[TESTS] testMiddlewareHook, dependency injection in integration tests

(cherry picked from commit 6623630d10)
(cherry picked from commit d30b9dc5b4)
(cherry picked from commit 8e790a65ba)
This commit is contained in:
Earl Warren 2023-06-05 11:04:47 +02:00
parent ef9494ddef
commit 9d98ba7e5c
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")