@@ -61,7 +61,7 @@ var _ = Describe("Test ApisixRoute", Label("apisix.apache.org", "v2", "apisixrou
6161
6262 Context ("Test ApisixRoute" , func () {
6363
64- It ("Basic tests" , func () {
64+ Context ("Basic tests" , func () {
6565 const apisixRouteSpec = `
6666apiVersion: apisix.apache.org/v2
6767kind: ApisixRoute
@@ -81,56 +81,111 @@ spec:
8181 - serviceName: httpbin-service-e2e-test
8282 servicePort: 80
8383`
84- request := func (path string ) int {
85- return s .NewAPISIXClient ().GET (path ).WithHost ("httpbin" ).Expect ().Raw ().StatusCode
86- }
8784
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" ))
85+ const apisixRouteSpecWithNameServiceAndGranularity = `
86+ apiVersion: apisix.apache.org/v2
87+ kind: ApisixRoute
88+ metadata:
89+ name: default
90+ namespace: %s
91+ spec:
92+ ingressClassName: %s
93+ http:
94+ - name: rule0
95+ match:
96+ hosts:
97+ - httpbin
98+ paths:
99+ - %s
100+ backends:
101+ - serviceName: httpbin-service-e2e-test
102+ servicePort: http
103+ resolveGranularity: service
104+ `
92105
93- By ("verify ApisixRoute works" )
94- Eventually (request ).WithArguments ("/get" ).WithTimeout (20 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusOK ))
106+ const apisixRouteSpecWithNameServicePort = `
107+ apiVersion: apisix.apache.org/v2
108+ kind: ApisixRoute
109+ metadata:
110+ name: default
111+ namespace: %s
112+ spec:
113+ ingressClassName: %s
114+ http:
115+ - name: rule0
116+ match:
117+ hosts:
118+ - httpbin
119+ paths:
120+ - %s
121+ backends:
122+ - serviceName: httpbin-service-e2e-test
123+ servicePort: http
124+ `
125+ test := func (apisixRouteSpec string ) {
126+ request := func (path string ) int {
127+ return s .NewAPISIXClient ().GET (path ).WithHost ("httpbin" ).Expect ().Raw ().StatusCode
128+ }
95129
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 )
130+ By ("apply ApisixRoute" )
131+ var apisixRoute apiv2.ApisixRoute
132+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" },
133+ & apisixRoute , fmt .Sprintf (apisixRouteSpec , s .Namespace (), s .Namespace (), "/get" ))
101134
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 ))
135+ By ("verify ApisixRoute works" )
136+ Eventually (request ).WithArguments ("/get" ).WithTimeout (20 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusOK ))
106137
107- By ("request /metrics endpoint from controller" )
138+ By ("update ApisixRoute" )
139+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" },
140+ & apisixRoute , fmt .Sprintf (apisixRouteSpec , s .Namespace (), s .Namespace (), "/headers" ))
141+ Eventually (request ).WithArguments ("/get" ).WithTimeout (20 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
142+ s .NewAPISIXClient ().GET ("/headers" ).WithHost ("httpbin" ).Expect ().Status (http .StatusOK )
108143
109- // Get the metrics service endpoint
110- metricsURL := s .GetMetricsEndpoint ()
144+ By ("delete ApisixRoute" )
145+ err := s .DeleteResource ("ApisixRoute" , "default" )
146+ Expect (err ).ShouldNot (HaveOccurred (), "deleting ApisixRoute" )
147+ Eventually (request ).WithArguments ("/headers" ).WithTimeout (20 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
111148
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- }()
149+ By ("request /metrics endpoint from controller" )
118150
119- Expect (resp .StatusCode ).Should (Equal (http .StatusOK ))
151+ // Get the metrics service endpoint
152+ metricsURL := s .GetMetricsEndpoint ()
120153
121- body , err := io .ReadAll (resp .Body )
122- Expect (err ).ShouldNot (HaveOccurred (), "read metrics response" )
154+ By ("verify metrics content" )
155+ resp , err := http .Get (metricsURL )
156+ Expect (err ).ShouldNot (HaveOccurred (), "request metrics endpoint" )
157+ defer func () {
158+ _ = resp .Body .Close ()
159+ }()
123160
124- bodyStr := string ( body )
161+ Expect ( resp . StatusCode ). Should ( Equal ( http . StatusOK ) )
125162
126- // Verify prometheus format
127- Expect (resp . Header . Get ( "Content-Type" )). Should ( ContainSubstring ( "text/plain; version=0.0.4; charset=utf-8" ) )
163+ body , err := io . ReadAll ( resp . Body )
164+ Expect (err ). ShouldNot ( HaveOccurred (), "read metrics response" )
128165
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" ))
166+ bodyStr := string (body )
167+
168+ // Verify prometheus format
169+ Expect (resp .Header .Get ("Content-Type" )).Should (ContainSubstring ("text/plain; version=0.0.4; charset=utf-8" ))
170+
171+ // Verify specific metrics from metrics.go exist
172+ Expect (bodyStr ).Should (ContainSubstring ("apisix_ingress_adc_sync_duration_seconds" ))
173+ Expect (bodyStr ).Should (ContainSubstring ("apisix_ingress_adc_sync_total" ))
174+ Expect (bodyStr ).Should (ContainSubstring ("apisix_ingress_status_update_queue_length" ))
175+ Expect (bodyStr ).Should (ContainSubstring ("apisix_ingress_file_io_duration_seconds" ))
176+
177+ // Log metrics for debugging
178+ fmt .Printf ("Metrics endpoint response:\n %s\n " , bodyStr )
179+ }
180+ It ("Basic" , func () {
181+ test (apisixRouteSpec )
182+ })
183+ It ("Basic: with named service port" , func () {
184+ test (apisixRouteSpecWithNameServicePort )
185+ })
186+ It ("Basic: with named service port and granularity service" , func () {
187+ test (apisixRouteSpecWithNameServiceAndGranularity )
188+ })
134189 })
135190
136191 It ("Test plugins in ApisixRoute" , func () {
0 commit comments