mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 12:32:03 +00:00
Add test case for validateHostPort.
This commit is contained in:
parent
cac6db5d94
commit
36a3193ca9
@ -112,7 +112,7 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
|
|||||||
config: componentconfig.KubeProxyConfiguration{
|
config: componentconfig.KubeProxyConfiguration{
|
||||||
BindAddress: "10.10.12.11",
|
BindAddress: "10.10.12.11",
|
||||||
HealthzBindAddress: "0.0.0.0:12345",
|
HealthzBindAddress: "0.0.0.0:12345",
|
||||||
// only HealthzBindAddress is invalid
|
// only MetricsBindAddress is invalid
|
||||||
MetricsBindAddress: "127.0.0.1",
|
MetricsBindAddress: "127.0.0.1",
|
||||||
ClusterCIDR: "192.168.59.0/24",
|
ClusterCIDR: "192.168.59.0/24",
|
||||||
UDPIdleTimeout: metav1.Duration{Duration: 1 * time.Second},
|
UDPIdleTimeout: metav1.Duration{Duration: 1 * time.Second},
|
||||||
@ -439,3 +439,53 @@ func TestValidateClientConnectionConfiguration(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateHostPort(t *testing.T) {
|
||||||
|
newPath := field.NewPath("KubeProxyConfiguration")
|
||||||
|
|
||||||
|
successCases := []string{
|
||||||
|
"0.0.0.0:10256",
|
||||||
|
"127.0.0.1:10256",
|
||||||
|
"10.10.10.10:10256",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, successCase := range successCases {
|
||||||
|
if errs := validateHostPort(successCase, newPath.Child("HealthzBindAddress")); len(errs) != 0 {
|
||||||
|
t.Errorf("expected success: %v", errs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
errorCases := []struct {
|
||||||
|
ccc string
|
||||||
|
msg string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
ccc: "10.10.10.10",
|
||||||
|
msg: "must be IP:port",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ccc: "123.456.789.10:12345",
|
||||||
|
msg: "must be a valid IP",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ccc: "10.10.10.10:foo",
|
||||||
|
msg: "must be a valid port",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ccc: "10.10.10.10:0",
|
||||||
|
msg: "must be a valid port",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ccc: "10.10.10.10:65536",
|
||||||
|
msg: "must be a valid port",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, errorCase := range errorCases {
|
||||||
|
if errs := validateHostPort(errorCase.ccc, newPath.Child("HealthzBindAddress")); len(errs) == 0 {
|
||||||
|
t.Errorf("expected failure for %s", errorCase.msg)
|
||||||
|
} else if !strings.Contains(errs[0].Error(), errorCase.msg) {
|
||||||
|
t.Errorf("unexpected error: %v, expected: %s", errs[0], errorCase.msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user