@@ -489,3 +489,61 @@ func TestCreateServiceImportStruct(t *testing.T) {
489
489
})
490
490
}
491
491
}
492
+
493
+ func TestExtractServiceType (t * testing.T ) {
494
+ tests := []struct {
495
+ name string
496
+ svc * v1.Service
497
+ want model.ServiceType
498
+ }{
499
+ {
500
+ name : "cluster ip type" ,
501
+ svc : & v1.Service {
502
+ TypeMeta : metav1.TypeMeta {},
503
+ ObjectMeta : metav1.ObjectMeta {
504
+ Name : test .SvcName ,
505
+ Namespace : test .HttpNsName ,
506
+ },
507
+ Spec : v1.ServiceSpec {
508
+ Ports : []v1.ServicePort {{
509
+ Name : test .PortName1 ,
510
+ Protocol : test .Protocol1 ,
511
+ Port : test .ServicePort1 ,
512
+ TargetPort : intstr.IntOrString {Type : intstr .Int , IntVal : test .Port1 },
513
+ }},
514
+ ClusterIP : "10.108.89.43" ,
515
+ },
516
+ Status : v1.ServiceStatus {},
517
+ },
518
+ want : model .ClusterSetIPType ,
519
+ },
520
+ {
521
+ name : "headless type" ,
522
+ svc : & v1.Service {
523
+ TypeMeta : metav1.TypeMeta {},
524
+ ObjectMeta : metav1.ObjectMeta {
525
+ Name : test .SvcName ,
526
+ Namespace : test .HttpNsName ,
527
+ },
528
+ Spec : v1.ServiceSpec {
529
+ Ports : []v1.ServicePort {{
530
+ Name : test .PortName1 ,
531
+ Protocol : test .Protocol1 ,
532
+ Port : test .ServicePort1 ,
533
+ TargetPort : intstr.IntOrString {Type : intstr .Int , IntVal : test .Port1 },
534
+ }},
535
+ ClusterIP : "None" ,
536
+ },
537
+ Status : v1.ServiceStatus {},
538
+ },
539
+ want : model .HeadlessType ,
540
+ },
541
+ }
542
+ for _ , tt := range tests {
543
+ t .Run (tt .name , func (t * testing.T ) {
544
+ if got := ExtractServiceType (tt .svc ); got != tt .want {
545
+ t .Errorf ("ExtractServiceType() = %v, want %v" , got , tt .want )
546
+ }
547
+ })
548
+ }
549
+ }
0 commit comments