mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
feat(featureflags): improved feature flag handling [EE-4609] (#8222)
* updated and improved feature flags using new module * merge init into parse * update the package documentation * better docs * minor tidy
This commit is contained in:
parent
51b9804fab
commit
bfc610c192
15 changed files with 257 additions and 184 deletions
75
pkg/featureflags/featureflags_test.go
Normal file
75
pkg/featureflags/featureflags_test.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
package featureflags
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_enableFeaturesFromFlags(t *testing.T) {
|
||||
is := assert.New(t)
|
||||
|
||||
supportedFeatures := []Feature{"supported", "supported2", "supported3", "supported4", "supported5"}
|
||||
|
||||
t.Run("supported features should be supported", func(t *testing.T) {
|
||||
Init(supportedFeatures)
|
||||
|
||||
for _, featureFlag := range supportedFeatures {
|
||||
is.True(IsSupported(featureFlag))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("unsupported features should not be supported", func(t *testing.T) {
|
||||
Init(supportedFeatures)
|
||||
|
||||
is.False(IsSupported("unsupported"))
|
||||
})
|
||||
|
||||
tests := []struct {
|
||||
cliFeatureFlags []string
|
||||
envFeatureFlags []string
|
||||
}{
|
||||
{[]string{"supported", "supported2"}, []string{"supported3", "supported4"}},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
Init(supportedFeatures)
|
||||
|
||||
os.Unsetenv("PORTAINER_FEATURE_FLAGS")
|
||||
os.Setenv("PORTAINER_FEATURE_FLAGS", strings.Join(test.envFeatureFlags, ","))
|
||||
|
||||
t.Run("testing", func(t *testing.T) {
|
||||
Parse(test.cliFeatureFlags)
|
||||
supported := toFeatureMap(test.cliFeatureFlags, test.envFeatureFlags)
|
||||
|
||||
// add env flags to supported flags
|
||||
for _, featureFlag := range test.envFeatureFlags {
|
||||
supported[Feature(featureFlag)] = true
|
||||
}
|
||||
|
||||
for _, featureFlag := range supportedFeatures {
|
||||
if _, ok := supported[featureFlag]; ok {
|
||||
is.True(IsEnabled(featureFlag))
|
||||
} else {
|
||||
is.False(IsEnabled(featureFlag))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// helper
|
||||
func toFeatureMap(cliFeatures []string, envFeatures []string) map[Feature]bool {
|
||||
m := map[Feature]bool{}
|
||||
for _, s := range cliFeatures {
|
||||
m[Feature(s)] = true
|
||||
}
|
||||
|
||||
for _, s := range envFeatures {
|
||||
m[Feature(s)] = true
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue