fix: make UNSPECIFIED protocol pass validation (#18634)

We explicitly enumerate the allowed protocols in validation, so this
change is necessary to use the new enum value.

Also add tests for enum validators to ensure they stay aligned to
protos unless we explicitly want them to diverge.
This commit is contained in:
Michael Zalimeni 2023-08-31 15:59:29 -04:00 committed by GitHub
parent 892ba52c56
commit 699aa47416
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -139,7 +139,9 @@ func validatePortName(name string) error {
func validateProtocol(protocol pbcatalog.Protocol) error {
switch protocol {
case pbcatalog.Protocol_PROTOCOL_TCP,
case pbcatalog.Protocol_PROTOCOL_UNSPECIFIED,
// means pbcatalog.FailoverMode_FAILOVER_MODE_TCP
pbcatalog.Protocol_PROTOCOL_TCP,
pbcatalog.Protocol_PROTOCOL_HTTP,
pbcatalog.Protocol_PROTOCOL_HTTP2,
pbcatalog.Protocol_PROTOCOL_GRPC,

View File

@ -334,6 +334,26 @@ func TestValidatePortName(t *testing.T) {
})
}
func TestValidateProtocol(t *testing.T) {
// this test simply verifies that we accept all enum values specified in our proto
// in order to avoid validator drift.
for name, value := range pbcatalog.Protocol_value {
t.Run(name, func(t *testing.T) {
require.NoError(t, validateProtocol(pbcatalog.Protocol(value)))
})
}
}
func TestValidateHealth(t *testing.T) {
// this test simply verifies that we accept all enum values specified in our proto
// in order to avoid validator drift.
for name, value := range pbcatalog.Health_value {
t.Run(name, func(t *testing.T) {
require.NoError(t, validateHealth(pbcatalog.Health(value)))
})
}
}
func TestValidateWorkloadAddress(t *testing.T) {
type testCase struct {
addr *pbcatalog.WorkloadAddress