@@ -2468,6 +2468,149 @@ func TestGetBackendServers(t *testing.T) {
2468
2468
}
2469
2469
},
2470
2470
},
2471
+ {
2472
+ Ingresses : []* ingress.Ingress {
2473
+ {
2474
+ Ingress : networking.Ingress {
2475
+ ObjectMeta : metav1.ObjectMeta {
2476
+ Namespace : "example" ,
2477
+ },
2478
+ Spec : networking.IngressSpec {
2479
+ Rules : []networking.IngressRule {
2480
+ {
2481
+ Host : "example.com" ,
2482
+ IngressRuleValue : networking.IngressRuleValue {
2483
+ HTTP : & networking.HTTPIngressRuleValue {
2484
+ Paths : []networking.HTTPIngressPath {
2485
+ {
2486
+ Path : "/a" ,
2487
+ PathType : & pathTypeExact ,
2488
+ Backend : networking.IngressBackend {
2489
+ Service : & networking.IngressServiceBackend {
2490
+ Name : "http-svc-1" ,
2491
+ Port : networking.ServiceBackendPort {
2492
+ Number : 80 ,
2493
+ },
2494
+ },
2495
+ },
2496
+ },
2497
+ },
2498
+ },
2499
+ },
2500
+ },
2501
+ },
2502
+ },
2503
+ },
2504
+ ParsedAnnotations : & annotations.Ingress {},
2505
+ },
2506
+ {
2507
+ Ingress : networking.Ingress {
2508
+ ObjectMeta : metav1.ObjectMeta {
2509
+ Namespace : "example" ,
2510
+ },
2511
+ Spec : networking.IngressSpec {
2512
+ Rules : []networking.IngressRule {
2513
+ {
2514
+ Host : "example.com" ,
2515
+ IngressRuleValue : networking.IngressRuleValue {
2516
+ HTTP : & networking.HTTPIngressRuleValue {
2517
+ Paths : []networking.HTTPIngressPath {
2518
+ {
2519
+ Path : "/a" ,
2520
+ PathType : & pathTypePrefix ,
2521
+ Backend : networking.IngressBackend {
2522
+ Service : & networking.IngressServiceBackend {
2523
+ Name : "http-svc-2" ,
2524
+ Port : networking.ServiceBackendPort {
2525
+ Number : 80 ,
2526
+ },
2527
+ },
2528
+ },
2529
+ },
2530
+ },
2531
+ },
2532
+ },
2533
+ },
2534
+ },
2535
+ },
2536
+ },
2537
+ ParsedAnnotations : & annotations.Ingress {},
2538
+ },
2539
+ {
2540
+ Ingress : networking.Ingress {
2541
+ ObjectMeta : metav1.ObjectMeta {
2542
+ Namespace : "example" ,
2543
+ },
2544
+ Spec : networking.IngressSpec {
2545
+ Rules : []networking.IngressRule {
2546
+ {
2547
+ Host : "example.com" ,
2548
+ IngressRuleValue : networking.IngressRuleValue {
2549
+ HTTP : & networking.HTTPIngressRuleValue {
2550
+ Paths : []networking.HTTPIngressPath {
2551
+ {
2552
+ Path : "/a" ,
2553
+ PathType : & pathTypePrefix ,
2554
+ Backend : networking.IngressBackend {
2555
+ Service : & networking.IngressServiceBackend {
2556
+ Name : "http-svc-3" ,
2557
+ Port : networking.ServiceBackendPort {
2558
+ Number : 80 ,
2559
+ },
2560
+ },
2561
+ },
2562
+ },
2563
+ },
2564
+ },
2565
+ },
2566
+ },
2567
+ },
2568
+ },
2569
+ },
2570
+ ParsedAnnotations : & annotations.Ingress {},
2571
+ },
2572
+ },
2573
+ Validate : func (ingresses []* ingress.Ingress , upstreams []* ingress.Backend , servers []* ingress.Server ) {
2574
+ if len (servers ) != 2 {
2575
+ t .Errorf ("servers count should be 2, got %d" , len (servers ))
2576
+ return
2577
+ }
2578
+
2579
+ s := servers [0 ]
2580
+ if s .Hostname != "_" {
2581
+ t .Errorf ("server hostname should be '_', got '%s'" , s .Hostname )
2582
+ }
2583
+ if len (s .Locations ) != 1 {
2584
+ t .Errorf ("servers locations count should be 1, got %d" , len (s .Locations ))
2585
+ return
2586
+ }
2587
+ if ! s .Locations [0 ].IsDefBackend {
2588
+ t .Errorf ("server location 0 should be default backend" )
2589
+ }
2590
+ if s .Locations [0 ].Backend != defUpstreamName {
2591
+ t .Errorf ("location backend should be '%s', got '%s'" , defUpstreamName , s .Locations [0 ].Backend )
2592
+ }
2593
+
2594
+ s = servers [1 ]
2595
+ if s .Hostname != "example.com" {
2596
+ t .Errorf ("server hostname should be 'example.com', got '%s'" , s .Hostname )
2597
+ }
2598
+ if len (s .Locations ) != 3 {
2599
+ t .Errorf ("servers locations count should be 2, got %d" , len (s .Locations ))
2600
+ return
2601
+ }
2602
+ if s .Locations [0 ].Backend != "example-http-svc-1-80" {
2603
+ t .Errorf ("location 0 backend should be 'example-http-svc-1-80', got '%s'" , s .Locations [0 ].Backend )
2604
+ }
2605
+ if s .Locations [1 ].Backend != "example-http-svc-2-80" {
2606
+ t .Errorf ("location 1 backend should be 'example-http-svc-2-80', got '%s'" , s .Locations [1 ].Backend )
2607
+ }
2608
+ if s .Locations [2 ].Backend != defUpstreamName {
2609
+ t .Errorf ("location 2 backend should be '%s', got '%s'" , defUpstreamName , s .Locations [2 ].Backend )
2610
+ }
2611
+ },
2612
+ SetConfigMap : testConfigMap ,
2613
+ },
2471
2614
}
2472
2615
2473
2616
for _ , testCase := range testCases {
0 commit comments