mirror of https://github.com/status-im/consul.git
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:
parent
892ba52c56
commit
699aa47416
|
@ -139,7 +139,9 @@ func validatePortName(name string) error {
|
||||||
|
|
||||||
func validateProtocol(protocol pbcatalog.Protocol) error {
|
func validateProtocol(protocol pbcatalog.Protocol) error {
|
||||||
switch protocol {
|
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_HTTP,
|
||||||
pbcatalog.Protocol_PROTOCOL_HTTP2,
|
pbcatalog.Protocol_PROTOCOL_HTTP2,
|
||||||
pbcatalog.Protocol_PROTOCOL_GRPC,
|
pbcatalog.Protocol_PROTOCOL_GRPC,
|
||||||
|
|
|
@ -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) {
|
func TestValidateWorkloadAddress(t *testing.T) {
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
addr *pbcatalog.WorkloadAddress
|
addr *pbcatalog.WorkloadAddress
|
||||||
|
|
Loading…
Reference in New Issue