Refactoring cfg refs and load / save functions (#7749)

* refactoring cfg refs and load / save functions

* improve error output
Этот коммит содержится в:
Chris
2017-10-31 09:39:31 -05:00
коммит произвёл Joram Wilander
родитель b446d0aa0a
Коммит ce2b2be5de
28 изменённых файлов: 250 добавлений и 247 удалений

Просмотреть файл

@@ -10,7 +10,6 @@ import (
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
"github.com/mattermost/mattermost-server/utils"
)
func TestGetLogs(t *testing.T) {
@@ -139,13 +138,13 @@ func TestSaveConfig(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer th.TearDown()
if _, err := th.BasicClient.SaveConfig(utils.Cfg); err == nil {
if _, err := th.BasicClient.SaveConfig(th.App.Config()); err == nil {
t.Fatal("Shouldn't have permissions")
}
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = false })
if _, err := th.SystemAdminClient.SaveConfig(utils.Cfg); err != nil {
if _, err := th.SystemAdminClient.SaveConfig(th.App.Config()); err != nil {
t.Fatal(err)
}

Просмотреть файл

@@ -16,20 +16,15 @@ import (
func TestMain(m *testing.M) {
flag.Parse()
utils.TranslationsPreInit()
// In the case where a dev just wants to run a single test, it's faster to just use the default
// store.
if filter := flag.Lookup("test.run").Value.String(); filter != "" && filter != "." {
utils.TranslationsPreInit()
utils.LoadConfig("config.json")
l4g.Info("-test.run used, not creating temporary containers")
os.Exit(m.Run())
}
utils.TranslationsPreInit()
utils.LoadConfig("config.json")
utils.InitTranslations(utils.Cfg.LocalizationSettings)
status := 0
container, settings, err := storetest.NewMySQLContainer()

Просмотреть файл

@@ -64,12 +64,6 @@ func StopTestStore() {
}
func setupTestHelper(enterprise bool) *TestHelper {
if utils.T == nil {
utils.TranslationsPreInit()
}
utils.LoadConfig("config.json")
utils.InitTranslations(utils.Cfg.LocalizationSettings)
var options []app.Option
if testStore != nil {
options = append(options, app.StoreOverride(testStore))
@@ -80,9 +74,11 @@ func setupTestHelper(enterprise bool) *TestHelper {
}
th.originalConfig = th.App.Config().Clone()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.RateLimitSettings.Enable = false })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.EmailSettings.SendEmailNotifications = true })
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.TeamSettings.MaxUsersPerTeam = 50
*cfg.RateLimitSettings.Enable = false
cfg.EmailSettings.SendEmailNotifications = true
})
utils.DisableDebugLogForTest()
prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress
if testStore != nil {

Просмотреть файл

@@ -517,7 +517,7 @@ func TestGetPublicFileOld(t *testing.T) {
// reconstruct old style of link
siteURL := fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port)
link := generatePublicLinkOld(siteURL, th.BasicTeam.Id, channel.Id, th.BasicUser.Id, fileId+"/test.png")
link := generatePublicLinkOld(siteURL, th.BasicTeam.Id, channel.Id, th.BasicUser.Id, fileId+"/test.png", *th.App.Config().FileSettings.PublicLinkSalt)
// Wait a bit for files to ready
time.Sleep(2 * time.Second)
@@ -553,8 +553,8 @@ func TestGetPublicFileOld(t *testing.T) {
}
}
func generatePublicLinkOld(siteURL, teamId, channelId, userId, filename string) string {
hash := app.GeneratePublicLinkHash(filename, *utils.Cfg.FileSettings.PublicLinkSalt)
func generatePublicLinkOld(siteURL, teamId, channelId, userId, filename, salt string) string {
hash := app.GeneratePublicLinkHash(filename, salt)
return fmt.Sprintf("%s%s/public/files/get/%s/%s/%s/%s?h=%s", siteURL, model.API_URL_SUFFIX_V3, teamId, channelId, userId, filename, hash)
}

Просмотреть файл

@@ -326,7 +326,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
if c.HandleEtag(etag, "Get User", w, r) {
return
} else {
app.SanitizeProfile(user, c.IsSystemAdmin())
c.App.SanitizeProfile(user, c.IsSystemAdmin())
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
w.Write([]byte(user.ToJson()))
return
@@ -560,7 +560,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
}
var img []byte
img, readFailed, err = app.GetProfileImage(user)
img, readFailed, err = c.App.GetProfileImage(user)
if err != nil {
c.Err = err
return

Просмотреть файл

@@ -643,7 +643,7 @@ func TestUserCreateImage(t *testing.T) {
Client := th.BasicClient
b, err := app.CreateProfileImage("Corey Hulen", "eo1zkdr96pdj98pjmq8zy35wba")
b, err := app.CreateProfileImage("Corey Hulen", "eo1zkdr96pdj98pjmq8zy35wba", th.App.Config().FileSettings.InitialFont)
if err != nil {
t.Fatal(err)
}