@@ -9951,16 +9951,18 @@ func TestValidatePodDNSConfig(t *testing.T) {
9951
9951
}
9952
9952
9953
9953
for _, tc := range testCases {
9954
- if tc.dnsPolicy == nil {
9955
- tc.dnsPolicy = &testDNSClusterFirst
9956
- }
9954
+ t.Run("", func(t *testing.T) {
9955
+ if tc.dnsPolicy == nil {
9956
+ tc.dnsPolicy = &testDNSClusterFirst
9957
+ }
9957
9958
9958
- errs := validatePodDNSConfig(tc.dnsConfig, tc.dnsPolicy, field.NewPath("dnsConfig"), tc.opts)
9959
- if len(errs) != 0 && !tc.expectedError {
9960
- t.Errorf("%v: validatePodDNSConfig(%v) = %v, want nil", tc.desc, tc.dnsConfig, errs)
9961
- } else if len(errs) == 0 && tc.expectedError {
9962
- t.Errorf("%v: validatePodDNSConfig(%v) = nil, want error", tc.desc, tc.dnsConfig)
9963
- }
9959
+ errs := validatePodDNSConfig(tc.dnsConfig, tc.dnsPolicy, field.NewPath("dnsConfig"), tc.opts)
9960
+ if len(errs) != 0 && !tc.expectedError {
9961
+ t.Errorf("%v: validatePodDNSConfig(%v) = %v, want nil", tc.desc, tc.dnsConfig, errs)
9962
+ } else if len(errs) == 0 && tc.expectedError {
9963
+ t.Errorf("%v: validatePodDNSConfig(%v) = nil, want error", tc.desc, tc.dnsConfig)
9964
+ }
9965
+ })
9964
9966
}
9965
9967
}
9966
9968
@@ -10304,12 +10306,14 @@ func TestValidatePodSpec(t *testing.T) {
10304
10306
),
10305
10307
}
10306
10308
for k, v := range failureCases {
10307
- opts := PodValidationOptions{
10308
- ResourceIsPod: true,
10309
- }
10310
- if errs := ValidatePodSpec(&v.Spec, nil, field.NewPath("field"), opts); len(errs) == 0 {
10311
- t.Errorf("expected failure for %q", k)
10312
- }
10309
+ t.Run(k, func(t *testing.T) {
10310
+ opts := PodValidationOptions{
10311
+ ResourceIsPod: true,
10312
+ }
10313
+ if errs := ValidatePodSpec(&v.Spec, nil, field.NewPath("field"), opts); len(errs) == 0 {
10314
+ t.Errorf("expected failure")
10315
+ }
10316
+ })
10313
10317
}
10314
10318
}
10315
10319
@@ -15302,35 +15306,35 @@ func TestValidateServiceCreate(t *testing.T) {
15302
15306
// numErrs: 1,
15303
15307
numErrs: 0,
15304
15308
}, {
15305
- name: "invalid publicIPs localhost",
15309
+ name: "invalid externalIPs localhost",
15306
15310
tweakSvc: func(s *core.Service) {
15307
15311
s.Spec.ExternalTrafficPolicy = core.ServiceExternalTrafficPolicyCluster
15308
15312
s.Spec.ExternalIPs = []string{"127.0.0.1"}
15309
15313
},
15310
15314
numErrs: 1,
15311
15315
}, {
15312
- name: "invalid publicIPs unspecified",
15316
+ name: "invalid externalIPs unspecified",
15313
15317
tweakSvc: func(s *core.Service) {
15314
15318
s.Spec.ExternalTrafficPolicy = core.ServiceExternalTrafficPolicyCluster
15315
15319
s.Spec.ExternalIPs = []string{"0.0.0.0"}
15316
15320
},
15317
15321
numErrs: 1,
15318
15322
}, {
15319
- name: "invalid publicIPs loopback",
15323
+ name: "invalid externalIPs loopback",
15320
15324
tweakSvc: func(s *core.Service) {
15321
15325
s.Spec.ExternalTrafficPolicy = core.ServiceExternalTrafficPolicyCluster
15322
15326
s.Spec.ExternalIPs = []string{"127.0.0.1"}
15323
15327
},
15324
15328
numErrs: 1,
15325
15329
}, {
15326
- name: "invalid publicIPs host",
15330
+ name: "invalid externalIPs host",
15327
15331
tweakSvc: func(s *core.Service) {
15328
15332
s.Spec.ExternalTrafficPolicy = core.ServiceExternalTrafficPolicyCluster
15329
15333
s.Spec.ExternalIPs = []string{"myhost.mydomain"}
15330
15334
},
15331
15335
numErrs: 1,
15332
15336
}, {
15333
- name: "valid publicIPs ",
15337
+ name: "valid externalIPs ",
15334
15338
tweakSvc: func(s *core.Service) {
15335
15339
s.Spec.ExternalTrafficPolicy = core.ServiceExternalTrafficPolicyCluster
15336
15340
s.Spec.ExternalIPs = []string{"1.2.3.4"}
@@ -16989,9 +16993,11 @@ func TestValidateNode(t *testing.T) {
16989
16993
},
16990
16994
}
16991
16995
for _, successCase := range successCases {
16992
- if errs := ValidateNode(&successCase); len(errs) != 0 {
16993
- t.Errorf("expected success: %v", errs)
16994
- }
16996
+ t.Run("", func(t *testing.T) {
16997
+ if errs := ValidateNode(&successCase); len(errs) != 0 {
16998
+ t.Errorf("expected success: %v", errs)
16999
+ }
17000
+ })
16995
17001
}
16996
17002
16997
17003
errorCases := map[string]core.Node{
@@ -17195,30 +17201,32 @@ func TestValidateNode(t *testing.T) {
17195
17201
},
17196
17202
}
17197
17203
for k, v := range errorCases {
17198
- errs := ValidateNode(&v)
17199
- if len(errs) == 0 {
17200
- t.Errorf("expected failure for %s", k)
17201
- }
17202
- for i := range errs {
17203
- field := errs[i].Field
17204
- expectedFields := map[string]bool{
17205
- "metadata.name": true,
17206
- "metadata.labels": true,
17207
- "metadata.annotations": true,
17208
- "metadata.namespace": true,
17209
- "spec.externalID": true,
17210
- "spec.taints[0].key": true,
17211
- "spec.taints[0].value": true,
17212
- "spec.taints[0].effect": true,
17213
- "metadata.annotations.scheduler.alpha.kubernetes.io/preferAvoidPods[0].PodSignature": true,
17214
- "metadata.annotations.scheduler.alpha.kubernetes.io/preferAvoidPods[0].PodSignature.PodController.Controller": true,
17204
+ t.Run(k, func(t *testing.T) {
17205
+ errs := ValidateNode(&v)
17206
+ if len(errs) == 0 {
17207
+ t.Errorf("expected failure")
17215
17208
}
17216
- if val, ok := expectedFields[field]; ok {
17217
- if !val {
17218
- t.Errorf("%s: missing prefix for: %v", k, errs[i])
17209
+ for i := range errs {
17210
+ field := errs[i].Field
17211
+ expectedFields := map[string]bool{
17212
+ "metadata.name": true,
17213
+ "metadata.labels": true,
17214
+ "metadata.annotations": true,
17215
+ "metadata.namespace": true,
17216
+ "spec.externalID": true,
17217
+ "spec.taints[0].key": true,
17218
+ "spec.taints[0].value": true,
17219
+ "spec.taints[0].effect": true,
17220
+ "metadata.annotations.scheduler.alpha.kubernetes.io/preferAvoidPods[0].PodSignature": true,
17221
+ "metadata.annotations.scheduler.alpha.kubernetes.io/preferAvoidPods[0].PodSignature.PodController.Controller": true,
17222
+ }
17223
+ if val, ok := expectedFields[field]; ok {
17224
+ if !val {
17225
+ t.Errorf("missing prefix for: %v", errs[i])
17226
+ }
17219
17227
}
17220
17228
}
17221
- }
17229
+ })
17222
17230
}
17223
17231
}
17224
17232
@@ -22825,28 +22833,32 @@ func makePod(podName string, podNamespace string, podIPs []core.PodIP) core.Pod
22825
22833
}
22826
22834
}
22827
22835
func TestPodIPsValidation(t *testing.T) {
22836
+ // We test updating every pod in testCases to every other pod in testCases.
22837
+ // expectError is true if we expect an error when updating *to* that pod.
22838
+
22828
22839
testCases := []struct {
22829
22840
pod core.Pod
22830
22841
expectError bool
22831
- }{{
22832
- expectError: false,
22833
- pod: makePod("nil-ips", "ns", nil),
22834
- }, {
22835
- expectError: false,
22836
- pod: makePod("empty-podips-list", "ns", []core.PodIP{}),
22837
- }, {
22838
- expectError: false,
22839
- pod: makePod("single-ip-family-6", "ns", []core.PodIP{{IP: "::1"}}),
22840
- }, {
22841
- expectError: false,
22842
- pod: makePod("single-ip-family-4", "ns", []core.PodIP{{IP: "1.1.1.1"}}),
22843
- }, {
22844
- expectError: false,
22845
- pod: makePod("dual-stack-4-6", "ns", []core.PodIP{{IP: "1.1.1.1"}, {IP: "::1"}}),
22846
- }, {
22847
- expectError: false,
22848
- pod: makePod("dual-stack-6-4", "ns", []core.PodIP{{IP: "::1"}, {IP: "1.1.1.1"}}),
22849
- },
22842
+ }{
22843
+ {
22844
+ expectError: false,
22845
+ pod: makePod("nil-ips", "ns", nil),
22846
+ }, {
22847
+ expectError: false,
22848
+ pod: makePod("empty-podips-list", "ns", []core.PodIP{}),
22849
+ }, {
22850
+ expectError: false,
22851
+ pod: makePod("single-ip-family-6", "ns", []core.PodIP{{IP: "::1"}}),
22852
+ }, {
22853
+ expectError: false,
22854
+ pod: makePod("single-ip-family-4", "ns", []core.PodIP{{IP: "1.1.1.1"}}),
22855
+ }, {
22856
+ expectError: false,
22857
+ pod: makePod("dual-stack-4-6", "ns", []core.PodIP{{IP: "1.1.1.1"}, {IP: "::1"}}),
22858
+ }, {
22859
+ expectError: false,
22860
+ pod: makePod("dual-stack-6-4", "ns", []core.PodIP{{IP: "::1"}, {IP: "1.1.1.1"}}),
22861
+ },
22850
22862
/* failure cases start here */
22851
22863
{
22852
22864
expectError: true,
@@ -22887,10 +22899,10 @@ func TestPodIPsValidation(t *testing.T) {
22887
22899
errs := ValidatePodStatusUpdate(newPod, oldPod, PodValidationOptions{})
22888
22900
22889
22901
if len(errs) == 0 && testCase.expectError {
22890
- t.Fatalf("expected failure for %s, but there were none", testCase .pod.Name)
22902
+ t.Fatalf("expected failure updating from %s, but there were none", oldTestCase .pod.Name)
22891
22903
}
22892
22904
if len(errs) != 0 && !testCase.expectError {
22893
- t.Fatalf("expected success for %s, but there were errors: %v", testCase .pod.Name, errs)
22905
+ t.Fatalf("expected success updating from %s, but there were errors: %v", oldTestCase .pod.Name, errs)
22894
22906
}
22895
22907
}
22896
22908
})
@@ -22921,6 +22933,9 @@ func makePodWithHostIPs(podName string, podNamespace string, hostIPs []core.Host
22921
22933
}
22922
22934
22923
22935
func TestHostIPsValidation(t *testing.T) {
22936
+ // We test updating every pod in testCases to every other pod in testCases.
22937
+ // expectError is true if we expect an error when updating *to* that pod.
22938
+
22924
22939
testCases := []struct {
22925
22940
pod core.Pod
22926
22941
expectError bool
@@ -22952,7 +22967,7 @@ func TestHostIPsValidation(t *testing.T) {
22952
22967
/* failure cases start here */
22953
22968
{
22954
22969
expectError: true,
22955
- pod: makePodWithHostIPs("invalid-pod -ip", "ns", []core.HostIP{{IP: "this-is-not-an-ip"}}),
22970
+ pod: makePodWithHostIPs("invalid-host -ip", "ns", []core.HostIP{{IP: "this-is-not-an-ip"}}),
22956
22971
},
22957
22972
{
22958
22973
expectError: true,
@@ -22994,10 +23009,10 @@ func TestHostIPsValidation(t *testing.T) {
22994
23009
errs := ValidatePodStatusUpdate(newPod, oldPod, PodValidationOptions{})
22995
23010
22996
23011
if len(errs) == 0 && testCase.expectError {
22997
- t.Fatalf("expected failure for %s, but there were none", testCase .pod.Name)
23012
+ t.Fatalf("expected failure updating from %s, but there were none", oldTestCase .pod.Name)
22998
23013
}
22999
23014
if len(errs) != 0 && !testCase.expectError {
23000
- t.Fatalf("expected success for %s, but there were errors: %v", testCase .pod.Name, errs)
23015
+ t.Fatalf("expected success updating from %s, but there were errors: %v", oldTestCase .pod.Name, errs)
23001
23016
}
23002
23017
}
23003
23018
})
0 commit comments