MM-29709 Client side feature flags (#16212)
* Client side feature flags. * Fix test. Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
213345fa2c
Коммит
ceb1422a5c
@@ -334,5 +334,9 @@ func GenerateLimitedClientConfig(c *model.Config, telemetryID string, license *m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for key, value := range featureFlagsToMap(c.FeatureFlags) {
|
||||||
|
props["FeatureFlag"+key] = value
|
||||||
|
}
|
||||||
|
|
||||||
return props
|
return props
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -257,6 +257,19 @@ func TestGetLimitedClientConfig(t *testing.T) {
|
|||||||
"PasswordRequireSymbol": "false",
|
"PasswordRequireSymbol": "false",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"Feature Flags",
|
||||||
|
&model.Config{
|
||||||
|
FeatureFlags: &model.FeatureFlags{
|
||||||
|
TestFeature: "myvalue",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"",
|
||||||
|
nil,
|
||||||
|
map[string]string{
|
||||||
|
"FeatureFlagTestFeature": "myvalue",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
|||||||
@@ -88,6 +88,24 @@ func featureFlagsFromMap(featuresMap map[string]string, baseFeatureFlags model.F
|
|||||||
return baseFeatureFlags
|
return baseFeatureFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// featureFlagsToMap returns the feature flags as a map[string]string
|
||||||
|
// Currently assumes that all feature flags are strings for now.
|
||||||
|
func featureFlagsToMap(featureFlags *model.FeatureFlags) map[string]string {
|
||||||
|
refStructVal := reflect.ValueOf(*featureFlags)
|
||||||
|
refStructType := reflect.TypeOf(*featureFlags)
|
||||||
|
ret := make(map[string]string)
|
||||||
|
for i := 0; i < refStructVal.NumField(); i++ {
|
||||||
|
refFieldVal := refStructVal.Field(i)
|
||||||
|
refFieldType := refStructType.Field(i)
|
||||||
|
if !refFieldVal.IsValid() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ret[refFieldType.Name] = refFieldVal.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func getStructFields(s interface{}) []string {
|
func getStructFields(s interface{}) []string {
|
||||||
structType := reflect.TypeOf(s)
|
structType := reflect.TypeOf(s)
|
||||||
fieldNames := make([]string, 0, structType.NumField())
|
fieldNames := make([]string, 0, structType.NumField())
|
||||||
|
|||||||
@@ -73,3 +73,27 @@ func TestFeatureFlagsFromMap(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFeatureFlagsToMap(t *testing.T) {
|
||||||
|
for name, tc := range map[string]struct {
|
||||||
|
Flags model.FeatureFlags
|
||||||
|
TestFeatureValue string
|
||||||
|
}{
|
||||||
|
"empty": {
|
||||||
|
TestFeatureValue: "",
|
||||||
|
Flags: model.FeatureFlags{},
|
||||||
|
},
|
||||||
|
"simple value": {
|
||||||
|
TestFeatureValue: "expectedvalue",
|
||||||
|
Flags: model.FeatureFlags{TestFeature: "expectedvalue"},
|
||||||
|
},
|
||||||
|
"empty value": {
|
||||||
|
TestFeatureValue: "",
|
||||||
|
Flags: model.FeatureFlags{TestFeature: ""},
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
require.Equal(t, tc.TestFeatureValue, featureFlagsToMap(&tc.Flags)["TestFeature"])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user