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
@@ -17,8 +17,10 @@ import (
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"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"
|
||||
"github.com/mattermost/mattermost-server/v5/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/mattermost/mattermost-server/v5/store/localcachelayer"
|
||||
@@ -30,6 +32,7 @@ import (
|
||||
|
||||
type TestHelper struct {
|
||||
App *App
|
||||
Context *request.Context
|
||||
Server *Server
|
||||
BasicTeam *model.Team
|
||||
BasicUser *model.User
|
||||
@@ -86,6 +89,7 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
|
||||
|
||||
th := &TestHelper{
|
||||
App: New(ServerConnector(s)),
|
||||
Context: &request.Context{},
|
||||
Server: s,
|
||||
LogBuffer: buffer,
|
||||
IncludeCacheLayer: includeCacheLayer,
|
||||
@@ -119,6 +123,8 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
|
||||
|
||||
if enterprise {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
th.App.Srv().Jobs.InitWorkers()
|
||||
th.App.Srv().Jobs.InitSchedulers()
|
||||
} else {
|
||||
th.App.Srv().SetLicense(nil)
|
||||
}
|
||||
@@ -127,8 +133,6 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
|
||||
th.tempWorkspace = tempWorkspace
|
||||
}
|
||||
|
||||
th.App.InitServer()
|
||||
|
||||
return th
|
||||
}
|
||||
|
||||
@@ -238,7 +242,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()
|
||||
@@ -267,11 +271,11 @@ func (th *TestHelper) CreateUserOrGuest(guest bool) *model.User {
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if guest {
|
||||
if user, err = th.App.CreateGuest(user); err != nil {
|
||||
if user, err = th.App.CreateGuest(th.Context, user); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
if user, err = th.App.CreateUser(user); err != nil {
|
||||
if user, err = th.App.CreateUser(th.Context, user); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -289,7 +293,7 @@ func (th *TestHelper) CreateBot() *model.Bot {
|
||||
OwnerId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
bot, err := th.App.CreateBot(bot)
|
||||
bot, err := th.App.CreateBot(th.Context, bot)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -329,7 +333,7 @@ func (th *TestHelper) createChannel(team *model.Team, channelType string, option
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var appErr *model.AppError
|
||||
if channel, appErr = th.App.CreateChannel(channel, true); appErr != nil {
|
||||
if channel, appErr = th.App.CreateChannel(th.Context, channel, true); appErr != nil {
|
||||
panic(appErr)
|
||||
}
|
||||
|
||||
@@ -357,7 +361,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()
|
||||
@@ -387,7 +391,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()
|
||||
@@ -404,7 +408,7 @@ func (th *TestHelper) CreateMessagePost(channel *model.Channel, message string)
|
||||
|
||||
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()
|
||||
@@ -414,7 +418,7 @@ func (th *TestHelper) CreateMessagePost(channel *model.Channel, message string)
|
||||
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)
|
||||
}
|
||||
@@ -425,7 +429,7 @@ func (th *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) {
|
||||
func (th *TestHelper) RemoveUserFromTeam(user *model.User, team *model.Team) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
err := th.App.RemoveUserFromTeam(team.Id, user.Id, "")
|
||||
err := th.App.RemoveUserFromTeam(th.Context, team.Id, user.Id, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -525,7 +529,7 @@ func (th *TestHelper) CreateEmoji() *model.Emoji {
|
||||
func (th *TestHelper) AddReactionToPost(post *model.Post, user *model.User, emojiName string) *model.Reaction {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
reaction, err := th.App.SaveReactionForPost(&model.Reaction{
|
||||
reaction, err := th.App.SaveReactionForPost(th.Context, &model.Reaction{
|
||||
UserId: user.Id,
|
||||
PostId: post.Id,
|
||||
EmojiName: emojiName,
|
||||
@@ -660,7 +664,7 @@ func (th *TestHelper) SetupPluginAPI() *PluginAPI {
|
||||
Id: "pluginid",
|
||||
}
|
||||
|
||||
return NewPluginAPI(th.App, manifest)
|
||||
return NewPluginAPI(th.App, th.Context, manifest)
|
||||
}
|
||||
|
||||
func (th *TestHelper) RemovePermissionFromRole(permission string, roleName string) {
|
||||
@@ -734,3 +738,7 @@ func NewTestId() string {
|
||||
|
||||
return string(newId)
|
||||
}
|
||||
|
||||
func (th *TestHelper) NewPluginAPI(manifest *model.Manifest) plugin.API {
|
||||
return th.App.NewPluginAPI(th.Context, manifest)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user