Files
mostlymatter/config/feature_flags_test.go
Christopher Speller 1aadd36644 MM-28859 Add feature flag managment system using split.io and remove viper. (#15954)
* Add feature flag managment system using split.io and remove viper.

* Fixing tests.

* Attempt to fix postgres tests.

* Fix watch filepath for advanced logging.

* Review fixes.

* Some error wrapping.

* Remove unessisary store interface.

* Desanitize SplitKey

* Simplify.

* Review feedback.

* Rename split mlog adatper to split logger.

* fsInner

* Style.

* Restore oldcfg test.

* Downgrading non-actionable feature flag errors to warnings.

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-10-29 15:54:39 -07:00

76 строки
2.1 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package config
import (
"testing"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/stretchr/testify/require"
)
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: "",
},
} {
t.Run(name, func(t *testing.T) {
require.Equal(t, tc.ExpectedTestValue, featureFlagsFromMap(tc.FeatureMap, tc.Base).TestFeature)
})
}
}