2020-04-28 13:45:33 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-11-20 22:43:32 +00:00
|
|
|
func TestValidateEnterpriseConfigKeys(t *testing.T) {
|
2020-04-28 13:45:33 +00:00
|
|
|
// ensure that all the enterprise configurations
|
|
|
|
type testCase struct {
|
|
|
|
config Config
|
|
|
|
badKeys []string
|
|
|
|
check func(t *testing.T, c *Config)
|
|
|
|
}
|
|
|
|
|
|
|
|
boolVal := true
|
|
|
|
stringVal := "string"
|
|
|
|
|
|
|
|
cases := map[string]testCase{
|
2020-11-17 15:53:57 +00:00
|
|
|
"read_replica": {
|
|
|
|
config: Config{
|
|
|
|
ReadReplica: &boolVal,
|
|
|
|
},
|
2020-11-20 22:43:32 +00:00
|
|
|
badKeys: []string{"read_replica (or the deprecated non_voting_server)"},
|
2020-11-17 15:53:57 +00:00
|
|
|
},
|
2020-04-28 13:45:33 +00:00
|
|
|
"segment": {
|
|
|
|
config: Config{
|
|
|
|
SegmentName: &stringVal,
|
|
|
|
},
|
|
|
|
badKeys: []string{"segment"},
|
|
|
|
},
|
|
|
|
"segments": {
|
|
|
|
config: Config{
|
2020-11-20 22:43:32 +00:00
|
|
|
Segments: []Segment{{Name: &stringVal}},
|
2020-04-28 13:45:33 +00:00
|
|
|
},
|
|
|
|
badKeys: []string{"segments"},
|
|
|
|
},
|
|
|
|
"autopilot.redundancy_zone_tag": {
|
|
|
|
config: Config{
|
|
|
|
Autopilot: Autopilot{
|
|
|
|
RedundancyZoneTag: &stringVal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
badKeys: []string{"autopilot.redundancy_zone_tag"},
|
|
|
|
},
|
|
|
|
"autopilot.upgrade_version_tag": {
|
|
|
|
config: Config{
|
|
|
|
Autopilot: Autopilot{
|
|
|
|
UpgradeVersionTag: &stringVal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
badKeys: []string{"autopilot.upgrade_version_tag"},
|
|
|
|
},
|
|
|
|
"autopilot.disable_upgrade_migration": {
|
|
|
|
config: Config{
|
2020-11-20 22:43:32 +00:00
|
|
|
Autopilot: Autopilot{DisableUpgradeMigration: &boolVal},
|
2020-04-28 13:45:33 +00:00
|
|
|
},
|
|
|
|
badKeys: []string{"autopilot.disable_upgrade_migration"},
|
|
|
|
},
|
|
|
|
"dns_config.prefer_namespace": {
|
|
|
|
config: Config{
|
2020-11-20 22:43:32 +00:00
|
|
|
DNS: DNS{PreferNamespace: &boolVal},
|
2020-04-28 13:45:33 +00:00
|
|
|
},
|
|
|
|
badKeys: []string{"dns_config.prefer_namespace"},
|
|
|
|
check: func(t *testing.T, c *Config) {
|
|
|
|
require.Nil(t, c.DNS.PreferNamespace)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"acl.msp_disable_bootstrap": {
|
|
|
|
config: Config{
|
2020-11-20 22:43:32 +00:00
|
|
|
ACL: ACL{MSPDisableBootstrap: &boolVal},
|
2020-04-28 13:45:33 +00:00
|
|
|
},
|
|
|
|
badKeys: []string{"acl.msp_disable_bootstrap"},
|
|
|
|
check: func(t *testing.T, c *Config) {
|
|
|
|
require.Nil(t, c.ACL.MSPDisableBootstrap)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"acl.tokens.managed_service_provider": {
|
|
|
|
config: Config{
|
|
|
|
ACL: ACL{
|
|
|
|
Tokens: Tokens{
|
|
|
|
ManagedServiceProvider: []ServiceProviderToken{
|
|
|
|
{
|
|
|
|
AccessorID: &stringVal,
|
|
|
|
SecretID: &stringVal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
badKeys: []string{"acl.tokens.managed_service_provider"},
|
|
|
|
check: func(t *testing.T, c *Config) {
|
|
|
|
require.Empty(t, c.ACL.Tokens.ManagedServiceProvider)
|
|
|
|
require.Nil(t, c.ACL.Tokens.ManagedServiceProvider)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"multi": {
|
|
|
|
config: Config{
|
2020-11-17 15:53:57 +00:00
|
|
|
ReadReplica: &boolVal,
|
|
|
|
SegmentName: &stringVal,
|
2020-11-20 22:43:32 +00:00
|
|
|
ACL: ACL{Tokens: Tokens{AgentMaster: &stringVal}},
|
2020-04-28 13:45:33 +00:00
|
|
|
},
|
2020-11-20 22:43:32 +00:00
|
|
|
badKeys: []string{"read_replica (or the deprecated non_voting_server)", "segment"},
|
2020-04-28 13:45:33 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tcase := range cases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2020-11-20 22:43:32 +00:00
|
|
|
errs := validateEnterpriseConfigKeys(&tcase.config)
|
|
|
|
if len(tcase.badKeys) == 0 {
|
|
|
|
require.Len(t, errs, 0)
|
|
|
|
return
|
|
|
|
}
|
2020-04-28 13:45:33 +00:00
|
|
|
|
2020-11-20 22:43:32 +00:00
|
|
|
var expected []error
|
|
|
|
for _, k := range tcase.badKeys {
|
|
|
|
expected = append(expected, enterpriseConfigKeyError{key: k})
|
|
|
|
}
|
|
|
|
require.ElementsMatch(t, expected, errs)
|
2020-04-28 13:45:33 +00:00
|
|
|
|
2020-11-20 22:43:32 +00:00
|
|
|
if tcase.check != nil {
|
|
|
|
tcase.check(t, &tcase.config)
|
2020-04-28 13:45:33 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|