1
0
Fork 0
forked from forgejo/forgejo

[TESTS] testMiddlewareHook, dependency injection in integration tests

(cherry picked from commit 6623630d10)
(cherry picked from commit 5e30a4f950)
This commit is contained in:
Earl Warren 2023-06-05 11:04:47 +02:00
parent 8bd051e6df
commit 355a117e74
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
6 changed files with 32 additions and 18 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(context.WithValue(context.Background(), web.KeyTestMiddlewareHook, middlewareHook))
}
type NilResponseRecorder struct {
httptest.ResponseRecorder
@ -87,8 +99,7 @@ func TestMain(m *testing.M) {
defer cancel()
tests.InitTest(true)
c = routers.NormalRoutes(context.TODO())
setNormalRoutes()
// integration test settings...
if setting.CfgProvider != nil {
testingCfg := setting.CfgProvider.Section("integration-tests")