@@ -35,7 +35,21 @@ var _ = Describe("Test ApisixRoute", func() {
3535 )
3636
3737 Context ("Test ApisixRoute" , func () {
38- const apisixRouteSpec = `
38+ BeforeEach (func () {
39+ By ("create GatewayProxy" )
40+ gatewayProxy := fmt .Sprintf (gatewayProxyYaml , s .Deployer .GetAdminEndpoint (), s .AdminKey ())
41+ err := s .CreateResourceFromStringWithNamespace (gatewayProxy , "default" )
42+ Expect (err ).NotTo (HaveOccurred (), "creating GatewayProxy" )
43+ time .Sleep (5 * time .Second )
44+
45+ By ("create IngressClass" )
46+ err = s .CreateResourceFromStringWithNamespace (ingressClassYaml , "" )
47+ Expect (err ).NotTo (HaveOccurred (), "creating IngressClass" )
48+ time .Sleep (5 * time .Second )
49+ })
50+
51+ It ("Basic tests" , func () {
52+ const apisixRouteSpec = `
3953apiVersion: apisix.apache.org/v2
4054kind: ApisixRoute
4155metadata:
@@ -48,35 +62,31 @@ spec:
4862 hosts:
4963 - httpbin
5064 paths:
51- - /get
65+ - %s
5266 backends:
5367 - serviceName: httpbin-service-e2e-test
5468 servicePort: 80
5569`
70+ request := func (path string ) int {
71+ return s .NewAPISIXClient ().GET (path ).WithHost ("httpbin" ).Expect ().Raw ().StatusCode
72+ }
5673
57- BeforeEach (func () {
58- By ("create GatewayProxy" )
59- gatewayProxy := fmt .Sprintf (gatewayProxyYaml , s .Deployer .GetAdminEndpoint (), s .AdminKey ())
60- err := s .CreateResourceFromStringWithNamespace (gatewayProxy , "default" )
61- Expect (err ).NotTo (HaveOccurred (), "creating GatewayProxy" )
62- time .Sleep (5 * time .Second )
63-
64- By ("create IngressClass" )
65- err = s .CreateResourceFromStringWithNamespace (ingressClassYaml , "" )
66- Expect (err ).NotTo (HaveOccurred (), "creating IngressClass" )
67- time .Sleep (5 * time .Second )
68- })
69-
70- It ("Basic tests" , func () {
7174 By ("apply ApisixRoute" )
7275 var apisixRoute apiv2.ApisixRoute
73- applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" }, & apisixRoute , apisixRouteSpec )
76+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" }, & apisixRoute , fmt . Sprintf ( apisixRouteSpec , "/get" ) )
7477
7578 By ("verify ApisixRoute works" )
76- request := func () int {
77- return s .NewAPISIXClient ().GET ("/get" ).WithHost ("httpbin" ).Expect ().Raw ().StatusCode
78- }
79- Eventually (request ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusOK ))
79+ Eventually (request ).WithArguments ("/get" ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusOK ))
80+
81+ By ("update ApisixRoute" )
82+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" }, & apisixRoute , fmt .Sprintf (apisixRouteSpec , "/headers" ))
83+ Eventually (request ).WithArguments ("/get" ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
84+ s .NewAPISIXClient ().GET ("/headers" ).WithHost ("httpbin" ).Expect ().Status (http .StatusOK )
85+
86+ By ("delete ApisixRoute" )
87+ err := s .DeleteResource ("ApisixRoute" , "default" )
88+ Expect (err ).ShouldNot (HaveOccurred (), "deleting ApisixRoute" )
89+ Eventually (request ).WithArguments ("/headers" ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
8090 })
8191
8292 It ("Test plugins in ApisixRoute" , func () {
0 commit comments