@@ -2,6 +2,7 @@ package gatewayapi
22
33import (
44 "fmt"
5+ "net/http"
56 "time"
67
78 . "github.com/onsi/ginkgo/v2"
@@ -10,7 +11,7 @@ import (
1011 "github.com/api7/api7-ingress-controller/test/e2e/scaffold"
1112)
1213
13- var _ = FDescribe ("Test GatewayProxy" , func () {
14+ var _ = Describe ("Test GatewayProxy" , func () {
1415 s := scaffold .NewDefaultScaffold ()
1516
1617 var defaultGatewayClass = `
8081 headers:
8182 X-Proxy-Test: "disabled"
8283`
84+ var gatewayProxyWithPluginMetadata = `
85+ apiVersion: gateway.apisix.io/v1alpha1
86+ kind: GatewayProxy
87+ metadata:
88+ name: api7-proxy-config
89+ spec:
90+ plugins:
91+ - name: error_page
92+ enabled: true
93+ config: {}
94+ pluginMetadata:
95+ error_page: {
96+ "enable": true,
97+ "error_404": {
98+ "body": "404 from plugin metadata",
99+ "content-type": "text/plain"
100+ }
101+ }
102+ `
83103
84104 var httpRouteForTest = `
85105apiVersion: gateway.networking.k8s.io/v1
@@ -101,21 +121,21 @@ spec:
101121 port: 80
102122`
103123
104- var ResourceApplied = func (resourType , resourceName , resourceRaw string , observedGeneration int ) {
124+ var ResourceApplied = func (resourceType , resourceName , resourceRaw string , observedGeneration int ) {
105125 Expect (s .CreateResourceFromString (resourceRaw )).
106- NotTo (HaveOccurred (), fmt .Sprintf ("creating %s" , resourType ))
126+ NotTo (HaveOccurred (), fmt .Sprintf ("creating %s" , resourceType ))
107127
108128 Eventually (func () string {
109- hryaml , err := s .GetResourceYaml (resourType , resourceName )
110- Expect (err ).NotTo (HaveOccurred (), fmt .Sprintf ("getting %s yaml" , resourType ))
129+ hryaml , err := s .GetResourceYaml (resourceType , resourceName )
130+ Expect (err ).NotTo (HaveOccurred (), fmt .Sprintf ("getting %s yaml" , resourceType ))
111131 return hryaml
112- }, "8s" , "2s" ).
132+ }). WithTimeout ( 8 * time . Second ). ProbeEvery ( 2 * time . Second ).
113133 Should (
114134 SatisfyAll (
115135 ContainSubstring (`status: "True"` ),
116136 ContainSubstring (fmt .Sprintf ("observedGeneration: %d" , observedGeneration )),
117137 ),
118- fmt .Sprintf ("checking %s condition status" , resourType ),
138+ fmt .Sprintf ("checking %s condition status" , resourceType ),
119139 )
120140 time .Sleep (1 * time .Second )
121141 }
@@ -220,4 +240,27 @@ spec:
220240 })
221241 })
222242
243+ FContext ("Test Gateway with PluginMetadata" , func () {
244+ var (
245+ err error
246+ )
247+
248+ It ("Should work OK with error_page" , func () {
249+ By ("Update GatewayProxy with PluginMetadata" )
250+ err = s .CreateResourceFromString (gatewayProxyWithPluginMetadata )
251+ Ω (err ).ShouldNot (HaveOccurred ())
252+ time .Sleep (5 * time .Second )
253+
254+ By ("Create HTTPRoute for Gateway with GatewayProxy" )
255+ ResourceApplied ("HTTPRoute" , "test-route" , fmt .Sprintf (httpRouteForTest , "api7" ), 1 )
256+
257+ By ("Check PluginMetadata working" )
258+ s .NewAPISIXClient ().
259+ GET ("/get" ).
260+ WithHost ("example.com" ).
261+ Expect ().
262+ Status (http .StatusNotFound ).
263+ Body ().Contains ("404 from plugin metadata" )
264+ })
265+ })
223266})
0 commit comments