add test in cmd/kubeadm/app/apis/kubeadm/validation/validation_test.go for ValidatePort

modify
This commit is contained in:
muyangren2 2022-07-28 15:07:18 +08:00
parent 1df7b3bed3
commit fc6bbf991e

View File

@ -18,6 +18,7 @@ package validation
import (
"os"
"strings"
"testing"
"github.com/spf13/pflag"
@ -183,6 +184,34 @@ func TestValidateIPFromString(t *testing.T) {
}
}
func TestValidatePort(t *testing.T) {
var tests = []struct {
name string
port int32
expectedErr bool
}{
{"negative number port", -1234, true},
{"zero number port", 0, true},
{"minimum valid value port", 1, false},
{"valid value port", 300, false},
{"maximum valid value port", 65535, false},
{"if port greater than 65535", 65538, true},
}
for _, rt := range tests {
t.Run(rt.name, func(t *testing.T) {
allErrs := ValidatePort(rt.port, nil)
if len(allErrs) > 0 {
find := strings.Contains(allErrs[0].Error(), "port number is not valid")
if find != rt.expectedErr {
t.Errorf(
"test case failed :\n\t err(s): %v\n\t", allErrs[0].Error(),
)
}
}
})
}
}
func TestValidateIPNetFromString(t *testing.T) {
var tests = []struct {
name string