* app.UpdateConfig method

* test fix

* another test fix

* the config override option as-was is just error prone, remove it for now

* derp
Этот коммит содержится в:
Chris
2017-10-18 15:36:43 -07:00
коммит произвёл GitHub
родитель 34a87fa8f4
Коммит 8e19ba029f
91 изменённых файлов: 1390 добавлений и 1276 удалений

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

@@ -10,7 +10,6 @@ import (
"time"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
)
func TestListCommands(t *testing.T) {
@@ -45,11 +44,11 @@ func TestCreateCommand(t *testing.T) {
user := th.SystemAdminUser
team := th.SystemAdminTeam
enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
enableCommands := *th.App.Config().ServiceSettings.EnableCommands
defer func() {
utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableCommands = &enableCommands })
}()
*utils.Cfg.ServiceSettings.EnableCommands = true
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
cmd1 := &model.Command{
CreatorId: user.Id,
@@ -108,11 +107,11 @@ func TestListTeamCommands(t *testing.T) {
Client := th.SystemAdminClient
enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
enableCommands := *th.App.Config().ServiceSettings.EnableCommands
defer func() {
utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableCommands = &enableCommands })
}()
*utils.Cfg.ServiceSettings.EnableCommands = true
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
cmd1 := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST, Trigger: "trigger"}
cmd1 = Client.Must(Client.CreateCommand(cmd1)).Data.(*model.Command)
@@ -136,11 +135,11 @@ func TestUpdateCommand(t *testing.T) {
user := th.SystemAdminUser
team := th.SystemAdminTeam
enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
enableCommands := *th.App.Config().ServiceSettings.EnableCommands
defer func() {
utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableCommands = &enableCommands })
}()
*utils.Cfg.ServiceSettings.EnableCommands = true
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
cmd1 := &model.Command{
CreatorId: user.Id,
@@ -175,11 +174,11 @@ func TestRegenToken(t *testing.T) {
Client := th.SystemAdminClient
enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
enableCommands := *th.App.Config().ServiceSettings.EnableCommands
defer func() {
utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableCommands = &enableCommands })
}()
*utils.Cfg.ServiceSettings.EnableCommands = true
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
cmd := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST, Trigger: "trigger"}
cmd = Client.Must(Client.CreateCommand(cmd)).Data.(*model.Command)
@@ -202,14 +201,14 @@ func TestDeleteCommand(t *testing.T) {
Client := th.SystemAdminClient
enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
onlyAdminIntegration := *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
enableCommands := *th.App.Config().ServiceSettings.EnableCommands
onlyAdminIntegration := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
*utils.Cfg.ServiceSettings.EnableCommands = enableCommands
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = onlyAdminIntegration
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = enableCommands })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = onlyAdminIntegration })
}()
*utils.Cfg.ServiceSettings.EnableCommands = true
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
cmd := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST, Trigger: "trigger"}
cmd = Client.Must(Client.CreateCommand(cmd)).Data.(*model.Command)
@@ -248,14 +247,16 @@ func TestTestCommand(t *testing.T) {
Client := th.SystemAdminClient
channel1 := th.SystemAdminChannel
enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections
enableCommands := *th.App.Config().ServiceSettings.EnableCommands
allowedInternalConnections := *th.App.Config().ServiceSettings.AllowedUntrustedInternalConnections
defer func() {
utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableCommands = &enableCommands })
th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
})
}()
*utils.Cfg.ServiceSettings.EnableCommands = true
*utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost"
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost" })
cmd1 := &model.Command{
URL: fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port) + model.API_URL_SUFFIX_V3 + "/teams/command_test",