catalog: add failover mode enum validation (#18545)

pull/18448/head
R.B. Boyer 2023-08-22 11:09:37 -05:00 committed by GitHub
parent c4b3234bbc
commit 570c84d032
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -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

View File

@ -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{