Skip to content

Commit

Permalink
catalog: add failover mode enum validation (#18545)
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyer authored Aug 22, 2023
1 parent c4b3234 commit 570c84d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/catalog/internal/types/failover_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

return errs
Expand Down
9 changes: 9 additions & 0 deletions internal/catalog/internal/types/failover_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ func TestValidateFailoverPolicy(t *testing.T) {
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": {
config: &pbcatalog.FailoverConfig{
Destinations: []*pbcatalog.FailoverDestination{
Expand Down

0 comments on commit 570c84d

Please sign in to comment.