* 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>
112 строки
3.3 KiB
Go
112 строки
3.3 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package featureflag
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/mattermost/mattermost-server/v5/model"
|
|
)
|
|
|
|
func TestGetStructFields(t *testing.T) {
|
|
type testStruct struct {
|
|
FieldOne string
|
|
SecondField bool
|
|
SomeOtherField int
|
|
}
|
|
|
|
fields := getStructFields(testStruct{})
|
|
require.Equal(t,
|
|
[]string{
|
|
"FieldOne",
|
|
"SecondField",
|
|
"SomeOtherField",
|
|
},
|
|
fields,
|
|
)
|
|
|
|
featureFlagsFields := getStructFields(model.FeatureFlags{})
|
|
require.Contains(t, featureFlagsFields, "TestFeature")
|
|
}
|
|
|
|
func TestFeatureFlagsFromMap(t *testing.T) {
|
|
for name, tc := range map[string]struct {
|
|
FeatureMap map[string]string
|
|
Base model.FeatureFlags
|
|
ExpectedTestValue string
|
|
}{
|
|
"empty": {
|
|
FeatureMap: map[string]string{},
|
|
Base: model.FeatureFlags{},
|
|
ExpectedTestValue: "",
|
|
},
|
|
"no base value": {
|
|
FeatureMap: map[string]string{"TestFeature": "expectedvalue"},
|
|
Base: model.FeatureFlags{},
|
|
ExpectedTestValue: "expectedvalue",
|
|
},
|
|
"only base value": {
|
|
FeatureMap: map[string]string{},
|
|
Base: model.FeatureFlags{TestFeature: "somebasevalue"},
|
|
ExpectedTestValue: "somebasevalue",
|
|
},
|
|
"override base value": {
|
|
FeatureMap: map[string]string{"TestFeature": "overridevalue"},
|
|
Base: model.FeatureFlags{TestFeature: "somebasevalue"},
|
|
ExpectedTestValue: "overridevalue",
|
|
},
|
|
"override base value with extras": {
|
|
FeatureMap: map[string]string{"TestFeature": "overridevalue", "SomeOldFlag": "oldvalue"},
|
|
Base: model.FeatureFlags{TestFeature: "somebasevalue"},
|
|
ExpectedTestValue: "overridevalue",
|
|
},
|
|
"all values do not exist": {
|
|
FeatureMap: map[string]string{"SomeOldFlag": "oldvalue"},
|
|
Base: model.FeatureFlags{},
|
|
ExpectedTestValue: "",
|
|
},
|
|
"bool on": {
|
|
FeatureMap: map[string]string{"TestBoolFeature": "on"},
|
|
Base: model.FeatureFlags{TestBoolFeature: true},
|
|
ExpectedTestValue: "",
|
|
},
|
|
"bool true": {
|
|
FeatureMap: map[string]string{"TestBoolFeature": "true"},
|
|
Base: model.FeatureFlags{TestBoolFeature: true},
|
|
ExpectedTestValue: "",
|
|
},
|
|
"bool True": {
|
|
FeatureMap: map[string]string{"TestBoolFeature": "True"},
|
|
Base: model.FeatureFlags{TestBoolFeature: true},
|
|
ExpectedTestValue: "",
|
|
},
|
|
"bool 1": {
|
|
FeatureMap: map[string]string{"TestBoolFeature": "1"},
|
|
Base: model.FeatureFlags{TestBoolFeature: true},
|
|
ExpectedTestValue: "",
|
|
},
|
|
"bool off": {
|
|
FeatureMap: map[string]string{"TestBoolFeature": "off"},
|
|
Base: model.FeatureFlags{},
|
|
ExpectedTestValue: "",
|
|
},
|
|
"bool false": {
|
|
FeatureMap: map[string]string{"TestBoolFeature": "false"},
|
|
Base: model.FeatureFlags{},
|
|
ExpectedTestValue: "",
|
|
},
|
|
"bool other value": {
|
|
FeatureMap: map[string]string{"TestBoolFeature": "someotherbadvalue"},
|
|
Base: model.FeatureFlags{},
|
|
ExpectedTestValue: "",
|
|
},
|
|
} {
|
|
t.Run(name, func(t *testing.T) {
|
|
require.Equal(t, tc.ExpectedTestValue, featureFlagsFromMap(tc.FeatureMap, tc.Base).TestFeature)
|
|
})
|
|
}
|
|
}
|