fix plugin test (#7436)
* fix plugin test * ugh. global state * Fix plugin test * Fix TestDeleteChannel * Remove plugin config listener when shutting down
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
b066b6df13
Коммит
4731b8f9b9
@@ -46,9 +46,6 @@ func setupTestHelper(enterprise bool) *TestHelper {
|
|||||||
*utils.Cfg.RateLimitSettings.Enable = false
|
*utils.Cfg.RateLimitSettings.Enable = false
|
||||||
utils.Cfg.EmailSettings.SendEmailNotifications = true
|
utils.Cfg.EmailSettings.SendEmailNotifications = true
|
||||||
utils.DisableDebugLogForTest()
|
utils.DisableDebugLogForTest()
|
||||||
if enterprise {
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
}
|
|
||||||
th.App.NewServer()
|
th.App.NewServer()
|
||||||
th.App.InitStores()
|
th.App.InitStores()
|
||||||
th.App.Srv.Router = NewRouter()
|
th.App.Srv.Router = NewRouter()
|
||||||
@@ -63,6 +60,11 @@ func setupTestHelper(enterprise bool) *TestHelper {
|
|||||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utils.SetIsLicensed(enterprise)
|
||||||
|
if enterprise {
|
||||||
|
utils.License().Features.SetDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
return th
|
return th
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,9 +58,6 @@ func setupTestHelper(enterprise bool) *TestHelper {
|
|||||||
*utils.Cfg.RateLimitSettings.Enable = false
|
*utils.Cfg.RateLimitSettings.Enable = false
|
||||||
utils.Cfg.EmailSettings.SendEmailNotifications = true
|
utils.Cfg.EmailSettings.SendEmailNotifications = true
|
||||||
utils.DisableDebugLogForTest()
|
utils.DisableDebugLogForTest()
|
||||||
if enterprise {
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
}
|
|
||||||
th.App.NewServer()
|
th.App.NewServer()
|
||||||
th.App.InitStores()
|
th.App.InitStores()
|
||||||
th.App.Srv.Router = NewRouter()
|
th.App.Srv.Router = NewRouter()
|
||||||
@@ -74,6 +71,11 @@ func setupTestHelper(enterprise bool) *TestHelper {
|
|||||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utils.SetIsLicensed(enterprise)
|
||||||
|
if enterprise {
|
||||||
|
utils.License().Features.SetDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
if jobs.Srv.Store == nil {
|
if jobs.Srv.Store == nil {
|
||||||
jobs.Srv.Store = th.App.Srv.Store
|
jobs.Srv.Store = th.App.Srv.Store
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -876,6 +876,8 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
_, resp = th.SystemAdminClient.DeleteChannel(publicChannel5.Id)
|
_, resp = th.SystemAdminClient.DeleteChannel(publicChannel5.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
th = Setup().InitBasic().InitSystemAdmin()
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
isLicensed := utils.IsLicensed()
|
||||||
license := utils.License()
|
license := utils.License()
|
||||||
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
|
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
|
||||||
@@ -894,7 +896,6 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
utils.License().Features.SetDefaults()
|
utils.License().Features.SetDefaults()
|
||||||
utils.SetDefaultRolesBasedOnConfig()
|
utils.SetDefaultRolesBasedOnConfig()
|
||||||
|
|
||||||
th = Setup().InitBasic().InitSystemAdmin()
|
|
||||||
Client = th.Client
|
Client = th.Client
|
||||||
team = th.BasicTeam
|
team = th.BasicTeam
|
||||||
user = th.BasicUser
|
user = th.BasicUser
|
||||||
|
|||||||
@@ -26,17 +26,21 @@ func TestPlugin(t *testing.T) {
|
|||||||
os.RemoveAll(webappDir)
|
os.RemoveAll(webappDir)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
th := Setup().InitBasic().InitSystemAdmin()
|
th := SetupEnterprise().InitBasic().InitSystemAdmin()
|
||||||
defer TearDown()
|
defer TearDown()
|
||||||
|
|
||||||
th.App.InitPlugins(pluginDir, webappDir)
|
|
||||||
|
|
||||||
enablePlugins := *utils.Cfg.PluginSettings.Enable
|
enablePlugins := *utils.Cfg.PluginSettings.Enable
|
||||||
defer func() {
|
defer func() {
|
||||||
*utils.Cfg.PluginSettings.Enable = enablePlugins
|
*utils.Cfg.PluginSettings.Enable = enablePlugins
|
||||||
}()
|
}()
|
||||||
*utils.Cfg.PluginSettings.Enable = true
|
*utils.Cfg.PluginSettings.Enable = true
|
||||||
|
|
||||||
|
th.App.InitPlugins(pluginDir, webappDir)
|
||||||
|
defer func() {
|
||||||
|
th.App.ShutDownPlugins()
|
||||||
|
th.App.PluginEnv = nil
|
||||||
|
}()
|
||||||
|
|
||||||
path, _ := utils.FindDir("tests")
|
path, _ := utils.FindDir("tests")
|
||||||
file, err := os.Open(path + "/testplugin.tar.gz")
|
file, err := os.Open(path + "/testplugin.tar.gz")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -108,7 +112,5 @@ func TestPlugin(t *testing.T) {
|
|||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
|
|
||||||
_, resp = th.SystemAdminClient.RemovePlugin("bad.id")
|
_, resp = th.SystemAdminClient.RemovePlugin("bad.id")
|
||||||
CheckNotFoundStatus(t, resp)
|
CheckBadRequestStatus(t, resp)
|
||||||
|
|
||||||
th.App.PluginEnv = nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
Srv *Server
|
Srv *Server
|
||||||
PluginEnv *pluginenv.Environment
|
PluginEnv *pluginenv.Environment
|
||||||
|
PluginConfigListenerId string
|
||||||
}
|
}
|
||||||
|
|
||||||
var globalApp App
|
var globalApp App
|
||||||
|
|||||||
@@ -33,9 +33,6 @@ func setupTestHelper(enterprise bool) *TestHelper {
|
|||||||
*utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
*utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
||||||
*utils.Cfg.RateLimitSettings.Enable = false
|
*utils.Cfg.RateLimitSettings.Enable = false
|
||||||
utils.DisableDebugLogForTest()
|
utils.DisableDebugLogForTest()
|
||||||
if enterprise {
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
}
|
|
||||||
th.App.NewServer()
|
th.App.NewServer()
|
||||||
th.App.InitStores()
|
th.App.InitStores()
|
||||||
th.App.StartServer()
|
th.App.StartServer()
|
||||||
@@ -46,6 +43,11 @@ func setupTestHelper(enterprise bool) *TestHelper {
|
|||||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utils.SetIsLicensed(enterprise)
|
||||||
|
if enterprise {
|
||||||
|
utils.License().Features.SetDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
return th
|
return th
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ func (a *App) InitPlugins(pluginPath, webappPath string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.AddConfigListener(func(_, _ *model.Config) {
|
a.PluginConfigListenerId = utils.AddConfigListener(func(_, _ *model.Config) {
|
||||||
for _, err := range a.PluginEnv.Hooks().OnConfigurationChange() {
|
for _, err := range a.PluginEnv.Hooks().OnConfigurationChange() {
|
||||||
l4g.Error(err.Error())
|
l4g.Error(err.Error())
|
||||||
}
|
}
|
||||||
@@ -412,4 +412,6 @@ func (a *App) ShutDownPlugins() {
|
|||||||
for _, err := range a.PluginEnv.Shutdown() {
|
for _, err := range a.PluginEnv.Shutdown() {
|
||||||
l4g.Error(err.Error())
|
l4g.Error(err.Error())
|
||||||
}
|
}
|
||||||
|
utils.RemoveConfigListener(a.PluginConfigListenerId)
|
||||||
|
a.PluginConfigListenerId = ""
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user