Skip to content

Commit 54bd7c8

Browse files
committed
Fix panics in patch unit tests
Signed-off-by: Stefan Büringer buringerst@vmware.com
1 parent f9cd33f commit 54bd7c8

File tree

1 file changed

+112
-1
lines changed

1 file changed

+112
-1
lines changed

util/patch/patch_test.go

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,19 @@ func TestPatchHelper(t *testing.T) {
263263

264264
testConditionCopy := conditions.Get(objCopy, "TestCondition")
265265
testConditionAfter := conditions.Get(objAfter, "TestCondition")
266+
if testConditionCopy == nil || testConditionAfter == nil {
267+
return false
268+
}
266269
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
267270
if err != nil || !ok {
268271
return false
269272
}
270273

271274
readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
272275
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
276+
if readyBefore == nil || readyAfter == nil {
277+
return false
278+
}
273279
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
274280
if err != nil || !ok {
275281
return false
@@ -329,13 +335,19 @@ func TestPatchHelper(t *testing.T) {
329335

330336
testConditionCopy := conditions.Get(objCopy, "TestCondition")
331337
testConditionAfter := conditions.Get(objAfter, "TestCondition")
338+
if testConditionCopy == nil || testConditionAfter == nil {
339+
return false
340+
}
332341
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
333342
if err != nil || !ok {
334343
return false
335344
}
336345

337346
readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
338347
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
348+
if readyBefore == nil || readyAfter == nil {
349+
return false
350+
}
339351
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
340352
if err != nil || !ok {
341353
return false
@@ -1135,13 +1147,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
11351147

11361148
testConditionCopy := conditions.Get(objCopy, "TestCondition")
11371149
testConditionAfter := conditions.Get(objAfter, "TestCondition")
1150+
if testConditionCopy == nil || testConditionAfter == nil {
1151+
return false
1152+
}
11381153
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
11391154
if err != nil || !ok {
11401155
return false
11411156
}
11421157

11431158
readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
11441159
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
1160+
if readyBefore == nil || readyAfter == nil {
1161+
return false
1162+
}
11451163
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
11461164
if err != nil || !ok {
11471165
return false
@@ -1199,13 +1217,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
11991217

12001218
testConditionCopy := conditions.Get(objCopy, "TestCondition")
12011219
testConditionAfter := conditions.Get(objAfter, "TestCondition")
1220+
if testConditionCopy == nil || testConditionAfter == nil {
1221+
return false
1222+
}
12021223
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
12031224
if err != nil || !ok {
12041225
return false
12051226
}
12061227

12071228
readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
12081229
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
1230+
if readyBefore == nil || readyAfter == nil {
1231+
return false
1232+
}
12091233
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
12101234
if err != nil || !ok {
12111235
return false
@@ -1539,28 +1563,37 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
15391563

15401564
testConditionCopy := conditions.Get(objCopy, "Test")
15411565
testConditionAfter := conditions.Get(objAfter, "Test")
1566+
if testConditionCopy == nil || testConditionAfter == nil {
1567+
return false
1568+
}
15421569
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
15431570
if err != nil || !ok {
15441571
return false
15451572
}
15461573

15471574
readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
15481575
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
1576+
if readyBefore == nil || readyAfter == nil {
1577+
return false
1578+
}
15491579
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
15501580
if err != nil || !ok {
15511581
return false
15521582
}
15531583

15541584
testV1Beta2ConditionCopy := v1beta2conditions.Get(objCopy, "Test")
15551585
testV1Beta2ConditionAfter := v1beta2conditions.Get(objAfter, "Test")
1586+
if testV1Beta2ConditionCopy == nil || testV1Beta2ConditionAfter == nil {
1587+
return false
1588+
}
15561589
ok, err = v1beta2conditions.MatchCondition(*testV1Beta2ConditionCopy).Match(*testV1Beta2ConditionAfter)
15571590
if err != nil || !ok {
15581591
return false
15591592
}
15601593

15611594
readyV1Beta2Before := v1beta2conditions.Get(obj, "Ready")
15621595
readyV1Beta2After := v1beta2conditions.Get(objAfter, "Ready")
1563-
if err != nil {
1596+
if readyV1Beta2Before == nil || readyV1Beta2After == nil {
15641597
return false
15651598
}
15661599
ok, err = v1beta2conditions.MatchCondition(*readyV1Beta2Before).Match(*readyV1Beta2After)
@@ -1623,27 +1656,39 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
16231656

16241657
testConditionCopy := conditions.Get(objCopy, "Test")
16251658
testConditionAfter := conditions.Get(objAfter, "Test")
1659+
if testConditionCopy == nil || testConditionAfter == nil {
1660+
return false
1661+
}
16261662
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
16271663
if err != nil || !ok {
16281664
return false
16291665
}
16301666

16311667
readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
16321668
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
1669+
if readyBefore == nil || readyAfter == nil {
1670+
return false
1671+
}
16331672
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
16341673
if err != nil || !ok {
16351674
return false
16361675
}
16371676

16381677
testV1Beta2ConditionCopy := v1beta2conditions.Get(objCopy, "Test")
16391678
testV1Beta2ConditionAfter := v1beta2conditions.Get(objAfter, "Test")
1679+
if testV1Beta2ConditionCopy == nil || testV1Beta2ConditionAfter == nil {
1680+
return false
1681+
}
16401682
ok, err = v1beta2conditions.MatchCondition(*testV1Beta2ConditionCopy).Match(*testV1Beta2ConditionAfter)
16411683
if err != nil || !ok {
16421684
return false
16431685
}
16441686

16451687
readyV1Beta2Before := v1beta2conditions.Get(obj, "Ready")
16461688
readyV1Beta2After := v1beta2conditions.Get(objAfter, "Ready")
1689+
if readyV1Beta2Before == nil || readyV1Beta2After == nil {
1690+
return false
1691+
}
16471692
ok, err = v1beta2conditions.MatchCondition(*readyV1Beta2Before).Match(*readyV1Beta2After)
16481693
if err != nil || !ok {
16491694
return false
@@ -1796,13 +1841,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
17961841

17971842
readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
17981843
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
1844+
if readyBefore == nil || readyAfter == nil {
1845+
return false
1846+
}
17991847
ok, err := conditions.MatchCondition(*readyBefore).Match(*readyAfter)
18001848
if err != nil || !ok {
18011849
return false
18021850
}
18031851

18041852
readyV1Beta2Before := v1beta2conditions.Get(obj, "Ready")
18051853
readyV1Beta2After := v1beta2conditions.Get(objAfter, "Ready")
1854+
if readyV1Beta2Before == nil || readyV1Beta2After == nil {
1855+
return false
1856+
}
18061857
ok, err = v1beta2conditions.MatchCondition(*readyV1Beta2Before).Match(*readyV1Beta2After)
18071858
if err != nil || !ok {
18081859
return false
@@ -1860,13 +1911,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
18601911

18611912
readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
18621913
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
1914+
if readyBefore == nil || readyAfter == nil {
1915+
return false
1916+
}
18631917
ok, err := conditions.MatchCondition(*readyBefore).Match(*readyAfter)
18641918
if err != nil || !ok {
18651919
return false
18661920
}
18671921

18681922
readyV1Beta2Before := v1beta2conditions.Get(obj, "Ready")
18691923
readyV1Beta2After := v1beta2conditions.Get(objAfter, "Ready")
1924+
if readyV1Beta2Before == nil || readyV1Beta2After == nil {
1925+
return false
1926+
}
18701927
ok, err = v1beta2conditions.MatchCondition(*readyV1Beta2Before).Match(*readyV1Beta2After)
18711928
if err != nil || !ok {
18721929
return false
@@ -2046,27 +2103,39 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
20462103

20472104
testBackCompatibilityCopy := conditions.Get(objCopy, "Test")
20482105
testBackCompatibilityAfter := conditions.Get(objAfter, "Test")
2106+
if testBackCompatibilityCopy == nil || testBackCompatibilityAfter == nil {
2107+
return false
2108+
}
20492109
ok, err := conditions.MatchCondition(*testBackCompatibilityCopy).Match(*testBackCompatibilityAfter)
20502110
if err != nil || !ok {
20512111
return false
20522112
}
20532113

20542114
readyBackCompatibilityBefore := conditions.Get(obj, clusterv1.ReadyCondition)
20552115
readyBackCompatibilityAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
2116+
if readyBackCompatibilityBefore == nil || readyBackCompatibilityAfter == nil {
2117+
return false
2118+
}
20562119
ok, err = conditions.MatchCondition(*readyBackCompatibilityBefore).Match(*readyBackCompatibilityAfter)
20572120
if err != nil || !ok {
20582121
return false
20592122
}
20602123

20612124
testConditionCopy := v1beta2conditions.Get(objCopy, "Test")
20622125
testConditionAfter := v1beta2conditions.Get(objAfter, "Test")
2126+
if testConditionCopy == nil || testConditionAfter == nil {
2127+
return false
2128+
}
20632129
ok, err = v1beta2conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
20642130
if err != nil || !ok {
20652131
return false
20662132
}
20672133

20682134
readyBefore := v1beta2conditions.Get(obj, "Ready")
20692135
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
2136+
if readyBefore == nil || readyAfter == nil {
2137+
return false
2138+
}
20702139
ok, err = v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
20712140
if err != nil || !ok {
20722141
return false
@@ -2127,27 +2196,39 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
21272196

21282197
testBackCompatibilityCopy := conditions.Get(objCopy, "Test")
21292198
testBackCompatibilityAfter := conditions.Get(objAfter, "Test")
2199+
if testBackCompatibilityCopy == nil || testBackCompatibilityAfter == nil {
2200+
return false
2201+
}
21302202
ok, err := conditions.MatchCondition(*testBackCompatibilityCopy).Match(*testBackCompatibilityAfter)
21312203
if err != nil || !ok {
21322204
return false
21332205
}
21342206

21352207
readyBackCompatibilityBefore := conditions.Get(obj, clusterv1.ReadyCondition)
21362208
readyBackCompatibilityAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
2209+
if readyBackCompatibilityBefore == nil || readyBackCompatibilityAfter == nil {
2210+
return false
2211+
}
21372212
ok, err = conditions.MatchCondition(*readyBackCompatibilityBefore).Match(*readyBackCompatibilityAfter)
21382213
if err != nil || !ok {
21392214
return false
21402215
}
21412216

21422217
testConditionCopy := v1beta2conditions.Get(objCopy, "Test")
21432218
testConditionAfter := v1beta2conditions.Get(objAfter, "Test")
2219+
if testConditionCopy == nil || testConditionAfter == nil {
2220+
return false
2221+
}
21442222
ok, err = v1beta2conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
21452223
if err != nil || !ok {
21462224
return false
21472225
}
21482226

21492227
readyBefore := v1beta2conditions.Get(obj, "Ready")
21502228
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
2229+
if readyBefore == nil || readyAfter == nil {
2230+
return false
2231+
}
21512232
ok, err = v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
21522233
if err != nil || !ok {
21532234
return false
@@ -2300,13 +2381,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
23002381

23012382
readyBackCompatibilityBefore := conditions.Get(obj, clusterv1.ReadyCondition)
23022383
readyBackCompatibilityAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
2384+
if readyBackCompatibilityBefore == nil || readyBackCompatibilityAfter == nil {
2385+
return false
2386+
}
23032387
ok, err := conditions.MatchCondition(*readyBackCompatibilityBefore).Match(*readyBackCompatibilityAfter)
23042388
if err != nil || !ok {
23052389
return false
23062390
}
23072391

23082392
readyBefore := v1beta2conditions.Get(obj, "Ready")
23092393
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
2394+
if readyBefore == nil || readyAfter == nil {
2395+
return false
2396+
}
23102397
ok, err = v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
23112398
if err != nil || !ok {
23122399
return false
@@ -2364,13 +2451,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
23642451

23652452
readyBackCompatibilityBefore := conditions.Get(obj, clusterv1.ReadyCondition)
23662453
readyBackCompatibilityAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
2454+
if readyBackCompatibilityBefore == nil || readyBackCompatibilityAfter == nil {
2455+
return false
2456+
}
23672457
ok, err := conditions.MatchCondition(*readyBackCompatibilityBefore).Match(*readyBackCompatibilityAfter)
23682458
if err != nil || !ok {
23692459
return false
23702460
}
23712461

23722462
readyBefore := v1beta2conditions.Get(obj, "Ready")
23732463
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
2464+
if readyBefore == nil || readyAfter == nil {
2465+
return false
2466+
}
23742467
ok, err = v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
23752468
if err != nil || !ok {
23762469
return false
@@ -2532,13 +2625,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
25322625

25332626
testConditionCopy := v1beta2conditions.Get(objCopy, "Test")
25342627
testConditionAfter := v1beta2conditions.Get(objAfter, "Test")
2628+
if testConditionCopy == nil || testConditionAfter == nil {
2629+
return false
2630+
}
25352631
ok, err := v1beta2conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
25362632
if err != nil || !ok {
25372633
return false
25382634
}
25392635

25402636
readyBefore := v1beta2conditions.Get(obj, "Ready")
25412637
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
2638+
if readyBefore == nil || readyAfter == nil {
2639+
return false
2640+
}
25422641
ok, err = v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
25432642
if err != nil || !ok {
25442643
return false
@@ -2597,13 +2696,19 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
25972696

25982697
testConditionCopy := v1beta2conditions.Get(objCopy, "Test")
25992698
testConditionAfter := v1beta2conditions.Get(objAfter, "Test")
2699+
if testConditionCopy == nil || testConditionAfter == nil {
2700+
return false
2701+
}
26002702
ok, err := v1beta2conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
26012703
if err != nil || !ok {
26022704
return false
26032705
}
26042706

26052707
readyBefore := v1beta2conditions.Get(obj, "Ready")
26062708
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
2709+
if readyBefore == nil || readyAfter == nil {
2710+
return false
2711+
}
26072712
ok, err = v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
26082713
if err != nil || !ok {
26092714
return false
@@ -2707,6 +2812,9 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
27072812

27082813
readyBefore := v1beta2conditions.Get(obj, "Ready")
27092814
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
2815+
if readyBefore == nil || readyAfter == nil {
2816+
return false
2817+
}
27102818
ok, err := v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
27112819
if err != nil || !ok {
27122820
return false
@@ -2762,6 +2870,9 @@ func TestPatchHelperForV1beta2Transition(t *testing.T) {
27622870

27632871
readyBefore := v1beta2conditions.Get(obj, "Ready")
27642872
readyAfter := v1beta2conditions.Get(objAfter, "Ready")
2873+
if readyBefore == nil || readyAfter == nil {
2874+
return false
2875+
}
27652876
ok, err := v1beta2conditions.MatchCondition(*readyBefore).Match(*readyAfter)
27662877
if err != nil || !ok {
27672878
return false

0 commit comments

Comments
 (0)