Skip to content

Commit 4842859

Browse files
committed
chore: refactor E2E tests to support parallel tests
1 parent 486cc65 commit 4842859

File tree

7 files changed

+182
-200
lines changed

7 files changed

+182
-200
lines changed

.github/workflows/apisix-e2e-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@ jobs:
111111
PROVIDER_TYPE: ${{ matrix.provider_type }}
112112
TEST_LABEL: ${{ matrix.cases_subset }}
113113
run: |
114-
make e2e-test
114+
make ginkgo-e2e-test

test/e2e/crds/v2/config.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package v2
19+
20+
import "fmt"
21+
22+
const gatewayProxyYaml = `
23+
apiVersion: apisix.apache.org/v1alpha1
24+
kind: GatewayProxy
25+
metadata:
26+
name: apisix-proxy-config
27+
namespace: %s
28+
spec:
29+
provider:
30+
type: ControlPlane
31+
controlPlane:
32+
endpoints:
33+
- %s
34+
auth:
35+
type: AdminKey
36+
adminKey:
37+
value: "%s"
38+
`
39+
40+
const ingressClassYaml = `
41+
apiVersion: networking.k8s.io/v1
42+
kind: IngressClass
43+
metadata:
44+
name: %s
45+
spec:
46+
controller: "apisix.apache.org/apisix-ingress-controller"
47+
parameters:
48+
apiGroup: "apisix.apache.org"
49+
kind: "GatewayProxy"
50+
name: "apisix-proxy-config"
51+
namespace: "%s"
52+
scope: "Namespace"
53+
`
54+
55+
func getGatewayProxyYaml(namespace, endpoint, adminKey string) string {
56+
return fmt.Sprintf(gatewayProxyYaml, namespace, endpoint, adminKey)
57+
}
58+
59+
func getIngressClassYaml(name, gatewayProxyNamespace string) string {
60+
return fmt.Sprintf(ingressClassYaml, name, gatewayProxyNamespace)
61+
}

test/e2e/crds/v2/consumer.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ var _ = Describe("Test ApisixConsumer", Label("apisix.apache.org", "v2", "apisix
4343

4444
BeforeEach(func() {
4545
By("create GatewayProxy")
46-
gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey())
47-
err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default")
46+
gatewayProxy := getGatewayProxyYaml(s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey())
47+
err := s.CreateResourceFromStringWithNamespace(gatewayProxy, s.Namespace())
4848
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
4949
time.Sleep(5 * time.Second)
5050

5151
By("create IngressClass")
52-
err = s.CreateResourceFromStringWithNamespace(ingressClassYaml, "")
52+
err = s.CreateResourceFromStringWithNamespace(getIngressClassYaml(s.Namespace(), s.Namespace()), "")
5353
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
5454
time.Sleep(5 * time.Second)
5555
})
@@ -62,7 +62,7 @@ kind: ApisixConsumer
6262
metadata:
6363
name: test-consumer
6464
spec:
65-
ingressClassName: apisix
65+
ingressClassName: %s
6666
authParameter:
6767
keyAuth:
6868
value:
@@ -74,7 +74,7 @@ kind: ApisixRoute
7474
metadata:
7575
name: default
7676
spec:
77-
ingressClassName: apisix
77+
ingressClassName: %s
7878
http:
7979
- name: rule0
8080
match:
@@ -115,7 +115,7 @@ kind: ApisixConsumer
115115
metadata:
116116
name: test-consumer
117117
spec:
118-
ingressClassName: apisix
118+
ingressClassName: %s
119119
authParameter:
120120
keyAuth:
121121
secretRef:
@@ -128,11 +128,12 @@ spec:
128128

129129
It("Basic tests", func() {
130130
By("apply ApisixRoute")
131-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, defaultApisixRoute)
131+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, fmt.Sprintf(defaultApisixRoute, s.Namespace()))
132132

133133
By("apply ApisixConsumer")
134-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, keyAuth)
134+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, fmt.Sprintf(keyAuth, s.Namespace()))
135135

136+
fmt.Println("ASHISH GO CHECK")
136137
By("verify ApisixRoute with ApisixConsumer")
137138
Eventually(request).WithArguments("/get", Headers{
138139
"apikey": "invalid-key",
@@ -157,15 +158,16 @@ spec:
157158

158159
It("SecretRef tests", func() {
159160
By("apply ApisixRoute")
160-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, defaultApisixRoute)
161+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, fmt.Sprintf(defaultApisixRoute, s.Namespace()))
161162

162163
By("apply Secret")
163164
err := s.CreateResourceFromString(secret)
164165
Expect(err).ShouldNot(HaveOccurred(), "creating Secret for ApisixConsumer")
165166

166167
By("apply ApisixConsumer")
167-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, keyAuthWiwhSecret)
168+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, fmt.Sprintf(keyAuthWiwhSecret, s.Namespace()))
168169

