Skip to content

Commit 650f362

Browse files
committed
more e2e test cases
1 parent b1ca121 commit 650f362

File tree

3 files changed

+147
-3
lines changed

3 files changed

+147
-3
lines changed

api/v2/apisixroute_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,13 @@ type ApisixRouteHTTPMatchExpr struct {
219219
Op string `json:"op" yaml:"op"`
220220
// Set is an array type object of the expression.
221221
// It should be used when the Op is "in" or "not_in";
222+
// +kubebuilder:validation:Optional
222223
Set []string `json:"set" yaml:"set"`
223224
// Value is the normal type object for the expression,
224225
// it should be used when the Op is not "in" and "not_in".
225226
// Set and Value are exclusive so only of them can be set
226227
// in the same time.
228+
// +kubebuilder:validation:Optional
227229
Value *string `json:"value" yaml:"value"`
228230
}
229231

config/crd/bases/apisix.apache.org_apisixroutes.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ spec:
192192
type: string
193193
required:
194194
- op
195-
- set
196195
- subject
197-
- value
198196
type: object
199197
type: array
200198
filter_func:

test/e2e/apisix/route.go

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ metadata:
4343
spec:
4444
ingressClassName: apisix
4545
http:
46-
- name: route0
46+
- name: rule0
4747
match:
4848
hosts:
4949
- httpbin
@@ -78,5 +78,149 @@ spec:
7878
}
7979
Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
8080
})
81+
82+
It("Test plugins in ApisixRoute", func() {
83+
const apisixRouteSpecPart0 = `
84+
apiVersion: apisix.apache.org/v2
85+
kind: ApisixRoute
86+
metadata:
87+
name: default
88+
spec:
89+
ingressClassName: apisix
90+
http:
91+
- name: rule0
92+
match:
93+
paths:
94+
- /*
95+
backends:
96+
- serviceName: httpbin-service-e2e-test
97+
servicePort: 80
98+
`
99+
const apisixRouteSpecPart1 = `
100+
plugins:
101+
- name: response-rewrite
102+
enable: true
103+
config:
104+
headers:
105+
X-Global-Rule: "test-response-rewrite"
106+
X-Global-Test: "enabled"
107+
`
108+
By("apply ApisixRoute without plugins")
109+
var apisixRoute apiv2.ApisixRoute
110+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, apisixRouteSpecPart0)
111+
112+
By("verify ApisixRoute works")
113+
request := func() int {
114+
return s.NewAPISIXClient().GET("/get").Expect().Raw().StatusCode
115+
}
116+
Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
117+
118+
By("apply ApisixRoute with plugins")
119+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, apisixRouteSpecPart0+apisixRouteSpecPart1)
120+
time.Sleep(5 * time.Second)
121+
122+
By("verify plugin works")
123+
resp := s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusOK)
124+
resp.Header("X-Global-Rule").IsEqual("test-response-rewrite")
125+
resp.Header("X-Global-Test").IsEqual("enabled")
126+
127+
By("remove plugin")
128+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, apisixRouteSpecPart0)
129+
time.Sleep(5 * time.Second)
130+
131+
By("verify no plugin works")
132+
resp = s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusOK)
133+
resp.Header("X-Global-Rule").IsEmpty()
134+
resp.Header("X-Global-Test").IsEmpty()
135+
})
136+
137+
It("Test ApisixRoute match by vars", func() {
138+
const apisixRouteSpec = `
139+
apiVersion: apisix.apache.org/v2
140+
kind: ApisixRoute
141+
metadata:
142+
name: default
143+
spec:
144+
ingressClassName: apisix
145+
http:
146+
- name: rule0
147+
match:
148+
paths:
149+
- /*
150+
exprs:
151+
- subject:
152+
scope: Header
153+
name: X-Foo
154+
op: Equal
155+
value: bar
156+
backends:
157+
- serviceName: httpbin-service-e2e-test
158+
servicePort: 80
159+
`
160+
By("apply ApisixRoute")
161+
var apisixRoute apiv2.ApisixRoute
162+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, apisixRouteSpec)
163+
164+
By("verify ApisixRoute works")
165+
request := func() int {
166+
return s.NewAPISIXClient().GET("/get").
167+
WithHeader("X-Foo", "bar").
168+
Expect().Raw().StatusCode
169+
}
170+
Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
171+
s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusNotFound)
172+
})
173+
174+
It("Test ApisixRoute filterFunc", func() {
175+
const apisixRouteSpec = `
176+
apiVersion: apisix.apache.org/v2
177+
kind: ApisixRoute
178+
metadata:
179+
name: default
180+
spec:
181+
ingressClassName: apisix
182+
http:
183+
- name: rule0
184+
match:
185+
paths:
186+
- /*
187+
filter_func: "function(vars)\n local core = require ('apisix.core')\n local body, err = core.request.get_body()\n if not body then\n return false\n end\n\n local data, err = core.json.decode(body)\n if not data then\n return false\n end\n\n if data['foo'] == 'bar' then\n return true\n end\n\n return false\nend"
188+
backends:
189+
- serviceName: httpbin-service-e2e-test
190+
servicePort: 80
191+
`
192+
By("apply ApisixRoute")
193+
var apisixRoute apiv2.ApisixRoute
194+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apisixRoute, apisixRouteSpec)
195+
196+
By("verify ApisixRoute works")
197+
request := func() int {
198+
return s.NewAPISIXClient().GET("/get").
199+
WithJSON(map[string]string{"foo": "bar"}).
200+
Expect().Raw().StatusCode
201+
}
202+
Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
203+
s.NewAPISIXClient().GET("/get").Expect().Status(http.StatusNotFound)
204+
})
205+
206+
PIt("Test ApisixRoute resolveGranularity", func() {
207+
// The `.Spec.HTTP[0].Backends[0].ResolveGranularity` can be "endpoints" or "service",
208+
// when set to "endpoints", the pod ips will be used; or the service ClusterIP or ExternalIP will be used when it set to "service",
209+
210+
// In the current implementation, pod ips are always used.
211+
// So the case is pending for now.
212+
})
213+
214+
PIt("Test ApisixRoute subset", func() {
215+
// route.Spec.HTTP[].Backends[].Subset depends on ApisixUpstream.
216+
// ApisixUpstream is not implemented yet.
217+
// So the case is pending for now
218+
})
219+
220+
PIt("Test ApisixRoute reference ApisixUpstream", func() {
221+
// This case depends on ApisixUpstream.
222+
// ApisixUpstream is not implemented yet.
223+
// So the case is pending for now.
224+
})
81225
})
82226
})

0 commit comments

Comments
 (0)