mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-12323: Fix trailing slash in ServiceSettings.SiteURL (#9463)
* Fix trailing slash in ServiceSettings.SiteURL * Add test for LoadConfig * Fix test * Simplify test
This commit is contained in:
@@ -61,13 +61,12 @@ func (a *App) LoadConfig(configFile string) *model.AppError {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*cfg.ServiceSettings.SiteURL = strings.TrimRight(*cfg.ServiceSettings.SiteURL, "/")
|
||||
a.config.Store(cfg)
|
||||
|
||||
a.configFile = configPath
|
||||
|
||||
a.config.Store(cfg)
|
||||
a.envConfig = envConfig
|
||||
|
||||
a.siteURL = strings.TrimRight(*cfg.ServiceSettings.SiteURL, "/")
|
||||
a.siteURL = *cfg.ServiceSettings.SiteURL
|
||||
|
||||
a.InvokeConfigListeners(old, cfg)
|
||||
return nil
|
||||
|
||||
@@ -4,17 +4,45 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store/sqlstore"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
func TestLoadConfig(t *testing.T) {
|
||||
tempConfig, err := ioutil.TempFile("", "")
|
||||
require.Nil(t, err)
|
||||
|
||||
input, err := ioutil.ReadFile(utils.FindConfigFile("config.json"))
|
||||
require.Nil(t, err)
|
||||
lines := strings.Split(string(input), "\n")
|
||||
for i, line := range lines {
|
||||
if strings.Contains(line, "SiteURL") {
|
||||
lines[i] = ` "SiteURL": "http://localhost:8065/",`
|
||||
}
|
||||
}
|
||||
output := strings.Join(lines, "\n")
|
||||
err = ioutil.WriteFile(tempConfig.Name(), []byte(output), 0644)
|
||||
require.Nil(t, err)
|
||||
tempConfig.Close()
|
||||
|
||||
a := App{}
|
||||
appErr := a.LoadConfig(tempConfig.Name())
|
||||
require.Nil(t, appErr)
|
||||
|
||||
assert.Equal(t, "http://localhost:8065", a.siteURL)
|
||||
assert.Equal(t, "http://localhost:8065", *a.GetConfig().ServiceSettings.SiteURL)
|
||||
}
|
||||
|
||||
func TestConfigListener(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Reference in New Issue
Block a user