@@ -10,45 +10,88 @@ import (
1010
1111func TestIngress (t * testing.T ) {
1212 tests := []struct {
13- name string
14- hosts []string
15- expHosts []string
13+ name string
14+ chartVersion string
15+ hosts []string
16+ expHosts []string
1617 }{
1718 {
18- name : "nil hosts" ,
19- hosts : nil ,
20- expHosts : []string {"" },
19+ name : "nil hosts v1" ,
20+ chartVersion : "1.9.9" ,
21+ hosts : nil ,
22+ expHosts : []string {"" },
2123 },
2224 {
23- name : "empty hosts" ,
24- hosts : []string {},
25- expHosts : []string {"" },
25+ name : "empty hosts v1" ,
26+ chartVersion : "1.9.9" ,
27+ hosts : []string {},
28+ expHosts : []string {"" },
2629 },
2730 {
28- name : "single new host" ,
29- hosts : []string {"example.test" },
30- expHosts : []string {"example.test" , "localhost" , "host.docker.internal" },
31+ name : "single new host v1" ,
32+ chartVersion : "1.9.9" ,
33+ hosts : []string {"example.test" },
34+ expHosts : []string {"example.test" , "localhost" , "host.docker.internal" },
3135 },
3236 {
33- name : "localhost" ,
34- hosts : []string {"localhost" },
35- expHosts : []string {"localhost" , "host.docker.internal" },
37+ name : "localhost v1" ,
38+ chartVersion : "1.9.9" ,
39+ hosts : []string {"localhost" },
40+ expHosts : []string {"localhost" , "host.docker.internal" },
3641 },
3742 {
38- name : "host.docker.internal" ,
39- hosts : []string {"host.docker.internal" },
40- expHosts : []string {"localhost" , "host.docker.internal" },
43+ name : "host.docker.internal v1" ,
44+ chartVersion : "1.9.9" ,
45+ hosts : []string {"host.docker.internal" },
46+ expHosts : []string {"localhost" , "host.docker.internal" },
4147 },
4248 {
43- name : "multiple new hosts" ,
44- hosts : []string {"abc.test" , "xyz.test" },
45- expHosts : []string {"abc.test" , "localhost" , "host.docker.internal" , "xyz.test" },
49+ name : "multiple new hosts v1" ,
50+ chartVersion : "1.9.9" ,
51+ hosts : []string {"abc.test" , "xyz.test" },
52+ expHosts : []string {"abc.test" , "localhost" , "host.docker.internal" , "xyz.test" },
53+ },
54+ {
55+ name : "nil hosts v2" ,
56+ chartVersion : "2.0.0" ,
57+ hosts : nil ,
58+ expHosts : []string {"" },
59+ },
60+ {
61+ name : "empty hosts v2" ,
62+ chartVersion : "2.0.0" ,
63+ hosts : []string {},
64+ expHosts : []string {"" },
65+ },
66+ {
67+ name : "single new host v2" ,
68+ chartVersion : "2.0.0" ,
69+ hosts : []string {"example.test" },
70+ expHosts : []string {"example.test" , "localhost" , "host.docker.internal" },
71+ },
72+ {
73+ name : "localhost v2" ,
74+ chartVersion : "2.0.0" ,
75+ hosts : []string {"localhost" },
76+ expHosts : []string {"localhost" , "host.docker.internal" },
77+ },
78+ {
79+ name : "host.docker.internal v2" ,
80+ chartVersion : "2.0.0" ,
81+ hosts : []string {"host.docker.internal" },
82+ expHosts : []string {"localhost" , "host.docker.internal" },
83+ },
84+ {
85+ name : "multiple new hosts v2" ,
86+ chartVersion : "2.0.0" ,
87+ hosts : []string {"abc.test" , "xyz.test" },
88+ expHosts : []string {"abc.test" , "localhost" , "host.docker.internal" , "xyz.test" },
4689 },
4790 }
4891
4992 for _ , tt := range tests {
5093 t .Run (tt .name , func (t * testing.T ) {
51- actHosts := extractHosts (Ingress (tt .hosts ))
94+ actHosts := extractHosts (Ingress (tt .chartVersion , tt . hosts ))
5295 sort .Strings (actHosts )
5396 sort .Strings (tt .expHosts )
5497 if d := cmp .Diff (tt .expHosts , actHosts ); d != "" {
@@ -66,3 +109,51 @@ func extractHosts(ingress *networkingv1.Ingress) []string {
66109 }
67110 return hosts
68111}
112+
113+ func TestIngressRouting (t * testing.T ) {
114+ tests := []struct {
115+ name string
116+ chartVersion string
117+ wantService string
118+ }{
119+ {
120+ name : "v1 routes to webapp" ,
121+ chartVersion : "1.9.9" ,
122+ wantService : "airbyte-abctl-airbyte-webapp-svc" ,
123+ },
124+ {
125+ name : "v2 routes to server" ,
126+ chartVersion : "2.0.0" ,
127+ wantService : "airbyte-abctl-airbyte-server-svc" ,
128+ },
129+ }
130+
131+ for _ , tt := range tests {
132+ t .Run (tt .name , func (t * testing.T ) {
133+ ingress := Ingress (tt .chartVersion , []string {"localhost" })
134+
135+ // Get the default route (path: "/")
136+ var defaultRoute * networkingv1.HTTPIngressPath
137+ for _ , rule := range ingress .Spec .Rules {
138+ for _ , path := range rule .HTTP .Paths {
139+ if path .Path == "/" {
140+ defaultRoute = & path
141+ break
142+ }
143+ }
144+ if defaultRoute != nil {
145+ break
146+ }
147+ }
148+
149+ if defaultRoute == nil {
150+ t .Fatal ("default route (/) not found" )
151+ }
152+
153+ gotService := defaultRoute .Backend .Service .Name
154+ if gotService != tt .wantService {
155+ t .Errorf ("wrong service for default route: got %s, want %s" , gotService , tt .wantService )
156+ }
157+ })
158+ }
159+ }
0 commit comments