170+
fmt.Println("ASHISH GO CHECK")
169171
By("verify ApisixRoute with ApisixConsumer")
170172
Eventually(request).WithArguments("/get", Headers{
171173
"apikey": "invalid-key",
@@ -209,7 +211,7 @@ kind: ApisixConsumer
209211
metadata:
210212
name: test-consumer
211213
spec:
212-
ingressClassName: apisix
214+
ingressClassName: %s
213215
authParameter:
214216
basicAuth:
215217
value:
@@ -222,7 +224,7 @@ kind: ApisixRoute
222224
metadata:
223225
name: default
224226
spec:
225-
ingressClassName: apisix
227+
ingressClassName: %s
226228
http:
227229
- name: rule0
228230
match:
@@ -267,7 +269,7 @@ kind: ApisixConsumer
267269
metadata:
268270
name: test-consumer
269271
spec:
270-
ingressClassName: apisix
272+
ingressClassName: %s
271273
authParameter:
272274
basicAuth:
273275
secretRef:
@@ -277,10 +279,10 @@ spec:
277279

278280
It("Basic tests", func() {
279281
By("apply ApisixRoute")
280-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, defaultApisixRoute)
282+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, fmt.Sprintf(defaultApisixRoute, s.Namespace()))
281283

282284
By("apply ApisixConsumer")
283-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, basicAuth)
285+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, fmt.Sprintf(basicAuth, s.Namespace()))
284286

285287
By("verify ApisixRoute with ApisixConsumer")
286288
s.RequestAssert(&scaffold.RequestAssert{
@@ -331,14 +333,14 @@ spec:
331333

332334
It("SecretRef tests", func() {
333335
By("apply ApisixRoute")
334-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, defaultApisixRoute)
336+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, fmt.Sprintf(defaultApisixRoute, s.Namespace()))
335337

336338
By("apply Secret")
337339
err := s.CreateResourceFromString(secret)
338340
Expect(err).ShouldNot(HaveOccurred(), "creating Secret for ApisixConsumer")
339341

340342
By("apply ApisixConsumer")
341-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, basicAuthWithSecret)
343+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, fmt.Sprintf(basicAuthWithSecret, s.Namespace()))
342344

