18
18
package v2
19
19
20
20
import (
21
+ "fmt"
22
+ "net/http"
23
+ "time"
24
+
21
25
. "github.com/onsi/ginkgo/v2"
22
26
. "github.com/onsi/gomega"
27
+ "k8s.io/apimachinery/pkg/types"
23
28
29
+ apiv2 "github.com/apache/apisix-ingress-controller/api/v2"
30
+ "github.com/apache/apisix-ingress-controller/test/e2e/framework"
24
31
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
25
32
)
26
33
@@ -56,11 +63,14 @@ spec:
56
63
`
57
64
58
65
var _ = Describe ("APISIX Standalone Basic Tests" , Label ("apisix.apache.org" , "v2" , "basic" ), func () {
59
- s := scaffold .NewScaffold (& scaffold.Options {
60
- ControllerName : "apisix.apache.org/apisix-ingress-controller" ,
61
- })
66
+ var (
67
+ s = scaffold .NewScaffold (& scaffold.Options {
68
+ ControllerName : "apisix.apache.org/apisix-ingress-controller" ,
69
+ })
70
+ applier = framework .NewApplier (s .GinkgoT , s .K8sClient , s .CreateResourceFromString )
71
+ )
62
72
63
- Describe ("APISIX HTTP Proxy" , func () {
73
+ Context ("APISIX HTTP Proxy" , func () {
64
74
It ("should handle basic HTTP requests" , func () {
65
75
httpClient := s .NewAPISIXClient ()
66
76
Expect (httpClient ).NotTo (BeNil ())
@@ -83,6 +93,97 @@ var _ = Describe("APISIX Standalone Basic Tests", Label("apisix.apache.org", "v2
83
93
Expect ().
84
94
Status (404 ).Body ().Contains ("404 Route Not Found" )
85
95
})
96
+ })
97
+
98
+ Context ("IngressClass Annotations" , func () {
99
+ It ("Basic tests" , func () {
100
+ const gatewayProxyYaml = `
101
+ apiVersion: apisix.apache.org/v1alpha1
102
+ kind: GatewayProxy
103
+ metadata:
104
+ name: apisix-proxy-config
105
+ spec:
106
+ provider:
107
+ type: ControlPlane
108
+ controlPlane:
109
+ endpoints:
110
+ - %s
111
+ auth:
112
+ type: AdminKey
113
+ adminKey:
114
+ value: "%s"
115
+ `
86
116
117
+ const ingressClassYaml = `
118
+ apiVersion: networking.k8s.io/%s
119
+ kind: IngressClass
120
+ metadata:
121
+ name: apisix
122
+ annotations:
123
+ apisix.apache.org/parameters-namespace: %s
124
+ spec:
125
+ controller: apisix.apache.org/apisix-ingress-controller
126
+ parameters:
127
+ apiGroup: apisix.apache.org
128
+ kind: GatewayProxy
129
+ name: apisix-proxy-config
130
+ `
131
+
132
+ By ("create GatewayProxy" )
133
+ gatewayProxy := fmt .Sprintf (gatewayProxyYaml , s .Deployer .GetAdminEndpoint (), s .AdminKey ())
134
+ err := s .CreateResourceFromString (gatewayProxy )
135
+ Expect (err ).NotTo (HaveOccurred (), "creating GatewayProxy" )
136
+ time .Sleep (5 * time .Second )
137
+
138
+ By ("create IngressClass" )
139
+ ingressClass := fmt .Sprintf (ingressClassYaml , framework .IngressVersion , s .Namespace ())
140
+ err = s .CreateResourceFromString (ingressClass )
141
+ Expect (err ).NotTo (HaveOccurred (), "creating IngressClass" )
142
+ time .Sleep (5 * time .Second )
143
+
144
+ const apisixRouteSpec = `
145
+ apiVersion: apisix.apache.org/v2
146
+ kind: ApisixRoute
147
+ metadata:
148
+ name: default
149
+ spec:
150
+ ingressClassName: apisix
151
+ http:
152
+ - name: rule0
153
+ match:
154
+ hosts:
155
+ - httpbin
156
+ paths:
157
+ - %s
158
+ backends:
159
+ - serviceName: httpbin-service-e2e-test
160
+ servicePort: 80
161
+ `
162
+ request := func (path string ) int {
163
+ return s .NewAPISIXClient ().GET (path ).WithHost ("httpbin" ).Expect ().Raw ().StatusCode
164
+ }
165
+
166
+ By ("apply ApisixRoute" )
167
+ var apisixRoute apiv2.ApisixRoute
168
+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" }, & apisixRoute , fmt .Sprintf (apisixRouteSpec , "/get" ))
169
+
170
+ By ("verify ApisixRoute works" )
171
+ Eventually (request ).WithArguments ("/get" ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusOK ))
172
+
173
+ By ("update ApisixRoute" )
174
+ applier .MustApplyAPIv2 (types.NamespacedName {Namespace : s .Namespace (), Name : "default" }, & apisixRoute , fmt .Sprintf (apisixRouteSpec , "/headers" ))
175
+ Eventually (request ).WithArguments ("/get" ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
176
+ s .RequestAssert (& scaffold.RequestAssert {
177
+ Method : "GET" ,
178
+ Path : "/headers" ,
179
+ Host : "httpbin" ,
180
+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
181
+ })
182
+
183
+ By ("delete ApisixRoute" )
184
+ err = s .DeleteResource ("ApisixRoute" , "default" )
185
+ Expect (err ).ShouldNot (HaveOccurred (), "deleting ApisixRoute" )
186
+ Eventually (request ).WithArguments ("/headers" ).WithTimeout (8 * time .Second ).ProbeEvery (time .Second ).Should (Equal (http .StatusNotFound ))
187
+ })
87
188
})
88
189
})
0 commit comments