Commit 4e6cc846 authored by Chris's avatar Chris Committed by Harrison Healey

Finally remove utils.Cfg (#8113)

* finally remove utils.Cfg

* fix compile error

* another test compilation fix
parent dce06163
......@@ -5,6 +5,8 @@ package api
import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"strings"
......@@ -24,7 +26,7 @@ import (
type TestHelper struct {
App *app.App
originalConfig *model.Config
tempConfigPath string
BasicClient *model.Client
BasicTeam *model.Team
......@@ -64,7 +66,22 @@ func StopTestStore() {
}
func setupTestHelper(enterprise bool) *TestHelper {
options := []app.Option{app.DisableConfigWatch}
permConfig, err := os.Open(utils.FindConfigFile("config.json"))
if err != nil {
panic(err)
}
defer permConfig.Close()
tempConfig, err := ioutil.TempFile("", "")
if err != nil {
panic(err)
}
_, err = io.Copy(tempConfig, permConfig)
tempConfig.Close()
if err != nil {
panic(err)
}
options := []app.Option{app.ConfigFile(tempConfig.Name()), app.DisableConfigWatch}
if testStore != nil {
options = append(options, app.StoreOverride(testStore))
}
......@@ -75,9 +92,9 @@ func setupTestHelper(enterprise bool) *TestHelper {
}
th := &TestHelper{
App: a,
App: a,
tempConfigPath: tempConfig.Name(),
}
th.originalConfig = th.App.Config().Clone()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.TeamSettings.MaxUsersPerTeam = 50
......@@ -176,7 +193,7 @@ func (me *TestHelper) CreateTeam(client *model.Client) *model.Team {
team := &model.Team{
DisplayName: "dn_" + id,
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: me.GenerateTestEmail(),
Type: model.TEAM_OPEN,
}
......@@ -190,7 +207,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User {
id := model.NewId()
user := &model.User{
Email: GenerateTestEmail(),
Email: me.GenerateTestEmail(),
Username: "un_" + id,
Nickname: "nn_" + id,
Password: "Password1",
......@@ -353,8 +370,8 @@ func (me *TestHelper) LoginSystemAdmin() {
utils.EnableDebugLogForTest()
}
func GenerateTestEmail() string {
if utils.Cfg.EmailSettings.SMTPServer != "dockerhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
func (me *TestHelper) GenerateTestEmail() string {
if me.App.Config().EmailSettings.SMTPServer != "dockerhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
return strings.ToLower("success+" + model.NewId() + "@simulator.amazonses.com")
}
return strings.ToLower(model.NewId() + "@dockerhost")
......@@ -365,11 +382,8 @@ func GenerateTestTeamName() string {
}
func (me *TestHelper) TearDown() {
me.App.UpdateConfig(func(cfg *model.Config) {
*cfg = *me.originalConfig
})
me.App.Shutdown()
os.Remove(me.tempConfigPath)
if err := recover(); err != nil {
StopTestStore()
panic(err)
......
......@@ -88,8 +88,6 @@ func TestOAuthRegisterApp(t *testing.T) {
t.Fatal("should have failed. not enough permissions")
}
adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
th.LoginBasic()
......@@ -741,9 +739,6 @@ func TestOAuthComplete(t *testing.T) {
// We are going to use mattermost as the provider emulating gitlab
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
oauthApp := &model.OAuthApp{
......
......@@ -66,7 +66,7 @@ func TestCreateTeamSanitization(t *testing.T) {
team := &model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}
......@@ -84,7 +84,7 @@ func TestCreateTeamSanitization(t *testing.T) {
team := &model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}
......@@ -304,7 +304,7 @@ func TestGetAllTeamsSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
......@@ -317,7 +317,7 @@ func TestGetAllTeamsSanitization(t *testing.T) {
if res, err := th.SystemAdminClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
......@@ -418,7 +418,7 @@ func TestGetAllTeamListingsSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
AllowOpenInvite: true,
......@@ -432,7 +432,7 @@ func TestGetAllTeamListingsSanitization(t *testing.T) {
if res, err := th.SystemAdminClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
AllowOpenInvite: true,
......@@ -665,7 +665,7 @@ func TestUpdateTeamSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
......@@ -772,7 +772,7 @@ func TestGetMyTeamSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
......@@ -1192,7 +1192,7 @@ func TestGetTeamByNameSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
......
......@@ -7,6 +7,7 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
......@@ -33,7 +34,7 @@ import (
type TestHelper struct {
App *app.App
originalConfig *model.Config
tempConfigPath string
Client *model.Client4
BasicUser *model.User
......@@ -73,7 +74,22 @@ func StopTestStore() {
}
func setupTestHelper(enterprise bool) *TestHelper {
options := []app.Option{app.DisableConfigWatch}
permConfig, err := os.Open(utils.FindConfigFile("config.json"))
if err != nil {
panic(err)
}
defer permConfig.Close()
tempConfig, err := ioutil.TempFile("", "")
if err != nil {
panic(err)
}
_, err = io.Copy(tempConfig, permConfig)
tempConfig.Close()
if err != nil {
panic(err)
}
options := []app.Option{app.ConfigFile(tempConfig.Name()), app.DisableConfigWatch}
if testStore != nil {
options = append(options, app.StoreOverride(testStore))
}
......@@ -84,9 +100,9 @@ func setupTestHelper(enterprise bool) *TestHelper {
}
th := &TestHelper{
App: a,
App: a,
tempConfigPath: tempConfig.Name(),
}
th.originalConfig = th.App.Config().Clone()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.TeamSettings.MaxUsersPerTeam = 50
......@@ -178,11 +194,8 @@ func (me *TestHelper) TearDown() {
wg.Wait()
me.App.UpdateConfig(func(cfg *model.Config) {
*cfg = *me.originalConfig
})
me.App.Shutdown()
os.Remove(me.tempConfigPath)
utils.EnableDebugLogForTest()
......@@ -262,7 +275,7 @@ func (me *TestHelper) CreateTeamWithClient(client *model.Client4) *model.Team {
team := &model.Team{
DisplayName: "dn_" + id,
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: me.GenerateTestEmail(),
Type: model.TEAM_OPEN,
}
......@@ -276,7 +289,7 @@ func (me *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
id := model.NewId()
user := &model.User{
Email: GenerateTestEmail(),
Email: me.GenerateTestEmail(),
Username: GenerateTestUsername(),
Nickname: "nn_" + id,
FirstName: "f_" + id,
......@@ -451,8 +464,8 @@ func (me *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) {
utils.EnableDebugLogForTest()
}
func GenerateTestEmail() string {
if utils.Cfg.EmailSettings.SMTPServer != "dockerhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
func (me *TestHelper) GenerateTestEmail() string {
if me.App.Config().EmailSettings.SMTPServer != "dockerhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
return strings.ToLower("success+" + model.NewId() + "@simulator.amazonses.com")
}
return strings.ToLower(model.NewId() + "@dockerhost")
......
......@@ -323,7 +323,7 @@ func TestCreatePostPublic(t *testing.T) {
post := &model.Post{ChannelId: th.BasicChannel.Id, Message: "#hashtag a" + model.NewId() + "a"}
user := model.User{Email: GenerateTestEmail(), Nickname: "Joram Wilander", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Joram Wilander", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_USER_ROLE_ID}
ruser, resp := Client.CreateUser(&user)
CheckNoError(t, resp)
......@@ -368,7 +368,7 @@ func TestCreatePostAll(t *testing.T) {
post := &model.Post{ChannelId: th.BasicChannel.Id, Message: "#hashtag a" + model.NewId() + "a"}
user := model.User{Email: GenerateTestEmail(), Nickname: "Joram Wilander", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Joram Wilander", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_USER_ROLE_ID}
directChannel, _ := th.App.CreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
......
......@@ -91,7 +91,7 @@ func TestCreateTeamSanitization(t *testing.T) {
team := &model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}
......@@ -109,7 +109,7 @@ func TestCreateTeamSanitization(t *testing.T) {
team := &model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}
......@@ -148,10 +148,10 @@ func TestGetTeam(t *testing.T) {
th.LoginTeamAdmin()
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: false}
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: false}
rteam2, _ := Client.CreateTeam(team2)
team3 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE, AllowOpenInvite: true}
team3 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_INVITE, AllowOpenInvite: true}
rteam3, _ := Client.CreateTeam(team3)
th.LoginBasic()
......@@ -178,7 +178,7 @@ func TestGetTeamSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -359,7 +359,7 @@ func TestUpdateTeamSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -458,7 +458,7 @@ func TestPatchTeamSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -492,7 +492,7 @@ func TestSoftDeleteTeam(t *testing.T) {
defer th.TearDown()
Client := th.Client
team := &model.Team{DisplayName: "DisplayName", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN}
team := &model.Team{DisplayName: "DisplayName", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN}
team, _ = Client.CreateTeam(team)
ok, resp := Client.SoftDeleteTeam(team.Id)
......@@ -534,7 +534,7 @@ func TestPermanentDeleteTeam(t *testing.T) {
defer th.TearDown()
Client := th.Client
team := &model.Team{DisplayName: "DisplayName", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN}
team := &model.Team{DisplayName: "DisplayName", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN}
team, _ = Client.CreateTeam(team)
ok, resp := Client.PermanentDeleteTeam(team.Id)
......@@ -567,7 +567,7 @@ func TestGetAllTeams(t *testing.T) {
defer th.TearDown()
Client := th.Client
team := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: true}
team := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: true}
_, resp := Client.CreateTeam(team)
CheckNoError(t, resp)
......@@ -627,7 +627,7 @@ func TestGetAllTeamsSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
AllowOpenInvite: true,
......@@ -636,7 +636,7 @@ func TestGetAllTeamsSanitization(t *testing.T) {
team2, resp := th.SystemAdminClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
AllowOpenInvite: true,
......@@ -722,10 +722,10 @@ func TestGetTeamByName(t *testing.T) {
th.LoginTeamAdmin()
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: false}
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: false}
rteam2, _ := Client.CreateTeam(team2)
team3 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE, AllowOpenInvite: true}
team3 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_INVITE, AllowOpenInvite: true}
rteam3, _ := Client.CreateTeam(team3)
th.LoginBasic()
......@@ -745,7 +745,7 @@ func TestGetTeamByNameSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -800,7 +800,7 @@ func TestSearchAllTeams(t *testing.T) {
oTeam.UpdateAt = updatedTeam.UpdateAt
}
pTeam := &model.Team{DisplayName: "PName", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE}
pTeam := &model.Team{DisplayName: "PName", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_INVITE}
Client.CreateTeam(pTeam)
rteams, resp := Client.SearchTeams(&model.TeamSearch{Term: oTeam.Name})
......@@ -876,7 +876,7 @@ func TestSearchAllTeamsSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -884,7 +884,7 @@ func TestSearchAllTeamsSanitization(t *testing.T) {
team2, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -954,7 +954,7 @@ func TestGetTeamsForUser(t *testing.T) {
defer th.TearDown()
Client := th.Client
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE}
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_INVITE}
rteam2, _ := Client.CreateTeam(team2)
teams, resp := Client.GetTeamsForUser(th.BasicUser.Id, "")
......@@ -998,7 +998,7 @@ func TestGetTeamsForUserSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -1006,7 +1006,7 @@ func TestGetTeamsForUserSanitization(t *testing.T) {
team2, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -1881,8 +1881,8 @@ func TestInviteUsersToTeam(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer th.TearDown()
user1 := GenerateTestEmail()
user2 := GenerateTestEmail()
user1 := th.GenerateTestEmail()
user2 := th.GenerateTestEmail()
emailList := []string{user1, user2}
......
This diff is collapsed.
......@@ -61,15 +61,11 @@ func TestUpdateConfig(t *testing.T) {
defer th.TearDown()
prev := *th.App.Config().ServiceSettings.SiteURL
defer th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.SiteURL = prev
})
listener := th.App.AddConfigListener(func(old, current *model.Config) {
th.App.AddConfigListener(func(old, current *model.Config) {
assert.Equal(t, prev, *old.ServiceSettings.SiteURL)
assert.Equal(t, "foo", *current.ServiceSettings.SiteURL)
})
defer th.App.RemoveConfigListener(listener)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.SiteURL = "foo"
......
......@@ -5,6 +5,7 @@ package app
import (
"encoding/json"
"io"
"io/ioutil"
"os"
"path/filepath"
......@@ -29,8 +30,9 @@ type TestHelper struct {
BasicChannel *model.Channel
BasicPost *model.Post
tempWorkspace string
pluginHooks map[string]plugin.Hooks
tempConfigPath string
tempWorkspace string
pluginHooks map[string]plugin.Hooks
}
type persistentTestStore struct {
......@@ -57,7 +59,22 @@ func StopTestStore() {
}
func setupTestHelper(enterprise bool) *TestHelper {
options := []Option{DisableConfigWatch}
permConfig, err := os.Open(utils.FindConfigFile("config.json"))
if err != nil {
panic(err)
}
defer permConfig.Close()
tempConfig, err := ioutil.TempFile("", "")
if err != nil {
panic(err)
}
_, err = io.Copy(tempConfig, permConfig)
tempConfig.Close()
if err != nil {
panic(err)
}
options := []Option{ConfigFile(tempConfig.Name()), DisableConfigWatch}
if testStore != nil {
options = append(options, StoreOverride(testStore))
}
......@@ -68,8 +85,9 @@ func setupTestHelper(enterprise bool) *TestHelper {
}
th := &TestHelper{
App: a,
pluginHooks: make(map[string]plugin.Hooks),
App: a,
pluginHooks: make(map[string]plugin.Hooks),
tempConfigPath: tempConfig.Name(),
}
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
......@@ -232,6 +250,7 @@ func (me *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) {
func (me *TestHelper) TearDown() {
me.App.Shutdown()
os.Remove(me.tempConfigPath)
if err := recover(); err != nil {
StopTestStore()
panic(err)
......
......@@ -27,7 +27,6 @@ func (a *App) UpdateConfig(f func(*model.Config)) {
updated := old.Clone()
f(updated)
a.config.Store(updated)
utils.Cfg = updated
a.InvokeConfigListeners(old, updated)
}
......@@ -48,7 +47,6 @@ func (a *App) LoadConfig(configFile string) *model.AppError {
utils.ConfigureLog(&cfg.LogSettings)
a.config.Store(cfg)
utils.Cfg = cfg
utils.SetSiteURL(*cfg.ServiceSettings.SiteURL)
......
......@@ -155,9 +155,7 @@ func TestDiagnostics(t *testing.T) {
})
t.Run("SendDailyDiagnosticsDisabled", func(t *testing.T) {
oldSetting := *th.App.Config().LogSettings.EnableDiagnostics
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.LogSettings.EnableDiagnostics = false })
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.LogSettings.EnableDiagnostics = oldSetting })
th.App.SendDailyDiagnostics()
......
......@@ -23,7 +23,7 @@ func (a *App) LoadLicense() {
if len(licenseId) != 26 {
// Lets attempt to load the file from disk since it was missing from the DB
license, licenseBytes := utils.GetAndValidateLicenseFileFromDisk()
license, licenseBytes := utils.GetAndValidateLicenseFileFromDisk(*a.Config().ServiceSettings.LicenseFileLocation)
if license != nil {
if _, err := a.SaveLicense(licenseBytes); err != nil {
......
......@@ -49,10 +49,6 @@ func TestOAuthDeleteApp(t *testing.T) {
th := Setup()
defer th.TearDown()
oldSetting := th.App.Config().ServiceSettings.EnableOAuthServiceProvider
defer th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.EnableOAuthServiceProvider = oldSetting
})
th.App.Config().ServiceSettings.EnableOAuthServiceProvider = true
a1 := &model.OAuthApp{}
......
......@@ -88,10 +88,6 @@ func TestCreateOAuthUser(t *testing.T) {
th.App.PermanentDeleteUser(user)
userCreation := th.App.Config().TeamSettings.EnableUserCreation
defer th.App.UpdateConfig(func(cfg *model.Config) {
cfg.TeamSettings.EnableUserCreation = userCreation
})
th.App.Config().TeamSettings.EnableUserCreation = false
_, err = th.App.CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
......
......@@ -17,13 +17,6 @@ func TestCreateIncomingWebhookForChannel(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
enableIncomingHooks := th.App.Config().ServiceSettings.EnableIncomingWebhooks
defer th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks })
enablePostUsernameOverride := th.App.Config().ServiceSettings.EnablePostUsernameOverride
defer th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = enablePostUsernameOverride })
enablePostIconOverride := th.App.Config().ServiceSettings.EnablePostIconOverride
defer th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = enablePostIconOverride })
type TestCase struct {
EnableIncomingHooks bool
EnablePostUsernameOverride bool
......@@ -155,13 +148,6 @@ func TestUpdateIncomingWebhook(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
enableIncomingHooks := th.App.Config().ServiceSettings.EnableIncomingWebhooks