[MM-32390] Config logic refactor (#17578)
* Replace config generator * Cleanup * Some renaming and docs additions to add clarity * Cleanup logging related methods * Cleanup emitter * Fix TestDefaultsGenerator * Move feature flags synchronization logic out of config package * Remove unnecessary util functions * Simplify load/set logic * Refine semantics and add some test to cover them * Remove unnecessary deep copies * Improve logic further * Fix license header * Review file store tests * Fix test * Fix test * Avoid additional write during initialization * More consistent naming * Update app/feature_flags.go Co-authored-by: Christopher Speller <crspeller@gmail.com> * Update config/store.go Co-authored-by: Christopher Speller <crspeller@gmail.com> * Update config/store.go Co-authored-by: Christopher Speller <crspeller@gmail.com> * Update config/store.go Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> * Move FF synchronizer to its own package * Remove unidiomatic use of sync.Once * Add some comments * Rename function * More comment Co-authored-by: Christopher Speller <crspeller@gmail.com> Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b810a40062
Коммит
3681cd3688
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
@@ -17,19 +18,19 @@ func TestDesanitize(t *testing.T) {
|
||||
actual.SetDefaults()
|
||||
|
||||
// These setting should be ignored
|
||||
actual.LdapSettings.Enable = bToP(false)
|
||||
actual.FileSettings.DriverName = sToP("s3")
|
||||
actual.LdapSettings.Enable = model.NewBool(false)
|
||||
actual.FileSettings.DriverName = model.NewString("s3")
|
||||
|
||||
// These settings should be desanitized into target.
|
||||
actual.LdapSettings.BindPassword = sToP("bind_password")
|
||||
actual.FileSettings.PublicLinkSalt = sToP("public_link_salt")
|
||||
actual.FileSettings.AmazonS3SecretAccessKey = sToP("amazon_s3_secret_access_key")
|
||||
actual.EmailSettings.SMTPPassword = sToP("smtp_password")
|
||||
actual.GitLabSettings.Secret = sToP("secret")
|
||||
actual.OpenIdSettings.Secret = sToP("secret")
|
||||
actual.SqlSettings.DataSource = sToP("data_source")
|
||||
actual.SqlSettings.AtRestEncryptKey = sToP("at_rest_encrypt_key")
|
||||
actual.ElasticsearchSettings.Password = sToP("password")
|
||||
actual.LdapSettings.BindPassword = model.NewString("bind_password")
|
||||
actual.FileSettings.PublicLinkSalt = model.NewString("public_link_salt")
|
||||
actual.FileSettings.AmazonS3SecretAccessKey = model.NewString("amazon_s3_secret_access_key")
|
||||
actual.EmailSettings.SMTPPassword = model.NewString("smtp_password")
|
||||
actual.GitLabSettings.Secret = model.NewString("secret")
|
||||
actual.OpenIdSettings.Secret = model.NewString("secret")
|
||||
actual.SqlSettings.DataSource = model.NewString("data_source")
|
||||
actual.SqlSettings.AtRestEncryptKey = model.NewString("at_rest_encrypt_key")
|
||||
actual.ElasticsearchSettings.Password = model.NewString("password")
|
||||
actual.SqlSettings.DataSourceReplicas = append(actual.SqlSettings.DataSourceReplicas, "replica0")
|
||||
actual.SqlSettings.DataSourceReplicas = append(actual.SqlSettings.DataSourceReplicas, "replica1")
|
||||
actual.SqlSettings.DataSourceSearchReplicas = append(actual.SqlSettings.DataSourceSearchReplicas, "search_replica0")
|
||||
@@ -39,19 +40,19 @@ func TestDesanitize(t *testing.T) {
|
||||
target.SetDefaults()
|
||||
|
||||
// These setting should be ignored
|
||||
target.LdapSettings.Enable = bToP(true)
|
||||
target.FileSettings.DriverName = sToP("file")
|
||||
target.LdapSettings.Enable = model.NewBool(true)
|
||||
target.FileSettings.DriverName = model.NewString("file")
|
||||
|
||||
// These settings should be updated from actual
|
||||
target.LdapSettings.BindPassword = sToP(model.FAKE_SETTING)
|
||||
target.FileSettings.PublicLinkSalt = sToP(model.FAKE_SETTING)
|
||||
target.FileSettings.AmazonS3SecretAccessKey = sToP(model.FAKE_SETTING)
|
||||
target.EmailSettings.SMTPPassword = sToP(model.FAKE_SETTING)
|
||||
target.GitLabSettings.Secret = sToP(model.FAKE_SETTING)
|
||||
target.OpenIdSettings.Secret = sToP(model.FAKE_SETTING)
|
||||
target.SqlSettings.DataSource = sToP(model.FAKE_SETTING)
|
||||
target.SqlSettings.AtRestEncryptKey = sToP(model.FAKE_SETTING)
|
||||
target.ElasticsearchSettings.Password = sToP(model.FAKE_SETTING)
|
||||
target.LdapSettings.BindPassword = model.NewString(model.FAKE_SETTING)
|
||||
target.FileSettings.PublicLinkSalt = model.NewString(model.FAKE_SETTING)
|
||||
target.FileSettings.AmazonS3SecretAccessKey = model.NewString(model.FAKE_SETTING)
|
||||
target.EmailSettings.SMTPPassword = model.NewString(model.FAKE_SETTING)
|
||||
target.GitLabSettings.Secret = model.NewString(model.FAKE_SETTING)
|
||||
target.OpenIdSettings.Secret = model.NewString(model.FAKE_SETTING)
|
||||
target.SqlSettings.DataSource = model.NewString(model.FAKE_SETTING)
|
||||
target.SqlSettings.AtRestEncryptKey = model.NewString(model.FAKE_SETTING)
|
||||
target.ElasticsearchSettings.Password = model.NewString(model.FAKE_SETTING)
|
||||
target.SqlSettings.DataSourceReplicas = []string{model.FAKE_SETTING, model.FAKE_SETTING}
|
||||
target.SqlSettings.DataSourceSearchReplicas = []string{model.FAKE_SETTING, model.FAKE_SETTING}
|
||||
|
||||
@@ -246,15 +247,7 @@ func TestStripPassword(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func sToP(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
func bToP(b bool) *bool {
|
||||
return &b
|
||||
}
|
||||
|
||||
func TestIsJsonMap(t *testing.T) {
|
||||
func TestIsJSONMap(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
data string
|
||||
@@ -278,9 +271,34 @@ func TestIsJsonMap(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := IsJsonMap(tt.data); got != tt.want {
|
||||
t.Errorf("IsJsonMap() = %v, want %v", got, tt.want)
|
||||
if got := isJSONMap(tt.data); got != tt.want {
|
||||
t.Errorf("isJSONMap() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqual(t *testing.T) {
|
||||
t.Run("nil", func(t *testing.T) {
|
||||
diff, err := equal(nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.False(t, diff)
|
||||
})
|
||||
|
||||
t.Run("no diff", func(t *testing.T) {
|
||||
old := minimalConfig.Clone()
|
||||
new := minimalConfig.Clone()
|
||||
diff, err := equal(old, new)
|
||||
require.NoError(t, err)
|
||||
require.False(t, diff)
|
||||
})
|
||||
|
||||
t.Run("diff", func(t *testing.T) {
|
||||
old := minimalConfig.Clone()
|
||||
new := minimalConfig.Clone()
|
||||
new.SqlSettings = model.SqlSettings{}
|
||||
diff, err := equal(old, new)
|
||||
require.NoError(t, err)
|
||||
require.True(t, diff)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user