@@ -19,7 +19,6 @@ package gatewayapi
1919
2020import (
2121 "fmt"
22- "net/http"
2322 "time"
2423
2524 . "github.com/onsi/ginkgo/v2"
@@ -103,64 +102,6 @@ spec:
103102 headers:
104103 X-Proxy-Test: "disabled"
105104`
106- var (
107- gatewayProxyWithPluginMetadata0 = `
108- apiVersion: apisix.apache.org/v1alpha1
109- kind: GatewayProxy
110- metadata:
111- name: apisix-proxy-config
112- spec:
113- provider:
114- type: ControlPlane
115- controlPlane:
116- endpoints:
117- - %s
118- auth:
119- type: AdminKey
120- adminKey:
121- value: "%s"
122- plugins:
123- - name: error-page
124- enabled: true
125- config: {}
126- pluginMetadata:
127- error-page: {
128- "enable": true,
129- "error_404": {
130- "body": "404 from plugin metadata",
131- "content-type": "text/plain"
132- }
133- }
134- `
135- gatewayProxyWithPluginMetadata1 = `
136- apiVersion: apisix.apache.org/v1alpha1
137- kind: GatewayProxy
138- metadata:
139- name: apisix-proxy-config
140- spec:
141- provider:
142- type: ControlPlane
143- controlPlane:
144- endpoints:
145- - %s
146- auth:
147- type: AdminKey
148- adminKey:
149- value: "%s"
150- plugins:
151- - name: error-page
152- enabled: true
153- config: {}
154- pluginMetadata:
155- error-page: {
156- "enable": false,
157- "error_404": {
158- "body": "404 from plugin metadata",
159- "content-type": "text/plain"
160- }
161- }
162- `
163- )
164105
165106 var httpRouteForTest = `
166107apiVersion: gateway.networking.k8s.io/v1
@@ -275,59 +216,48 @@ spec:
275216 })
276217 })
277218
278- Context ("Test Gateway with PluginMetadata" , func () {
279- var (
280- err error
281- )
282-
283- PIt ("Should work OK with error-page" , func () {
284- By ("Update GatewayProxy with PluginMetadata" )
285- err = s .CreateResourceFromString (fmt .Sprintf (gatewayProxyWithPluginMetadata0 , s .Deployer .GetAdminEndpoint (), s .AdminKey ()))
286- Expect (err ).ShouldNot (HaveOccurred ())
219+ Context ("Test GatewayProxy with invalid endpoint" , func () {
220+ var gatewayProxyWithInvalidEndpoint = `
221+ apiVersion: apisix.apache.org/v1alpha1
222+ kind: GatewayProxy
223+ metadata:
224+ name: apisix-proxy-config
225+ spec:
226+ provider:
227+ type: ControlPlane
228+ controlPlane:
229+ endpoints:
230+ - "http://invalid-endpoint:9180"
231+ - %s
232+ auth:
233+ type: AdminKey
234+ adminKey:
235+ value: "%s"
236+ `
237+ It ("Should fail to apply GatewayProxy with invalid endpoint" , func () {
238+ By ("Update GatewayProxy with invalid endpoint" )
239+ err := s .CreateResourceFromString (fmt .Sprintf (gatewayProxyWithInvalidEndpoint , s .Deployer .GetAdminEndpoint (), s .AdminKey ()))
240+ Expect (err ).NotTo (HaveOccurred (), "creating GatewayProxy with enabled plugin" )
287241 time .Sleep (5 * time .Second )
288242
289- By ("Create HTTPRoute for Gateway with GatewayProxy " )
243+ By ("Create HTTPRoute" )
290244 resourceApplied ("HTTPRoute" , "test-route" , fmt .Sprintf (httpRouteForTest , "apisix" ), 1 )
291245
292- time .Sleep (5 * time .Second )
293- By ("Check PluginMetadata working" )
294- s .NewAPISIXClient ().
295- GET ("/not-found" ).
296- WithHost ("example.com" ).
297- Expect ().
298- Status (http .StatusNotFound ).
299- Body ().Contains ("404 from plugin metadata" )
300-
301- By ("Update GatewayProxy with PluginMetadata" )
302- err = s .CreateResourceFromString (fmt .Sprintf (gatewayProxyWithPluginMetadata1 , s .Deployer .GetAdminEndpoint (), s .AdminKey ()))
303- Expect (err ).ShouldNot (HaveOccurred ())
304- time .Sleep (5 * time .Second )
305-
306- By ("Check PluginMetadata working" )
307- s .NewAPISIXClient ().
308- GET ("/not-found" ).
309- WithHost ("example.com" ).
310- Expect ().
311- Status (http .StatusNotFound ).
312- Body ().Contains (`{"error_msg":"404 Route Not Found"}` )
313-
314- By ("Delete GatewayProxy" )
315- err = s .DeleteResourceFromString (fmt .Sprintf (gatewayProxyWithPluginMetadata0 , s .Deployer .GetAdminEndpoint (), s .AdminKey ()))
316- Expect (err ).ShouldNot (HaveOccurred ())
317- time .Sleep (5 * time .Second )
246+ expectRequest := func () bool {
247+ resp := s .NewAPISIXClient ().
248+ GET ("/get" ).
249+ WithHost ("example.com" ).
250+ Expect ().Raw ()
251+ return resp .StatusCode == 200 && resp .Header .Get ("X-Proxy-Test" ) == ""
252+ }
318253
319- By ("Check PluginMetadata is not working" )
320- s .NewAPISIXClient ().
321- GET ("/not-found" ).
322- WithHost ("example.com" ).
323- Expect ().
324- Status (http .StatusNotFound ).
325- Body ().Contains (`{"error_msg":"404 Route Not Found"}` )
254+ Eventually (expectRequest ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (BeTrue ())
326255 })
327256 })
328257
329- var (
330- gatewayProxyWithInvalidProviderType = `
258+ Context ("Test GatewayProxy Provider Validation" , func () {
259+ var (
260+ gatewayProxyWithInvalidProviderType = `
331261apiVersion: apisix.apache.org/v1alpha1
332262kind: GatewayProxy
333263metadata:
@@ -336,7 +266,7 @@ spec:
336266 provider:
337267 type: "InvalidType"
338268`
339- gatewayProxyWithMissingControlPlane = `
269+ gatewayProxyWithMissingControlPlane = `
340270apiVersion: apisix.apache.org/v1alpha1
341271kind: GatewayProxy
342272metadata:
@@ -345,7 +275,7 @@ spec:
345275 provider:
346276 type: "ControlPlane"
347277`
348- gatewayProxyWithValidProvider = `
278+ gatewayProxyWithValidProvider = `
349279apiVersion: apisix.apache.org/v1alpha1
350280kind: GatewayProxy
351281metadata:
@@ -361,16 +291,7 @@ spec:
361291 adminKey:
362292 value: "test-key"
363293`
364- )
365-
366- Context ("Test GatewayProxy Provider Validation" , func () {
367- AfterEach (func () {
368- By ("Clean up GatewayProxy resources" )
369- _ = s .DeleteResourceFromString (gatewayProxyWithInvalidProviderType )
370- _ = s .DeleteResourceFromString (gatewayProxyWithMissingControlPlane )
371- _ = s .DeleteResourceFromString (gatewayProxyWithValidProvider )
372- })
373-
294+ )
374295 It ("Should reject invalid provider type" , func () {
375296 By ("Create GatewayProxy with invalid provider type" )
376297 err := s .CreateResourceFromString (gatewayProxyWithInvalidProviderType )
0 commit comments