TCPSocket could not be used as it was not checked in validation
Attempting to use it gave the error "must register one handler". Added more tests for it.
This commit is contained in:
@@ -454,6 +454,14 @@ func validateHTTPGetAction(http *api.HTTPGetAction) errs.ValidationErrorList {
|
||||
return allErrors
|
||||
}
|
||||
|
||||
func validateTCPSocketAction(tcp *api.TCPSocketAction) errs.ValidationErrorList {
|
||||
allErrors := errs.ValidationErrorList{}
|
||||
if len(tcp.Port.StrVal) == 0 && tcp.Port.IntVal == 0 {
|
||||
allErrors = append(allErrors, errs.NewFieldRequired("port", tcp.Port))
|
||||
}
|
||||
return allErrors
|
||||
}
|
||||
|
||||
func validateHandler(handler *api.Handler) errs.ValidationErrorList {
|
||||
numHandlers := 0
|
||||
allErrors := errs.ValidationErrorList{}
|
||||
@@ -465,6 +473,10 @@ func validateHandler(handler *api.Handler) errs.ValidationErrorList {
|
||||
numHandlers++
|
||||
allErrors = append(allErrors, validateHTTPGetAction(handler.HTTPGet).Prefix("httpGet")...)
|
||||
}
|
||||
if handler.TCPSocket != nil {
|
||||
numHandlers++
|
||||
allErrors = append(allErrors, validateTCPSocketAction(handler.TCPSocket).Prefix("tcpSocket")...)
|
||||
}
|
||||
if numHandlers != 1 {
|
||||
allErrors = append(allErrors, errs.NewFieldInvalid("", handler, "exactly 1 handler type is required"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user