4444apiVersion: gateway.networking.k8s.io/v1
4545kind: Gateway
4646metadata:
47- name: api7-no-proxy
47+ name: api7
4848spec:
4949 gatewayClassName: %s
5050 listeners:
@@ -95,51 +95,81 @@ spec:
9595 - matches:
9696 - path:
9797 type: Exact
98- value: /test
98+ value: /get
9999 backendRefs:
100100 - name: httpbin-service-e2e-test
101101 port: 80
102102`
103103
104+ var ResourceApplied = func (resourType , resourceName , resourceRaw string , observedGeneration int ) {
105+ Expect (s .CreateResourceFromString (resourceRaw )).
106+ NotTo (HaveOccurred (), fmt .Sprintf ("creating %s" , resourType ))
107+
108+ Eventually (func () string {
109+ hryaml , err := s .GetResourceYaml (resourType , resourceName )
110+ Expect (err ).NotTo (HaveOccurred (), fmt .Sprintf ("getting %s yaml" , resourType ))
111+ return hryaml
112+ }, "8s" , "2s" ).
113+ Should (
114+ SatisfyAll (
115+ ContainSubstring (`status: "True"` ),
116+ ContainSubstring (fmt .Sprintf ("observedGeneration: %d" , observedGeneration )),
117+ ),
118+ fmt .Sprintf ("checking %s condition status" , resourType ),
119+ )
120+ time .Sleep (1 * time .Second )
121+ }
122+
123+ var (
124+ gatewayClassName string
125+ )
126+
104127 BeforeEach (func () {
105128 By ("Create GatewayClass" )
106- gatewayClassName : = fmt .Sprintf ("api7-%d" , time .Now ().Unix ())
129+ gatewayClassName = fmt .Sprintf ("api7-%d" , time .Now ().Unix ())
107130 err := s .CreateResourceFromStringWithNamespace (fmt .Sprintf (defaultGatewayClass , gatewayClassName , s .GetControllerName ()), "" )
108131 Expect (err ).NotTo (HaveOccurred (), "creating GatewayClass" )
109- time .Sleep (3 * time .Second )
132+ time .Sleep (5 * time .Second )
110133
111134 By ("Check GatewayClass condition" )
112135 gcYaml , err := s .GetResourceYaml ("GatewayClass" , gatewayClassName )
113136 Expect (err ).NotTo (HaveOccurred (), "getting GatewayClass yaml" )
114137 Expect (gcYaml ).To (ContainSubstring (`status: "True"` ), "checking GatewayClass condition status" )
115138 Expect (gcYaml ).To (ContainSubstring ("message: the gatewayclass has been accepted by the api7-ingress-controller" ), "checking GatewayClass condition message" )
116139
140+ By ("Create GatewayProxy with enabled plugin" )
141+ err = s .CreateResourceFromString (gatewayProxyWithEnabledPlugin )
142+ Expect (err ).NotTo (HaveOccurred (), "creating GatewayProxy with enabled plugin" )
143+ time .Sleep (5 * time .Second )
144+
117145 By ("Create Gateway with GatewayProxy" )
118146 err = s .CreateResourceFromString (fmt .Sprintf (gatewayWithProxy , gatewayClassName ))
119147 Expect (err ).NotTo (HaveOccurred (), "creating Gateway with GatewayProxy" )
120- time .Sleep (3 * time .Second )
148+ time .Sleep (5 * time .Second )
121149
122- By ("Create Gateway without GatewayProxy" )
123- err = s .CreateResourceFromString (fmt .Sprintf (gatewayWithoutProxy , gatewayClassName ))
124- Expect (err ).NotTo (HaveOccurred (), "creating Gateway without GatewayProxy" )
125- time .Sleep (3 * time .Second )
150+ By ("check Gateway condition" )
151+ gwyaml , err := s .GetResourceYaml ("Gateway" , "api7" )
152+ Expect (err ).NotTo (HaveOccurred (), "getting Gateway yaml" )
153+ Expect (gwyaml ).To (ContainSubstring (`status: "True"` ), "checking Gateway condition status" )
154+ Expect (gwyaml ).To (ContainSubstring ("message: the gateway has been accepted by the api7-ingress-controller" ), "checking Gateway condition message" )
155+ })
156+
157+ AfterEach (func () {
158+ By ("Clean up resources" )
159+ _ = s .DeleteResourceFromString (gatewayProxyWithEnabledPlugin )
160+ _ = s .DeleteResourceFromString (gatewayProxyWithDisabledPlugin )
161+ _ = s .DeleteResourceFromString (fmt .Sprintf (httpRouteForTest , "api7" ))
162+ _ = s .DeleteResourceFromString (fmt .Sprintf (gatewayWithProxy , gatewayClassName ))
126163 })
127164
128165 Context ("Test Gateway with enabled GatewayProxy plugin" , func () {
129166 It ("Should apply plugin configuration when enabled" , func () {
130- By ("Create GatewayProxy with enabled plugin" )
131- err := s .CreateResourceFromString (gatewayProxyWithEnabledPlugin )
132- Expect (err ).NotTo (HaveOccurred (), "creating GatewayProxy with enabled plugin" )
133- time .Sleep (5 * time .Second )
134-
135167 By ("Create HTTPRoute for Gateway with GatewayProxy" )
136- err = s .CreateResourceFromString (fmt .Sprintf (httpRouteForTest , "api7" ))
137- Expect (err ).NotTo (HaveOccurred (), "creating HTTPRoute for Gateway with GatewayProxy" )
138- time .Sleep (5 * time .Second )
168+ ResourceApplied ("HTTPRoute" , "test-route" , fmt .Sprintf (httpRouteForTest , "api7" ), 1 )
139169
140170 By ("Check if the plugin is applied" )
141171 resp := s .NewAPISIXClient ().
142- GET ("/test " ).
172+ GET ("/get " ).
143173 WithHost ("example.com" ).
144174 Expect ().
145175 Status (200 )
@@ -155,9 +185,12 @@ spec:
155185 Expect (err ).NotTo (HaveOccurred (), "updating GatewayProxy with disabled plugin" )
156186 time .Sleep (5 * time .Second )
157187
188+ By ("Create HTTPRoute for Gateway with GatewayProxy" )
189+ ResourceApplied ("HTTPRoute" , "test-route" , fmt .Sprintf (httpRouteForTest , "api7" ), 1 )
190+
158191 By ("Check if the plugin is not applied" )
159192 resp := s .NewAPISIXClient ().
160- GET ("/test " ).
193+ GET ("/get " ).
161194 WithHost ("example.com" ).
162195 Expect ().
163196 Status (200 )
@@ -168,14 +201,17 @@ spec:
168201
169202 Context ("Test Gateway without GatewayProxy" , func () {
170203 It ("Should work normally without GatewayProxy" , func () {
171- By ("Create HTTPRoute for Gateway without GatewayProxy" )
172- err := s .CreateResourceFromString (fmt .Sprintf (httpRouteForTest , "api7-no-proxy" ))
173- Expect (err ).NotTo (HaveOccurred (), "creating HTTPRoute for Gateway without GatewayProxy" )
204+ By ("Update Gateway without GatewayProxy" )
205+ err := s .CreateResourceFromString (fmt .Sprintf (gatewayWithoutProxy , gatewayClassName ))
206+ Expect (err ).NotTo (HaveOccurred (), "updating Gateway without GatewayProxy" )
174207 time .Sleep (5 * time .Second )
175208
209+ By ("Create HTTPRoute for Gateway without GatewayProxy" )
210+ ResourceApplied ("HTTPRoute" , "test-route" , fmt .Sprintf (httpRouteForTest , "api7" ), 1 )
211+
176212 By ("Check if the route works without plugin" )
177213 resp := s .NewAPISIXClient ().
178- GET ("/test " ).
214+ GET ("/get " ).
179215 WithHost ("example.com" ).
180216 Expect ().
181217 Status (200 )
@@ -184,13 +220,4 @@ spec:
184220 })
185221 })
186222
187- AfterEach (func () {
188- By ("Clean up resources" )
189- _ = s .DeleteResourceFromString (gatewayProxyWithEnabledPlugin )
190- _ = s .DeleteResourceFromString (fmt .Sprintf (httpRouteForTest , "api7" ))
191- _ = s .DeleteResourceFromString (fmt .Sprintf (httpRouteForTest , "api7-no-proxy" ))
192- _ = s .DeleteResourceFromString (fmt .Sprintf (gatewayWithProxy , "dummy" ))
193- _ = s .DeleteResourceFromString (fmt .Sprintf (gatewayWithoutProxy , "dummy" ))
194- time .Sleep (3 * time .Second )
195- })
196223})
0 commit comments