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
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
|
||||
"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/store/localcachelayer"
|
||||
@@ -15,6 +16,7 @@ import (
|
||||
|
||||
type TestHelper struct {
|
||||
App *app.App
|
||||
Context *request.Context
|
||||
Server *app.Server
|
||||
BasicTeam *model.Team
|
||||
BasicUser *model.User
|
||||
@@ -40,6 +42,7 @@ func setupTestHelper(enterprise bool) *TestHelper {
|
||||
var options []app.Option
|
||||
options = append(options, app.ConfigStore(memoryStore))
|
||||
options = append(options, app.StoreOverride(mainHelper.Store))
|
||||
options = append(options, app.SkipPostInitializiation())
|
||||
|
||||
s, err := app.NewServer(options...)
|
||||
if err != nil {
|
||||
@@ -52,8 +55,9 @@ func setupTestHelper(enterprise bool) *TestHelper {
|
||||
}
|
||||
|
||||
th := &TestHelper{
|
||||
App: app.New(app.ServerConnector(s)),
|
||||
Server: s,
|
||||
App: app.New(app.ServerConnector(s)),
|
||||
Context: &request.Context{},
|
||||
Server: s,
|
||||
}
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
|
||||
@@ -76,6 +80,8 @@ func setupTestHelper(enterprise bool) *TestHelper {
|
||||
|
||||
if enterprise {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
th.App.Srv().Jobs.InitWorkers()
|
||||
th.App.Srv().Jobs.InitSchedulers()
|
||||
} else {
|
||||
th.App.Srv().SetLicense(nil)
|
||||
}
|
||||
@@ -122,7 +128,7 @@ func (th *TestHelper) CreateTeam() *model.Team {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if team, err = th.App.CreateTeam(team); err != nil {
|
||||
if team, err = th.App.CreateTeam(th.Context, team); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
utils.EnableDebugLogForTest()
|
||||
@@ -142,7 +148,7 @@ func (th *TestHelper) CreateUser() *model.User {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if user, err = th.App.CreateUser(user); err != nil {
|
||||
if user, err = th.App.CreateUser(th.Context, user); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
utils.EnableDebugLogForTest()
|
||||
@@ -166,7 +172,7 @@ func (th *TestHelper) createChannel(team *model.Team, channelType string) *model
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if channel, err = th.App.CreateChannel(channel, true); err != nil {
|
||||
if channel, err = th.App.CreateChannel(th.Context, channel, true); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
utils.EnableDebugLogForTest()
|
||||
@@ -177,7 +183,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()
|
||||
@@ -196,7 +202,7 @@ func (th *TestHelper) CreatePost(channel *model.Channel) *model.Post {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if post, err = th.App.CreatePost(post, channel, false, true); err != nil {
|
||||
if post, err = th.App.CreatePost(th.Context, post, channel, false, true); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
utils.EnableDebugLogForTest()
|
||||
@@ -206,7 +212,7 @@ func (th *TestHelper) CreatePost(channel *model.Channel) *model.Post {
|
||||
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