@@ -549,3 +549,79 @@ func (s *fakeProxyServerError) Run() error {
549
549
return fmt .Errorf ("mocking error from ProxyServer.Run()" )
550
550
}
551
551
}
552
+
553
+ func TestAddressFromDeprecatedFlags (t * testing.T ) {
554
+ testCases := []struct {
555
+ name string
556
+ healthzPort int32
557
+ healthzBindAddress string
558
+ metricsPort int32
559
+ metricsBindAddress string
560
+ expHealthz string
561
+ expMetrics string
562
+ }{
563
+ {
564
+ name : "IPv4 bind address" ,
565
+ healthzBindAddress : "1.2.3.4" ,
566
+ healthzPort : 12345 ,
567
+ metricsBindAddress : "2.3.4.5" ,
568
+ metricsPort : 23456 ,
569
+ expHealthz : "1.2.3.4:12345" ,
570
+ expMetrics : "2.3.4.5:23456" ,
571
+ },
572
+ {
573
+ name : "IPv4 bind address has port" ,
574
+ healthzBindAddress : "1.2.3.4:12345" ,
575
+ healthzPort : 23456 ,
576
+ metricsBindAddress : "2.3.4.5:12345" ,
577
+ metricsPort : 23456 ,
578
+ expHealthz : "1.2.3.4:12345" ,
579
+ expMetrics : "2.3.4.5:12345" ,
580
+ },
581
+ {
582
+ name : "IPv6 bind address" ,
583
+ healthzBindAddress : "fd00:1::5" ,
584
+ healthzPort : 12345 ,
585
+ metricsBindAddress : "fd00:1::6" ,
586
+ metricsPort : 23456 ,
587
+ expHealthz : "[fd00:1::5]:12345" ,
588
+ expMetrics : "[fd00:1::6]:23456" ,
589
+ },
590
+ {
591
+ name : "IPv6 bind address has port" ,
592
+ healthzBindAddress : "[fd00:1::5]:12345" ,
593
+ healthzPort : 56789 ,
594
+ metricsBindAddress : "[fd00:1::6]:56789" ,
595
+ metricsPort : 12345 ,
596
+ expHealthz : "[fd00:1::5]:12345" ,
597
+ expMetrics : "[fd00:1::6]:56789" ,
598
+ },
599
+ {
600
+ name : "Invalid IPv6 Config" ,
601
+ healthzBindAddress : "[fd00:1::5]" ,
602
+ healthzPort : 12345 ,
603
+ metricsBindAddress : "[fd00:1::6]" ,
604
+ metricsPort : 56789 ,
605
+ expHealthz : "[fd00:1::5]" ,
606
+ expMetrics : "[fd00:1::6]" ,
607
+ },
608
+ }
609
+
610
+ for i := range testCases {
611
+ gotHealthz := addressFromDeprecatedFlags (testCases [i ].healthzBindAddress , testCases [i ].healthzPort )
612
+ gotMetrics := addressFromDeprecatedFlags (testCases [i ].metricsBindAddress , testCases [i ].metricsPort )
613
+
614
+ errFn := func (name , except , got string ) {
615
+ t .Errorf ("case %s: expected %v, got %v" , name , except , got )
616
+ }
617
+
618
+ if gotHealthz != testCases [i ].expHealthz {
619
+ errFn (testCases [i ].name , testCases [i ].expHealthz , gotHealthz )
620
+ }
621
+
622
+ if gotMetrics != testCases [i ].expMetrics {
623
+ errFn (testCases [i ].name , testCases [i ].expMetrics , gotMetrics )
624
+ }
625
+
626
+ }
627
+ }
0 commit comments