343345
By("verify ApisixRoute with ApisixConsumer")
344346
s.RequestAssert(&scaffold.RequestAssert{

test/e2e/crds/v2/globalrule.go

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,6 @@ import (
2828
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
2929
)
3030

31-
const gatewayProxyYaml = `
32-
apiVersion: apisix.apache.org/v1alpha1
33-
kind: GatewayProxy
34-
metadata:
35-
name: apisix-proxy-config
36-
namespace: default
37-
spec:
38-
provider:
39-
type: ControlPlane
40-
controlPlane:
41-
endpoints:
42-
- %s
43-
auth:
44-
type: AdminKey
45-
adminKey:
46-
value: "%s"
47-
`
48-
49-
const ingressClassYaml = `
50-
apiVersion: networking.k8s.io/v1
51-
kind: IngressClass
52-
metadata:
53-
name: apisix
54-
spec:
55-
controller: "apisix.apache.org/apisix-ingress-controller"
56-
parameters:
57-
apiGroup: "apisix.apache.org"
58-
kind: "GatewayProxy"
59-
name: "apisix-proxy-config"
60-
namespace: "default"
61-
scope: "Namespace"
62-
`
63-
6431
var _ = Describe("Test GlobalRule", Label("apisix.apache.org", "v2", "apisixglobalrule"), func() {
6532
s := scaffold.NewScaffold(&scaffold.Options{
6633
ControllerName: "apisix.apache.org/apisix-ingress-controller",
@@ -72,7 +39,7 @@ kind: Ingress
7239
metadata:
7340
name: test-ingress
7441
spec:
75-
ingressClassName: apisix
42+
ingressClassName: %s
7643
rules:
7744
- host: globalrule.example.com
7845
http:
@@ -89,18 +56,18 @@ spec:
8956
Context("ApisixGlobalRule Basic Operations", func() {
9057
BeforeEach(func() {
9158
By("create GatewayProxy")
92-
gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey())
93-
err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default")
59+
gatewayProxy := getGatewayProxyYaml(s.Namespace(), s.Deployer.GetAdminEndpoint(), s.AdminKey())
60+
err := s.CreateResourceFromStringWithNamespace(gatewayProxy, s.Namespace())
9461
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
9562
time.Sleep(5 * time.Second)
9663

9764
By("create IngressClass")
98-
err = s.CreateResourceFromStringWithNamespace(ingressClassYaml, "")
65+
err = s.CreateResourceFromStringWithNamespace(getIngressClassYaml(s.Namespace(), s.Namespace()), "")
9966
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
10067
time.Sleep(5 * time.Second)
10168

10269
By("create Ingress")
103-
err = s.CreateResourceFromString(ingressYaml)
70+
err = s.CreateResourceFromString(fmt.Sprintf(ingressYaml, s.Namespace()))
10471
Expect(err).NotTo(HaveOccurred(), "creating Ingress")
10572
time.Sleep(5 * time.Second)
10673

@@ -121,7 +88,7 @@ kind: ApisixGlobalRule
12188
metadata:
12289
name: test-global-rule-response-rewrite
12390
spec:
124-
ingressClassName: apisix
91+
ingressClassName: %s
12592
plugins:
12693
- name: response-rewrite
12794
enable: true
@@ -132,7 +99,7 @@ spec:
13299
`
133100

134101
By("create ApisixGlobalRule with response-rewrite plugin")
135-
err := s.CreateResourceFromString(globalRuleYaml)
102+
err := s.CreateResourceFromString(fmt.Sprintf(globalRuleYaml, s.Namespace()))
136103
Expect(err).NotTo(HaveOccurred(), "creating ApisixGlobalRule")
137104

138105
By("verify ApisixGlobalRule status condition")
@@ -173,7 +140,7 @@ kind: ApisixGlobalRule
173140
metadata:
174141
name: test-global-rule-update
175142
spec:
176-
ingressClassName: apisix
143+
ingressClassName: %s
177144
plugins:
178145
- name: response-rewrite
179146
enable: true
@@ -188,7 +155,7 @@ kind: ApisixGlobalRule
188155
metadata:
189156
name: test-global-rule-update
190157
spec:
191-
ingressClassName: apisix
158+
ingressClassName: %s
192159
plugins:
193160
- name: response-rewrite
194161
enable: true
@@ -199,7 +166,7 @@ spec:
199166
`
200167

201168
By("create initial ApisixGlobalRule")
202-
err := s.CreateResourceFromString(globalRuleYaml)
169+
err := s.CreateResourceFromString(fmt.Sprintf(globalRuleYaml, s.Namespace()))
203170
Expect(err).NotTo(HaveOccurred(), "creating ApisixGlobalRule")
204171

205172
By("verify initial ApisixGlobalRule status condition")
@@ -219,7 +186,7 @@ spec:
219186
resp.Header("X-New-Header").IsEmpty()
220187

221188
By("update ApisixGlobalRule")
222-
err = s.CreateResourceFromString(updatedGlobalRuleYaml)
189+
err = s.CreateResourceFromString(fmt.Sprintf(updatedGlobalRuleYaml, s.Namespace()))
223190
Expect(err).NotTo(HaveOccurred(), "updating ApisixGlobalRule")
224191

225192
By("verify updated ApisixGlobalRule status condition")
@@ -251,7 +218,7 @@ kind: ApisixGlobalRule
251218
metadata:
252219
name: test-global-rule-proxy-rewrite
253220
spec:
254-
ingressClassName: apisix
221+
ingressClassName: %s
255222
plugins:
256223
- name: proxy-rewrite
257224
enable: true
@@ -267,7 +234,7 @@ kind: ApisixGlobalRule
267234
metadata:
268235
name: test-global-rule-response-rewrite-multi
269236
spec:
270-
ingressClassName: apisix
237+
ingressClassName: %s
271238
plugins:
272239
- name: response-rewrite
273240
enable: true
@@ -278,11 +245,11 @@ spec:
278245
`
279246

280247
By("create ApisixGlobalRule with proxy-rewrite plugin")
281-
err := s.CreateResourceFromString(proxyRewriteGlobalRuleYaml)
248+
err := s.CreateResourceFromString(fmt.Sprintf(proxyRewriteGlobalRuleYaml, s.Namespace()))
282249
Expect(err).NotTo(HaveOccurred(), "creating ApisixGlobalRule with proxy-rewrite")
283250

284251
By("create ApisixGlobalRule with response-rewrite plugin")
285-
err = s.CreateResourceFromString(responseRewriteGlobalRuleYaml)
252+
err = s.CreateResourceFromString(fmt.Sprintf(responseRewriteGlobalRuleYaml, s.Namespace()))
286253
Expect(err).NotTo(HaveOccurred(), "creating ApisixGlobalRule with response-rewrite")
287254

288255
By("verify both ApisixGlobalRule status conditions")

0 commit comments

Comments
 (0)