mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-03 11:48:15 +00:00
Rename ValidateNonSpecialIP to ValidateEndpointIP
There is not a single definition of "non-special IP" that makes sense in all contexts. Rename ValidateNonSpecialIP to ValidateEndpointIP and clarify that it shouldn't be used for other validations. Also add a few more unit tests.
This commit is contained in:
@@ -20725,7 +20725,7 @@ func TestValidateEndpointsCreate(t *testing.T) {
|
||||
}},
|
||||
},
|
||||
expectedErrs: field.ErrorList{
|
||||
field.Invalid(field.NewPath("subsets[0].addresses[0].ip"), nil, "").WithOrigin("format=non-special-ip"),
|
||||
field.Invalid(field.NewPath("subsets[0].addresses[0].ip"), nil, "").WithOrigin("format=endpoint-ip"),
|
||||
},
|
||||
},
|
||||
"Address is link-local": {
|
||||
@@ -20737,7 +20737,7 @@ func TestValidateEndpointsCreate(t *testing.T) {
|
||||
}},
|
||||
},
|
||||
expectedErrs: field.ErrorList{
|
||||
field.Invalid(field.NewPath("subsets[0].addresses[0].ip"), nil, "").WithOrigin("format=non-special-ip"),
|
||||
field.Invalid(field.NewPath("subsets[0].addresses[0].ip"), nil, "").WithOrigin("format=endpoint-ip"),
|
||||
},
|
||||
},
|
||||
"Address is link-local multicast": {
|
||||
@@ -20749,7 +20749,7 @@ func TestValidateEndpointsCreate(t *testing.T) {
|
||||
}},
|
||||
},
|
||||
expectedErrs: field.ErrorList{
|
||||
field.Invalid(field.NewPath("subsets[0].addresses[0].ip"), nil, "").WithOrigin("format=non-special-ip"),
|
||||
field.Invalid(field.NewPath("subsets[0].addresses[0].ip"), nil, "").WithOrigin("format=endpoint-ip"),
|
||||
},
|
||||
},
|
||||
"Invalid AppProtocol": {
|
||||
@@ -23641,7 +23641,7 @@ func TestValidateResourceRequirements(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateNonSpecialIP(t *testing.T) {
|
||||
func TestValidateEndpointIP(t *testing.T) {
|
||||
fp := field.NewPath("ip")
|
||||
|
||||
// Valid values.
|
||||
@@ -23652,11 +23652,15 @@ func TestValidateNonSpecialIP(t *testing.T) {
|
||||
{"ipv4", "10.1.2.3"},
|
||||
{"ipv4 class E", "244.1.2.3"},
|
||||
{"ipv6", "2000::1"},
|
||||
|
||||
// These probably should not have been allowed, but they are
|
||||
{"ipv4 multicast", "239.255.255.253"},
|
||||
{"ipv6 multicast", "ff05::1:3"},
|
||||
} {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
errs := ValidateNonSpecialIP(tc.ip, fp)
|
||||
errs := ValidateEndpointIP(tc.ip, fp)
|
||||
if len(errs) != 0 {
|
||||
t.Errorf("ValidateNonSpecialIP(%q, ...) = %v; want nil", tc.ip, errs)
|
||||
t.Errorf("ValidateEndpointIP(%q, ...) = %v; want nil", tc.ip, errs)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -23670,13 +23674,15 @@ func TestValidateNonSpecialIP(t *testing.T) {
|
||||
{"ipv4 localhost", "127.0.0.0"},
|
||||
{"ipv4 localhost", "127.255.255.255"},
|
||||
{"ipv6 localhost", "::1"},
|
||||
{"ipv4 link local", "169.254.169.254"},
|
||||
{"ipv6 link local", "fe80::"},
|
||||
{"ipv4 local multicast", "224.0.0.251"},
|
||||
{"ipv6 local multicast", "ff02::"},
|
||||
} {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
errs := ValidateNonSpecialIP(tc.ip, fp)
|
||||
errs := ValidateEndpointIP(tc.ip, fp)
|
||||
if len(errs) == 0 {
|
||||
t.Errorf("ValidateNonSpecialIP(%q, ...) = nil; want non-nil (errors)", tc.ip)
|
||||
t.Errorf("ValidateEndpointIP(%q, ...) = nil; want non-nil (errors)", tc.ip)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user