summaryrefslogtreecommitdiffstats
path: root/api4
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-09-12 09:19:52 -0500
committerGitHub <noreply@github.com>2017-09-12 09:19:52 -0500
commitb066b6df138e88e75cb40f1ec3e58fbd13e61909 (patch)
tree7ee0e8c935cd3bbafd15d0d07d8900af8b82a4e0 /api4
parent674a606bd00b276d0a05b3b29a3d5f5e5e7f8206 (diff)
downloadchat-b066b6df138e88e75cb40f1ec3e58fbd13e61909.tar.gz
chat-b066b6df138e88e75cb40f1ec3e58fbd13e61909.tar.bz2
chat-b066b6df138e88e75cb40f1ec3e58fbd13e61909.zip
Remove global app references (#7433)
* remove global app references * test fix * fix api4 test compilation
Diffstat (limited to 'api4')
-rw-r--r--api4/api.go15
-rw-r--r--api4/apitestlib.go66
-rw-r--r--api4/plugin_test.go2
3 files changed, 31 insertions, 52 deletions
diff --git a/api4/api.go b/api4/api.go
index 50c56ca0b..7b3beaf40 100644
--- a/api4/api.go
+++ b/api4/api.go
@@ -105,15 +105,16 @@ type Routes struct {
var BaseRoutes *Routes
-func InitRouter() {
- app.Global().Srv.Router = mux.NewRouter()
- app.Global().Srv.Router.NotFoundHandler = http.HandlerFunc(Handle404)
+func NewRouter() *mux.Router {
+ ret := mux.NewRouter()
+ ret.NotFoundHandler = http.HandlerFunc(Handle404)
+ return ret
}
-func InitApi(full bool) {
+func InitApi(root *mux.Router, full bool) {
BaseRoutes = &Routes{}
- BaseRoutes.Root = app.Global().Srv.Router
- BaseRoutes.ApiRoot = app.Global().Srv.Router.PathPrefix(model.API_URL_SUFFIX).Subrouter()
+ BaseRoutes.Root = root
+ BaseRoutes.ApiRoot = root.PathPrefix(model.API_URL_SUFFIX).Subrouter()
BaseRoutes.Users = BaseRoutes.ApiRoot.PathPrefix("/users").Subrouter()
BaseRoutes.User = BaseRoutes.ApiRoot.PathPrefix("/users/{user_id:[A-Za-z0-9]+}").Subrouter()
@@ -213,7 +214,7 @@ func InitApi(full bool) {
InitOpenGraph()
InitPlugin()
- app.Global().Srv.Router.Handle("/api/v4/{anything:.*}", http.HandlerFunc(Handle404))
+ root.Handle("/api/v4/{anything:.*}", http.HandlerFunc(Handle404))
// REMOVE CONDITION WHEN APIv3 REMOVED
if full {
diff --git a/api4/apitestlib.go b/api4/apitestlib.go
index e647d659c..d98683d32 100644
--- a/api4/apitestlib.go
+++ b/api4/apitestlib.go
@@ -45,8 +45,12 @@ type TestHelper struct {
SystemAdminUser *model.User
}
-func SetupEnterprise() *TestHelper {
- if app.Global().Srv == nil {
+func setupTestHelper(enterprise bool) *TestHelper {
+ th := &TestHelper{
+ App: app.Global(),
+ }
+
+ if th.App.Srv == nil {
utils.TranslationsPreInit()
utils.LoadConfig("config.json")
utils.InitTranslations(utils.Cfg.LocalizationSettings)
@@ -54,63 +58,37 @@ func SetupEnterprise() *TestHelper {
*utils.Cfg.RateLimitSettings.Enable = false
utils.Cfg.EmailSettings.SendEmailNotifications = true
utils.DisableDebugLogForTest()
- utils.License().Features.SetDefaults()
- app.Global().NewServer()
- app.Global().InitStores()
- InitRouter()
+ if enterprise {
+ utils.License().Features.SetDefaults()
+ }
+ th.App.NewServer()
+ th.App.InitStores()
+ th.App.Srv.Router = NewRouter()
wsapi.InitRouter()
- app.Global().StartServer()
- utils.InitHTML()
- InitApi(true)
+ th.App.StartServer()
+ InitApi(th.App.Srv.Router, true)
wsapi.InitApi()
utils.EnableDebugLogForTest()
- app.Global().Srv.Store.MarkSystemRanUnitTests()
+ th.App.Srv.Store.MarkSystemRanUnitTests()
*utils.Cfg.TeamSettings.EnableOpenServer = true
}
if jobs.Srv.Store == nil {
- jobs.Srv.Store = app.Global().Srv.Store
+ jobs.Srv.Store = th.App.Srv.Store
}
- th := &TestHelper{}
- th.App = app.Global()
th.Client = th.CreateClient()
th.SystemAdminClient = th.CreateClient()
return th
}
-func Setup() *TestHelper {
- if app.Global().Srv == nil {
- utils.TranslationsPreInit()
- utils.LoadConfig("config.json")
- utils.InitTranslations(utils.Cfg.LocalizationSettings)
- *utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
- *utils.Cfg.RateLimitSettings.Enable = false
- utils.Cfg.EmailSettings.SendEmailNotifications = true
- utils.DisableDebugLogForTest()
- app.Global().NewServer()
- app.Global().InitStores()
- InitRouter()
- wsapi.InitRouter()
- app.Global().StartServer()
- InitApi(true)
- wsapi.InitApi()
- utils.EnableDebugLogForTest()
- app.Global().Srv.Store.MarkSystemRanUnitTests()
-
- *utils.Cfg.TeamSettings.EnableOpenServer = true
- }
-
- if jobs.Srv.Store == nil {
- jobs.Srv.Store = app.Global().Srv.Store
- }
+func SetupEnterprise() *TestHelper {
+ return setupTestHelper(true)
+}
- th := &TestHelper{}
- th.App = app.Global()
- th.Client = th.CreateClient()
- th.SystemAdminClient = th.CreateClient()
- return th
+func Setup() *TestHelper {
+ return setupTestHelper(false)
}
func StopServer() {
@@ -389,7 +367,7 @@ func (me *TestHelper) LoginSystemAdminWithClient(client *model.Client4) {
func (me *TestHelper) UpdateActiveUser(user *model.User, active bool) {
utils.DisableDebugLogForTest()
- _, err := app.Global().UpdateActive(user, active)
+ _, err := me.App.UpdateActive(user, active)
if err != nil {
l4g.Error(err.Error())
l4g.Close()
diff --git a/api4/plugin_test.go b/api4/plugin_test.go
index 0e8c0638c..898649f56 100644
--- a/api4/plugin_test.go
+++ b/api4/plugin_test.go
@@ -29,7 +29,7 @@ func TestPlugin(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()
- th.App.StartupPlugins(pluginDir, webappDir)
+ th.App.InitPlugins(pluginDir, webappDir)
enablePlugins := *utils.Cfg.PluginSettings.Enable
defer func() {