forked from forgejo/forgejo
[TESTS] testMiddlewareHook, dependency injection in integration tests
(cherry picked from commit6623630d10
) (cherry picked from commitd30b9dc5b4
) (cherry picked from commit8e790a65ba
) (cherry picked from commit9d98ba7e5c
) (cherry picked from commit07fc55a3a7
) (cherry picked from commitf9d054d17f
)
This commit is contained in:
parent
61a3cf77df
commit
c7dc1e1c7f
6 changed files with 28 additions and 19 deletions
|
@ -14,7 +14,6 @@ import (
|
|||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/activitypub"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/routers"
|
||||
|
||||
ap "github.com/go-ap/activitypub"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -22,10 +21,10 @@ import (
|
|||
|
||||
func TestActivityPubPerson(t *testing.T) {
|
||||
setting.Federation.Enabled = true
|
||||
c = routers.NormalRoutes()
|
||||
setNormalRoutes()
|
||||
defer func() {
|
||||
setting.Federation.Enabled = false
|
||||
c = routers.NormalRoutes()
|
||||
setNormalRoutes()
|
||||
}()
|
||||
|
||||
onGiteaRun(t, func(*testing.T, *url.URL) {
|
||||
|
@ -60,10 +59,10 @@ func TestActivityPubPerson(t *testing.T) {
|
|||
|
||||
func TestActivityPubMissingPerson(t *testing.T) {
|
||||
setting.Federation.Enabled = true
|
||||
c = routers.NormalRoutes()
|
||||
setNormalRoutes()
|
||||
defer func() {
|
||||
setting.Federation.Enabled = false
|
||||
c = routers.NormalRoutes()
|
||||
setNormalRoutes()
|
||||
}()
|
||||
|
||||
onGiteaRun(t, func(*testing.T, *url.URL) {
|
||||
|
@ -75,10 +74,10 @@ func TestActivityPubMissingPerson(t *testing.T) {
|
|||
|
||||
func TestActivityPubPersonInbox(t *testing.T) {
|
||||
setting.Federation.Enabled = true
|
||||
c = routers.NormalRoutes()
|
||||
setNormalRoutes()
|
||||
defer func() {
|
||||
setting.Federation.Enabled = false
|
||||
c = routers.NormalRoutes()
|
||||
setNormalRoutes()
|
||||
}()
|
||||
|
||||
srv := httptest.NewServer(c)
|
||||
|
|
|
@ -10,17 +10,16 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/routers"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNodeinfo(t *testing.T) {
|
||||
setting.Federation.Enabled = true
|
||||
c = routers.NormalRoutes()
|
||||
setNormalRoutes()
|
||||
defer func() {
|
||||
setting.Federation.Enabled = false
|
||||
c = routers.NormalRoutes()
|
||||
setNormalRoutes()
|
||||
}()
|
||||
|
||||
onGiteaRun(t, func(*testing.T, *url.URL) {
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/routers"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"gitea.com/go-chi/session"
|
||||
|
@ -56,7 +55,7 @@ func TestSessionFileCreation(t *testing.T) {
|
|||
oldSessionConfig := setting.SessionConfig.ProviderConfig
|
||||
defer func() {
|
||||
setting.SessionConfig.ProviderConfig = oldSessionConfig
|
||||
c = routers.NormalRoutes()
|
||||
setNormalRoutes()
|
||||
}()
|
||||
|
||||
var config session.Options
|
||||
|
@ -75,7 +74,7 @@ func TestSessionFileCreation(t *testing.T) {
|
|||
|
||||
setting.SessionConfig.ProviderConfig = string(newConfigBytes)
|
||||
|
||||
c = routers.NormalRoutes()
|
||||
setNormalRoutes()
|
||||
|
||||
t.Run("NoSessionOnViewIssue", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue