Migrate to stateless app.App (#17542)
* add request context * move initialialization to server * use app interface instead of global app functions * remove app context from webconn * cleanup * remove duplicated services * move context to separate package * remove finalize init method and move content to NewServer function * restart workers and schedulers after adding license for tests * reflect review comments Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c09369f14a
Коммит
5ea06e51d0
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/app/request"
|
||||
"github.com/mattermost/mattermost-server/v5/config"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/plugin/plugintest/mock"
|
||||
@@ -41,6 +42,7 @@ type TestHelper struct {
|
||||
Server *app.Server
|
||||
ConfigStore *config.Store
|
||||
|
||||
Context *request.Context
|
||||
Client *model.Client4
|
||||
BasicUser *model.User
|
||||
BasicUser2 *model.User
|
||||
@@ -127,6 +129,11 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
||||
Server: s,
|
||||
ConfigStore: configStore,
|
||||
IncludeCacheLayer: includeCache,
|
||||
Context: &request.Context{},
|
||||
}
|
||||
|
||||
if s.SearchEngine != nil && s.SearchEngine.BleveEngine != nil && searchEngine != nil {
|
||||
searchEngine.BleveEngine = s.SearchEngine.BleveEngine
|
||||
}
|
||||
|
||||
if searchEngine != nil {
|
||||
@@ -158,13 +165,15 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Init(th.Server, th.Server.AppOptions, th.App.Srv().Router)
|
||||
InitLocal(th.Server, th.Server.AppOptions, th.App.Srv().LocalRouter)
|
||||
web.New(th.Server, th.Server.AppOptions, th.App.Srv().Router)
|
||||
Init(th.App, th.App.Srv().Router)
|
||||
InitLocal(th.App, th.App.Srv().LocalRouter)
|
||||
web.New(th.App, th.App.Srv().Router)
|
||||
wsapi.Init(th.App.Srv())
|
||||
|
||||
if enterprise {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
th.App.Srv().Jobs.InitWorkers()
|
||||
th.App.Srv().Jobs.InitSchedulers()
|
||||
} else {
|
||||
th.App.Srv().SetLicense(nil)
|
||||
}
|
||||
@@ -189,8 +198,6 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
||||
th.tempWorkspace = tempWorkspace
|
||||
}
|
||||
|
||||
th.App.InitServer()
|
||||
|
||||
return th
|
||||
}
|
||||
|
||||
@@ -545,7 +552,7 @@ func (th *TestHelper) CreateUserWithAuth(authService string) *model.User {
|
||||
EmailVerified: true,
|
||||
AuthService: authService,
|
||||
}
|
||||
user, err := th.App.CreateUser(user)
|
||||
user, err := th.App.CreateUser(th.Context, user)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -714,7 +721,7 @@ func (th *TestHelper) CreateDmChannel(user *model.User) *model.Channel {
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
var channel *model.Channel
|
||||
if channel, err = th.App.GetOrCreateDirectChannel(th.BasicUser.Id, user.Id); err != nil {
|
||||
if channel, err = th.App.GetOrCreateDirectChannel(th.Context, th.BasicUser.Id, user.Id); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
utils.EnableDebugLogForTest()
|
||||
@@ -789,7 +796,7 @@ func (th *TestHelper) LoginSystemAdminWithClient(client *model.Client4) {
|
||||
func (th *TestHelper) UpdateActiveUser(user *model.User, active bool) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
_, err := th.App.UpdateActive(user, active)
|
||||
_, err := th.App.UpdateActive(th.Context, user, active)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -800,7 +807,7 @@ func (th *TestHelper) UpdateActiveUser(user *model.User, active bool) {
|
||||
func (th *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
_, err := th.App.JoinUserToTeam(team, user, "")
|
||||
_, err := th.App.JoinUserToTeam(th.Context, team, user, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user