mirror of https://github.com/hashicorp/consul
catalog: add failover mode enum validation (#18545)
parent
c4b3234bbc
commit
570c84d032
|
@ -139,6 +139,18 @@ func validateFailoverConfig(config *pbcatalog.FailoverConfig, ported bool) []err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch config.Mode {
|
||||||
|
case pbcatalog.FailoverMode_FAILOVER_MODE_UNSPECIFIED:
|
||||||
|
// means pbcatalog.FailoverMode_FAILOVER_MODE_SEQUENTIAL
|
||||||
|
case pbcatalog.FailoverMode_FAILOVER_MODE_SEQUENTIAL:
|
||||||
|
case pbcatalog.FailoverMode_FAILOVER_MODE_ORDER_BY_LOCALITY:
|
||||||
|
default:
|
||||||
|
errs = append(errs, resource.ErrInvalidField{
|
||||||
|
Name: "mode",
|
||||||
|
Wrapped: fmt.Errorf("not a supported enum value: %v", config.Mode),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: validate sameness group requirements
|
// TODO: validate sameness group requirements
|
||||||
|
|
||||||
return errs
|
return errs
|
||||||
|
|
|
@ -200,6 +200,15 @@ func TestValidateFailoverPolicy(t *testing.T) {
|
||||||
SamenessGroup: "blah",
|
SamenessGroup: "blah",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"mode: invalid": {
|
||||||
|
config: &pbcatalog.FailoverConfig{
|
||||||
|
Mode: 99,
|
||||||
|
Destinations: []*pbcatalog.FailoverDestination{
|
||||||
|
{Ref: newRef(ServiceType, "api-backup")},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectErr: `invalid "mode" field: not a supported enum value: 99`,
|
||||||
|
},
|
||||||
"dest: no ref": {
|
"dest: no ref": {
|
||||||
config: &pbcatalog.FailoverConfig{
|
config: &pbcatalog.FailoverConfig{
|
||||||
Destinations: []*pbcatalog.FailoverDestination{
|
Destinations: []*pbcatalog.FailoverDestination{
|
||||||
|
|
Loading…
Reference in New Issue