@@ -334,6 +334,18 @@ func Test_ReadyChecker_podsReadyForObject(t *testing.T) {
334
334
want : false ,
335
335
wantErr : false ,
336
336
},
337
+ {
338
+ name : "ReplicaSet not set" ,
339
+ args : args {
340
+ namespace : defaultNamespace ,
341
+ obj : nil ,
342
+ },
343
+ existPods : []corev1.Pod {
344
+ * newPodWithCondition ("foo" , corev1 .ConditionFalse ),
345
+ },
346
+ want : false ,
347
+ wantErr : true ,
348
+ },
337
349
}
338
350
for _ , tt := range tests {
339
351
t .Run (tt .name , func (t * testing.T ) {
@@ -463,6 +475,52 @@ func Test_ReadyChecker_volumeReady(t *testing.T) {
463
475
}
464
476
}
465
477
478
+ func Test_ReadyChecker_serviceReady (t * testing.T ) {
479
+ type args struct {
480
+ service * corev1.Service
481
+ }
482
+ tests := []struct {
483
+ name string
484
+ args args
485
+ want bool
486
+ }{
487
+ {
488
+ name : "service type is of external name" ,
489
+ args : args {service : newService ("foo" , corev1.ServiceSpec {Type : corev1 .ServiceTypeExternalName , ClusterIP : "" })},
490
+ want : true ,
491
+ },
492
+ {
493
+ name : "service cluster ip is empty" ,
494
+ args : args {service : newService ("foo" , corev1.ServiceSpec {Type : corev1 .ServiceTypeLoadBalancer , ClusterIP : "" })},
495
+ want : false ,
496
+ },
497
+ {
498
+ name : "service has a cluster ip that is greater than 0" ,
499
+ args : args {service : newService ("foo" , corev1.ServiceSpec {Type : corev1 .ServiceTypeLoadBalancer , ClusterIP : "bar" , ExternalIPs : []string {"bar" }})},
500
+ want : true ,
501
+ },
502
+ {
503
+ name : "service has a cluster ip that is less than 0 and ingress is nil" ,
504
+ args : args {service : newService ("foo" , corev1.ServiceSpec {Type : corev1 .ServiceTypeLoadBalancer , ClusterIP : "bar" })},
505
+ want : false ,
506
+ },
507
+ {
508
+ name : "service has a cluster ip that is less than 0 and ingress is nil" ,
509
+ args : args {service : newService ("foo" , corev1.ServiceSpec {Type : corev1 .ServiceTypeClusterIP , ClusterIP : "bar" })},
510
+ want : true ,
511
+ },
512
+ }
513
+ for _ , tt := range tests {
514
+ t .Run (tt .name , func (t * testing.T ) {
515
+ c := NewReadyChecker (fake .NewSimpleClientset (), nil )
516
+ got := c .serviceReady (tt .args .service )
517
+ if got != tt .want {
518
+ t .Errorf ("serviceReady() = %v, want %v" , got , tt .want )
519
+ }
520
+ })
521
+ }
522
+ }
523
+
466
524
func newStatefulSetWithUpdateRevision (name string , replicas , partition , readyReplicas , updatedReplicas int , updateRevision string , generationInSync bool ) * appsv1.StatefulSet {
467
525
ss := newStatefulSet (name , replicas , partition , readyReplicas , updatedReplicas , generationInSync )
468
526
ss .Status .UpdateRevision = updateRevision
@@ -699,6 +757,21 @@ func newJob(name string, backoffLimit int, completions *int32, succeeded int, fa
699
757
}
700
758
}
701
759
760
+ func newService (name string , serviceSpec corev1.ServiceSpec ) * corev1.Service {
761
+ return & corev1.Service {
762
+ ObjectMeta : metav1.ObjectMeta {
763
+ Name : name ,
764
+ Namespace : defaultNamespace ,
765
+ },
766
+ Spec : serviceSpec ,
767
+ Status : corev1.ServiceStatus {
768
+ LoadBalancer : corev1.LoadBalancerStatus {
769
+ Ingress : nil ,
770
+ },
771
+ },
772
+ }
773
+ }
774
+
702
775
func intToInt32 (i int ) * int32 {
703
776
i32 := int32 (i )
704
777
return & i32
0 commit comments