Skip to content

Commit f9cdfb6

Browse files
authored
chore: add crd v2 API testing for API7 (#190)
1 parent 2647195 commit f9cdfb6

File tree

15 files changed

+58
-24
lines changed

15 files changed

+58
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ KIND_NAME ?= apisix-ingress-cluster
2929

3030
GATEAY_API_VERSION ?= v1.2.0
3131
DASHBOARD_VERSION ?= dev
32-
ADC_VERSION ?= 0.19.0
32+
ADC_VERSION ?= 0.20.0
3333

3434
TEST_TIMEOUT ?= 80m
3535
TEST_DIR ?= ./test/e2e/

internal/provider/adc/adc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (d *adcClient) Update(ctx context.Context, tctx *provider.TranslateContext,
194194
// This mode is full synchronization,
195195
// which only needs to be saved in cache
196196
// and triggered by a timer for synchronization
197-
if d.BackendMode == BackendModeAPISIXStandalone || d.BackendMode == BackendModeAPISIX || apiv2.Is(obj) {
197+
if d.BackendMode == BackendModeAPISIXStandalone || d.BackendMode == BackendModeAPISIX {
198198
return nil
199199
}
200200

test/e2e/apisix/e2e_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import (
2424
. "github.com/onsi/ginkgo/v2"
2525
. "github.com/onsi/gomega"
2626

27-
_ "github.com/apache/apisix-ingress-controller/test/e2e/crds"
27+
_ "github.com/apache/apisix-ingress-controller/test/e2e/crds/v1alpha1"
28+
_ "github.com/apache/apisix-ingress-controller/test/e2e/crds/v2"
2829
"github.com/apache/apisix-ingress-controller/test/e2e/framework"
2930
_ "github.com/apache/apisix-ingress-controller/test/e2e/gatewayapi"
3031
_ "github.com/apache/apisix-ingress-controller/test/e2e/ingress"
@@ -38,9 +39,7 @@ func TestAPISIXE2E(t *testing.T) {
3839
_ = framework.NewFramework()
3940

4041
// init newDeployer function
41-
scaffold.NewDeployer = func(s *scaffold.Scaffold) scaffold.Deployer {
42-
return scaffold.NewAPISIXDeployer(s)
43-
}
42+
scaffold.NewDeployer = scaffold.NewAPISIXDeployer
4443

4544
_, _ = fmt.Fprintf(GinkgoWriter, "Starting APISIX standalone e2e suite\n")
4645
RunSpecs(t, "apisix standalone e2e suite")
File renamed without changes.

test/e2e/apisix/consumer.go renamed to test/e2e/crds/v2/consumer.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,17 @@ spec:
286286
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, basicAuth)
287287

288288
By("verify ApisixRoute with ApisixConsumer")
289-
Eventually(request).WithArguments("/get", "invalid-username", "invalid-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized))
289+
Eventually(request).WithArguments("/get", "invalid-username", "invalid-password").
290+
WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized))
290291

291292
Eventually(request).WithArguments("/get", "test-user", "test-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
292293

293294
By("Delete ApisixConsumer")
294295
err := s.DeleteResource("ApisixConsumer", "test-consumer")
295296
Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixConsumer")
296-
Eventually(request).WithArguments("/get", "test-user", "test-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized))
297+
Eventually(request).WithArguments("/get", "test-user", "test-password").
298+
WithTimeout(5 * time.Second).ProbeEvery(time.Second).
299+
Should(Equal(http.StatusUnauthorized))
297300

298301
By("delete ApisixRoute")
299302
err = s.DeleteResource("ApisixRoute", "default")
@@ -321,12 +324,16 @@ spec:
321324
Expect(err).ShouldNot(HaveOccurred(), "updating Secret for ApisixConsumer")
322325

323326
Eventually(request).WithArguments("/get", "foo", "bar").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized))
324-
Eventually(request).WithArguments("/get", "foo-new-user", "bar-new-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
327+
Eventually(request).WithArguments("/get", "foo-new-user", "bar-new-password").
328+
WithTimeout(5 * time.Second).ProbeEvery(time.Second).
329+
Should(Equal(http.StatusOK))
325330

326331
By("Delete ApisixConsumer")
327332
err = s.DeleteResource("ApisixConsumer", "test-consumer")
328333
Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixConsumer")
329-
Eventually(request).WithArguments("/get", "foo-new-user", "bar-new-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized))
334+
Eventually(request).WithArguments("/get", "foo-new-user", "bar-new-password").
335+
WithTimeout(5 * time.Second).ProbeEvery(time.Second).
336+
Should(Equal(http.StatusUnauthorized))
330337

331338
By("delete ApisixRoute")
332339
err = s.DeleteResource("ApisixRoute", "default")

test/e2e/apisix/globalrule.go renamed to test/e2e/crds/v2/globalrule.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ spec:
8888

8989
Context("ApisixGlobalRule Basic Operations", func() {
9090
BeforeEach(func() {
91+
if s.Deployer.Name() == "api7ee" {
92+
Skip("GlobalRule is not supported in api7ee")
93+
}
9194
By("create GatewayProxy")
9295
gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey())
9396
err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default")
File renamed without changes.

test/e2e/apisix/route.go renamed to test/e2e/crds/v2/route.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ spec:
189189
})
190190

191191
It("Test ApisixRoute filterFunc", func() {
192+
if s.Deployer.Name() == "api7ee" {
193+
Skip("filterFunc is not supported in api7ee")
194+
}
192195
const apisixRouteSpec = `
193196
apiVersion: apisix.apache.org/v2
194197
kind: ApisixRoute
@@ -201,7 +204,22 @@ spec:
201204
match:
202205
paths:
203206
- /*
204-
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"
207+
filter_func: |
208+
function(vars)
209+
local core = require ('apisix.core')
210+
local body, err = core.request.get_body()
211+
if not body then
212+
return false
213+
end
214+
local data, err = core.json.decode(body)
215+
if not data then
216+
return false
217+
end
218+
if data['foo'] == 'bar' then
219+
return true
220+
end
221+
return false
222+
end
205223
backends:
206224
- serviceName: httpbin-service-e2e-test
207225
servicePort: 80

test/e2e/apisix/tls.go renamed to test/e2e/crds/v2/tls.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ var _ = Describe("Test ApisixTls", Label("apisix.apache.org", "v2", "apisixtls")
126126
err = s.DeleteResourceFromStringWithNamespace(ingressClassYamlTls, "")
127127
Expect(err).ShouldNot(HaveOccurred(), "deleting IngressClass")
128128
})
129+
normalizePEM := func(s string) string {
130+
return strings.TrimSpace(s)
131+
}
129132

130133
It("Basic ApisixTls test", func() {
131134
const host = "api6.com"
@@ -252,11 +255,11 @@ spec:
252255
assert.Nil(GinkgoT(), err, "list tls error")
253256
assert.Len(GinkgoT(), tls, 1, "tls number not expect")
254257
assert.Len(GinkgoT(), tls[0].Certificates, 1, "length of certificates not expect")
255-
assert.Equal(GinkgoT(), serverCert, tls[0].Certificates[0].Certificate, "tls cert not expect")
258+
assert.Equal(GinkgoT(), normalizePEM(serverCert), normalizePEM(tls[0].Certificates[0].Certificate), "tls cert not expect")
256259
assert.ElementsMatch(GinkgoT(), []string{host}, tls[0].Snis)
257260
assert.NotNil(GinkgoT(), tls[0].Client, "client configuration should not be nil")
258261
assert.NotEmpty(GinkgoT(), tls[0].Client.CA, "client CA should not be empty")
259-
assert.Equal(GinkgoT(), caCert, tls[0].Client.CA, "client CA should be test-ca-secret")
262+
assert.Equal(GinkgoT(), normalizePEM(caCert), normalizePEM(tls[0].Client.CA), "client CA should be test-ca-secret")
260263
assert.Equal(GinkgoT(), int64(1), *tls[0].Client.Depth, "client depth should be 1")
261264
})
262265

0 commit comments

Comments
 (0)