@@ -36,6 +36,110 @@ func TestRouter(t *testing.T) {
3636 args fakeRouter
3737 want map [string ][]objref.KMetadata
3838 }{
39+ {
40+ name : "self" ,
41+ args : fakeRouter {
42+ Services : []* corev1.Service {
43+ {
44+ ObjectMeta : metav1.ObjectMeta {
45+ Name : "svc1" ,
46+ Namespace : "test" ,
47+ },
48+ Spec : corev1.ServiceSpec {
49+ Ports : []corev1.ServicePort {
50+ {
51+ Name : "http" ,
52+ Port : 80 ,
53+ Protocol : corev1 .ProtocolTCP ,
54+ },
55+ },
56+ },
57+ },
58+ },
59+ Hubs : []* v1alpha2.Hub {
60+ {
61+ ObjectMeta : metav1.ObjectMeta {
62+ Name : "self" ,
63+ },
64+ Spec : v1alpha2.HubSpec {
65+ Gateway : v1alpha2.HubSpecGateway {
66+ Reachable : true ,
67+ Address : "10.0.0.1:8080" ,
68+ },
69+ },
70+ },
71+ },
72+ Routes : []* v1alpha2.Route {
73+ {
74+ ObjectMeta : metav1.ObjectMeta {
75+ Name : "svc1" ,
76+ Namespace : "test" ,
77+ },
78+ Spec : v1alpha2.RouteSpec {
79+ Import : v1alpha2.RouteSpecRule {
80+ HubName : "self" ,
81+ Service : v1alpha2.RouteSpecRuleService {
82+ Name : "svc1-new" ,
83+ Namespace : "test" ,
84+ },
85+ },
86+ Export : v1alpha2.RouteSpecRule {
87+ HubName : "self" ,
88+ Service : v1alpha2.RouteSpecRuleService {
89+ Name : "svc1" ,
90+ Namespace : "test" ,
91+ },
92+ },
93+ },
94+ },
95+ },
96+ },
97+
98+ want : map [string ][]objref.KMetadata {
99+ "self" : {
100+ & corev1.ConfigMap {
101+ ObjectMeta : metav1.ObjectMeta {
102+ Name : "svc1-service" ,
103+ Namespace : "ferry-tunnel-system" ,
104+ Labels : map [string ]string {
105+ "tunnel.ferryproxy.io/config" : "service" ,
106+ },
107+ },
108+ Data : map [string ]string {
109+ "export_hub_name" : "self" ,
110+ "export_service_name" : "svc1" ,
111+ "export_service_namespace" : "test" ,
112+ "import_service_name" : "svc1-new" ,
113+ "import_service_namespace" : "test" ,
114+ "ports" : `[{"name":"http","protocol":"TCP","port":80,"targetPort":10001}]` ,
115+ },
116+ },
117+ & corev1.ConfigMap {
118+ ObjectMeta : metav1.ObjectMeta {
119+ Name : "svc1-tunnel-80-10001" ,
120+ Namespace : "ferry-tunnel-system" ,
121+ Labels : map [string ]string {
122+ "tunnel.ferryproxy.io/config" : "rules" ,
123+ },
124+ },
125+ Data : map [string ]string {
126+ consts .TunnelRulesKey : toJson (
127+ []Chain {
128+ {
129+ Bind : []string {
130+ ":10001" ,
131+ },
132+ Proxy : []string {
133+ "svc1.test.svc:80" ,
134+ },
135+ },
136+ },
137+ ),
138+ },
139+ },
140+ },
141+ },
142+ },
39143 {
40144 name : "export reachable" ,
41145 args : fakeRouter {
@@ -104,7 +208,7 @@ func TestRouter(t *testing.T) {
104208 },
105209 Spec : v1alpha2.RouteSpec {
106210 Import : v1alpha2.RouteSpecRule {
107- HubName : "export " ,
211+ HubName : "import " ,
108212 Service : v1alpha2.RouteSpecRuleService {
109213 Name : "svc1" ,
110214 Namespace : "test" ,
@@ -275,7 +379,7 @@ func TestRouter(t *testing.T) {
275379 },
276380 Spec : v1alpha2.RouteSpec {
277381 Import : v1alpha2.RouteSpecRule {
278- HubName : "export " ,
382+ HubName : "import " ,
279383 Service : v1alpha2.RouteSpecRuleService {
280384 Name : "svc1" ,
281385 Namespace : "test" ,
@@ -448,7 +552,7 @@ func TestRouter(t *testing.T) {
448552 },
449553 Spec : v1alpha2.RouteSpec {
450554 Import : v1alpha2.RouteSpecRule {
451- HubName : "export " ,
555+ HubName : "import " ,
452556 Service : v1alpha2.RouteSpecRuleService {
453557 Name : "svc1" ,
454558 Namespace : "test" ,
@@ -634,22 +738,21 @@ func (f *fakeRouter) BuildResource() (out map[string][]objref.KMetadata, err err
634738 portCache : map [string ]int {},
635739 }
636740
637- exportHubName := "export"
638- importHubName := "import"
741+ route := f .Routes [0 ]
639742
640743 solution := Solution {
641744 getHubGateway : fake .GetHubGateway ,
642745 }
643746
644- ways , err := solution .CalculateWays (exportHubName , importHubName )
747+ ways , err := solution .CalculateWays (route . Spec . Export . HubName , route . Spec . Import . HubName )
645748 if err != nil {
646749 return nil , err
647750 }
648751
649752 router := NewRouter (RouterConfig {
650753 Labels : map [string ]string {},
651- ExportHubName : exportHubName ,
652- ImportHubName : importHubName ,
754+ ExportHubName : route . Spec . Export . HubName ,
755+ ImportHubName : route . Spec . Import . HubName ,
653756 HubInterface : fake ,
654757 })
655758
0 commit comments