summaryrefslogtreecommitdiffstats
path: root/utils/config_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'utils/config_test.go')
-rw-r--r--utils/config_test.go114
1 files changed, 108 insertions, 6 deletions
diff --git a/utils/config_test.go b/utils/config_test.go
index 5809422f1..f816e2ee8 100644
--- a/utils/config_test.go
+++ b/utils/config_test.go
@@ -12,6 +12,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+
+ "github.com/mattermost/mattermost-server/model"
)
func TestConfig(t *testing.T) {
@@ -21,6 +23,15 @@ func TestConfig(t *testing.T) {
InitTranslations(cfg.LocalizationSettings)
}
+func TestTimezoneConfig(t *testing.T) {
+ TranslationsPreInit()
+ supportedTimezones := LoadTimezones("timezones.json")
+ assert.Equal(t, len(supportedTimezones) > 0, true)
+
+ supportedTimezones2 := LoadTimezones("timezones_file_does_not_exists.json")
+ assert.Equal(t, len(supportedTimezones2) > 0, true)
+}
+
func TestFindConfigFile(t *testing.T) {
dir, err := ioutil.TempDir("", "")
require.NoError(t, err)
@@ -193,14 +204,97 @@ func TestValidateLocales(t *testing.T) {
}
func TestGetClientConfig(t *testing.T) {
- TranslationsPreInit()
- cfg, _, err := LoadConfig("config.json")
- require.Nil(t, err)
+ t.Parallel()
+ testCases := []struct {
+ description string
+ config *model.Config
+ diagnosticId string
+ license *model.License
+ expectedFields map[string]string
+ }{
+ {
+ "unlicensed",
+ &model.Config{
+ EmailSettings: model.EmailSettings{
+ EmailNotificationContentsType: sToP(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
+ },
+ ThemeSettings: model.ThemeSettings{
+ // Ignored, since not licensed.
+ AllowCustomThemes: bToP(false),
+ },
+ },
+ "",
+ nil,
+ map[string]string{
+ "DiagnosticId": "",
+ "EmailNotificationContentsType": "full",
+ "AllowCustomThemes": "true",
+ },
+ },
+ {
+ "licensed, but not for theme management",
+ &model.Config{
+ EmailSettings: model.EmailSettings{
+ EmailNotificationContentsType: sToP(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
+ },
+ ThemeSettings: model.ThemeSettings{
+ // Ignored, since not licensed.
+ AllowCustomThemes: bToP(false),
+ },
+ },
+ "tag1",
+ &model.License{
+ Features: &model.Features{
+ ThemeManagement: bToP(false),
+ },
+ },
+ map[string]string{
+ "DiagnosticId": "tag1",
+ "EmailNotificationContentsType": "full",
+ "AllowCustomThemes": "true",
+ },
+ },
+ {
+ "licensed for theme management",
+ &model.Config{
+ EmailSettings: model.EmailSettings{
+ EmailNotificationContentsType: sToP(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
+ },
+ ThemeSettings: model.ThemeSettings{
+ AllowCustomThemes: bToP(false),
+ },
+ },
+ "tag2",
+ &model.License{
+ Features: &model.Features{
+ ThemeManagement: bToP(true),
+ },
+ },
+ map[string]string{
+ "DiagnosticId": "tag2",
+ "EmailNotificationContentsType": "full",
+ "AllowCustomThemes": "false",
+ },
+ },
+ }
- configMap := GenerateClientConfig(cfg, "", nil)
- if configMap["EmailNotificationContentsType"] != *cfg.EmailSettings.EmailNotificationContentsType {
- t.Fatal("EmailSettings.EmailNotificationContentsType not exposed to client config")
+ for _, testCase := range testCases {
+ testCase := testCase
+ t.Run(testCase.description, func(t *testing.T) {
+ t.Parallel()
+
+ testCase.config.SetDefaults()
+ if testCase.license != nil {
+ testCase.license.Features.SetDefaults()
+ }
+
+ configMap := GenerateClientConfig(testCase.config, testCase.diagnosticId, testCase.license)
+ for expectedField, expectedValue := range testCase.expectedFields {
+ assert.Equal(t, expectedValue, configMap[expectedField])
+ }
+ })
}
+
}
func TestReadConfig(t *testing.T) {
@@ -213,3 +307,11 @@ func TestReadConfig(t *testing.T) {
assert.Equal(t, "http://foo.bar", *config.ServiceSettings.SiteURL)
}
+
+func sToP(s string) *string {
+ return &s
+}
+
+func bToP(b bool) *bool {
+ return &b
+}