@@ -60,8 +60,7 @@ var _ = Describe("Test ApisixRoute", Label("apisix.apache.org", "v2", "apisixrou
6060 })
6161
6262 Context ("Test ApisixRoute" , func () {
63-
64- It ("Basic tests" , func () {
63+ Context ("Basic tests" , func () {
6564 const apisixRouteSpec = `
6665apiVersion: apisix.apache.org/v2
6766kind: ApisixRoute
@@ -81,59 +80,111 @@ spec:
8180 - serviceName: httpbin-service-e2e-test
8281 servicePort: 80
8382`
84- request := func (path string ) int {
85- return s .NewAPISIXClient ().GET (path ).WithHost ("httpbin" ).Expect ().Raw ().StatusCode
86- }
8783
88- By ("apply ApisixRoute" )
89- var apisixRoute apiv2.ApisixRoute
90- applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" },
91- & apisixRoute , fmt .Sprintf (apisixRouteSpec , s .Namespace (), s .Namespace (), "/get" ))
84+ const apisixRouteSpecWithNameServiceAndGranularity = `
85+ apiVersion: apisix.apache.org/v2
86+ kind: ApisixRoute
87+ metadata:
88+ name: default
89+ namespace: %s
90+ spec:
91+ ingressClassName: %s
92+ http:
93+ - name: rule0
94+ match:
95+ hosts:
96+ - httpbin
97+ paths:
98+ - %s
99+ backends:
100+ - serviceName: httpbin-service-e2e-test
101+ servicePort: http
102+ resolveGranularity: service
103+ `
92104
93- By ("verify ApisixRoute works" )
94- Eventually (request ).WithArguments ("/get" ).WithTimeout (20 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusOK ))
105+ const apisixRouteSpecWithNameServicePort = `
106+ apiVersion: apisix.apache.org/v2
107+ kind: ApisixRoute
108+ metadata:
109+ name: default
110+ namespace: %s
111+ spec:
112+ ingressClassName: %s
113+ http:
114+ - name: rule0
115+ match:
116+ hosts:
117+ - httpbin
118+ paths:
119+ - %s
120+ backends:
121+ - serviceName: httpbin-service-e2e-test
122+ servicePort: http
123+ `
124+ test := func (apisixRouteSpec string ) {
125+ request := func (path string ) int {
126+ return s .NewAPISIXClient ().GET (path ).WithHost ("httpbin" ).Expect ().Raw ().StatusCode
127+ }
95128
96- By ("update ApisixRoute" )
97- applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" },
98- & apisixRoute , fmt .Sprintf (apisixRouteSpec , s .Namespace (), s .Namespace (), "/headers" ))
99- Eventually (request ).WithArguments ("/get" ).WithTimeout (20 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
100- s .NewAPISIXClient ().GET ("/headers" ).WithHost ("httpbin" ).Expect ().Status (http .StatusOK )
129+ By ("apply ApisixRoute" )
130+ var apisixRoute apiv2.ApisixRoute
131+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" },
132+ & apisixRoute , fmt .Sprintf (apisixRouteSpec , s .Namespace (), s .Namespace (), "/get" ))
101133
102- By ("delete ApisixRoute" )
103- err := s .DeleteResource ("ApisixRoute" , "default" )
104- Expect (err ).ShouldNot (HaveOccurred (), "deleting ApisixRoute" )
105- Eventually (request ).WithArguments ("/headers" ).WithTimeout (20 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
134+ By ("verify ApisixRoute works" )
135+ Eventually (request ).WithArguments ("/get" ).WithTimeout (20 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusOK ))
106136
107- By ("request /metrics endpoint from controller" )
137+ By ("update ApisixRoute" )
138+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" },
139+ & apisixRoute , fmt .Sprintf (apisixRouteSpec , s .Namespace (), s .Namespace (), "/headers" ))
140+ Eventually (request ).WithArguments ("/get" ).WithTimeout (20 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
141+ s .NewAPISIXClient ().GET ("/headers" ).WithHost ("httpbin" ).Expect ().Status (http .StatusOK )
108142
109- // Get the metrics service endpoint
110- metricsURL := s .GetMetricsEndpoint ()
143+ By ("delete ApisixRoute" )
144+ err := s .DeleteResource ("ApisixRoute" , "default" )
145+ Expect (err ).ShouldNot (HaveOccurred (), "deleting ApisixRoute" )
146+ Eventually (request ).WithArguments ("/headers" ).WithTimeout (20 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
111147
112- By ("verify metrics content" )
113- resp , err := http .Get (metricsURL )
114- Expect (err ).ShouldNot (HaveOccurred (), "request metrics endpoint" )
115- defer func () {
116- _ = resp .Body .Close ()
117- }()
148+ By ("request /metrics endpoint from controller" )
118149
119- Expect (resp .StatusCode ).Should (Equal (http .StatusOK ))
150+ // Get the metrics service endpoint
151+ metricsURL := s .GetMetricsEndpoint ()
152+
153+ By ("verify metrics content" )
154+ resp , err := http .Get (metricsURL )
155+ Expect (err ).ShouldNot (HaveOccurred (), "request metrics endpoint" )
156+ defer func () {
157+ _ = resp .Body .Close ()
158+ }()
120159
121- body , err := io .ReadAll (resp .Body )
122- Expect (err ).ShouldNot (HaveOccurred (), "read metrics response" )
160+ Expect (resp .StatusCode ).Should (Equal (http .StatusOK ))
123161
124- bodyStr := string (body )
162+ body , err := io .ReadAll (resp .Body )
163+ Expect (err ).ShouldNot (HaveOccurred (), "read metrics response" )
125164
126- // Verify prometheus format
127- Expect (resp .Header .Get ("Content-Type" )).Should (ContainSubstring ("text/plain; version=0.0.4; charset=utf-8" ))
165+ bodyStr := string (body )
128166
129- // Verify specific metrics from metrics.go exist
130- Expect (bodyStr ).Should (ContainSubstring ("apisix_ingress_adc_sync_duration_seconds" ))
131- Expect (bodyStr ).Should (ContainSubstring ("apisix_ingress_adc_sync_total" ))
132- Expect (bodyStr ).Should (ContainSubstring ("apisix_ingress_status_update_queue_length" ))
133- Expect (bodyStr ).Should (ContainSubstring ("apisix_ingress_file_io_duration_seconds" ))
167+ // Verify prometheus format
168+ Expect (resp .Header .Get ("Content-Type" )).Should (ContainSubstring ("text/plain; version=0.0.4; charset=utf-8" ))
134169
135- // Log metrics for debugging
136- fmt .Printf ("Metrics endpoint response:\n %s\n " , bodyStr )
170+ // Verify specific metrics from metrics.go exist
171+ Expect (bodyStr ).Should (ContainSubstring ("apisix_ingress_adc_sync_duration_seconds" ))
172+ Expect (bodyStr ).Should (ContainSubstring ("apisix_ingress_adc_sync_total" ))
173+ Expect (bodyStr ).Should (ContainSubstring ("apisix_ingress_status_update_queue_length" ))
174+ Expect (bodyStr ).Should (ContainSubstring ("apisix_ingress_file_io_duration_seconds" ))
175+
176+ // Log metrics for debugging
177+ fmt .Printf ("Metrics endpoint response:\n %s\n " , bodyStr )
178+ }
179+ It ("Basic" , func () {
180+ test (apisixRouteSpec )
181+ })
182+ It ("Basic: with named service port" , func () {
183+ test (apisixRouteSpecWithNameServicePort )
184+ })
185+ It ("Basic: with named service port and granularity service" , func () {
186+ test (apisixRouteSpecWithNameServiceAndGranularity )
187+ })
137188 })
138189
139190 It ("Test plugins in ApisixRoute" , func () {
0 commit comments