@@ -291,10 +291,67 @@ spec:
291291 s .NewAPISIXClient ().GET ("/get" ).Expect ().Header ("X-Upstream-IP" ).IsEqual (clusterIP )
292292 })
293293
294- PIt ("Test ApisixRoute subset" , func () {
295- // route.Spec.HTTP[].Backends[].Subset depends on ApisixUpstream.
296- // ApisixUpstream is not implemented yet.
297- // So the case is pending for now
294+ It ("Test ApisixRoute subset" , func () {
295+ const apisixRouteSpec = `
296+ apiVersion: apisix.apache.org/v2
297+ kind: ApisixRoute
298+ metadata:
299+ name: default
300+ spec:
301+ ingressClassName: apisix
302+ http:
303+ - name: rule0
304+ match:
305+ hosts:
306+ - httpbin
307+ paths:
308+ - /*
309+ backends:
310+ - serviceName: httpbin-service-e2e-test
311+ servicePort: 80
312+ subset: test-subset
313+ `
314+ const apisixUpstreamSpec0 = `
315+ apiVersion: apisix.apache.org/v2
316+ kind: ApisixUpstream
317+ metadata:
318+ name: httpbin-service-e2e-test
319+ spec:
320+ ingressClassName: apisix
321+ subsets:
322+ - name: test-subset
323+ labels:
324+ unknown-key: unknown-value
325+ `
326+ const apisixUpstreamSpec1 = `
327+ apiVersion: apisix.apache.org/v2
328+ kind: ApisixUpstream
329+ metadata:
330+ name: httpbin-service-e2e-test
331+ spec:
332+ ingressClassName: apisix
333+ subsets:
334+ - name: test-subset
335+ labels:
336+ app: httpbin-deployment-e2e-test
337+ `
338+ request := func () int {
339+ return s .NewAPISIXClient ().GET ("/get" ).WithHost ("httpbin" ).Expect ().Raw ().StatusCode
340+ }
341+ By ("apply ApisixRoute" )
342+ var apisixRoute apiv2.ApisixRoute
343+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" }, & apisixRoute , apisixRouteSpec )
344+ Eventually (request ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusOK ))
345+
346+ // no pod matches the subset label "unknown-key: unknown-value" so there will be no node in the upstream,
347+ // to request the route will get http.StatusServiceUnavailable
348+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "httpbin-service-e2e-test" }, new (apiv2.ApisixUpstream ), apisixUpstreamSpec0 )
349+ Eventually (request ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusServiceUnavailable ))
350+
351+ // the pod matches the subset label "app: httpbin-deployment-e2e-test",
352+ // to request the route will be OK
353+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "httpbin-service-e2e-test" }, new (apiv2.ApisixUpstream ), apisixUpstreamSpec1 )
354+ Eventually (request ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusOK ))
298355 })
299356 })
300357
0 commit comments