forked from banzaicloud/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
87 lines (80 loc) · 1.92 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"testing"
"k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/util/intstr"
"reflect"
"fmt"
)
func TestIngressEndpointUrls(t *testing.T) {
// given
ingress := &v1beta1.Ingress {
Spec: v1beta1.IngressSpec {
Backend: &v1beta1.IngressBackend {},
TLS: []v1beta1.IngressTLS {},
Rules: []v1beta1.IngressRule {
{
Host:"",
IngressRuleValue: v1beta1.IngressRuleValue{
HTTP: &v1beta1.HTTPIngressRuleValue {
Paths: []v1beta1.HTTPIngressPath {
{
Path: "/svc1_path1",
Backend: v1beta1.IngressBackend{
ServiceName: "service1",
ServicePort: intstr.FromInt(1000),
},
},
{
Path: "/svc1_path2",
Backend: v1beta1.IngressBackend{
ServiceName: "service1",
ServicePort: intstr.FromInt(1000),
},
},
},
},
},
},
{
Host:"",
IngressRuleValue: v1beta1.IngressRuleValue{
HTTP: &v1beta1.HTTPIngressRuleValue {
Paths: []v1beta1.HTTPIngressPath {
{
Path: "/svc1_ui",
Backend: v1beta1.IngressBackend{
ServiceName: "service1",
ServicePort: intstr.FromInt(1000),
},
},
},
},
},
},
},
},
Status: v1beta1.IngressStatus {},
}
loadBalancerPublicHost := "lb.url.com"
expectedEndpoints := []EndPointURLs {
{
ServiceName: "svc1_path1",
URL: fmt.Sprint("http://",loadBalancerPublicHost, "/svc1_path1/"),
},
{
ServiceName: "svc1_path2",
URL: fmt.Sprint("http://",loadBalancerPublicHost, "/svc1_path2/"),
},
{
ServiceName: "svc1_ui",
URL: fmt.Sprint("http://",loadBalancerPublicHost, "/svc1_ui/"),
},
}
// when
actualEndpoints := getIngressEndpoints(loadBalancerPublicHost, ingress)
// then
if !reflect.DeepEqual(expectedEndpoints, actualEndpoints) {
t.Errorf("Expected: %v, got: %v", expectedEndpoints, actualEndpoints)
}
}