This is an automated email from the ASF dual-hosted git repository. alinsran pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push: new f6196ff5 chore: differentiate the API versions for CRD testing (#2492) f6196ff5 is described below commit f6196ff50c20d0564b79179f668673e9b5582c7d Author: AlinsRan <alins...@apache.org> AuthorDate: Thu Jul 24 15:20:15 2025 +0800 chore: differentiate the API versions for CRD testing (#2492) * chore: differentiate the API versions for CRD testing * revert ingress.go * update test * update test --- test/e2e/apisix/e2e_test.go | 3 +- .../crds/{ => v1alpha1}/backendtrafficpolicy.go | 2 +- test/e2e/crds/{ => v1alpha1}/consumer.go | 2 +- test/e2e/crds/{ => v1alpha1}/gatewayproxy.go | 2 +- test/e2e/{apisix => crds/v2}/basic.go | 2 +- test/e2e/{apisix => crds/v2}/consumer.go | 105 +++++++++++++++++---- test/e2e/{apisix => crds/v2}/globalrule.go | 2 +- test/e2e/{apisix => crds/v2}/pluginconfig.go | 2 +- test/e2e/{apisix => crds/v2}/route.go | 19 +++- test/e2e/{apisix => crds/v2}/status.go | 2 +- test/e2e/{apisix => crds/v2}/tls.go | 2 +- 11 files changed, 116 insertions(+), 27 deletions(-) diff --git a/test/e2e/apisix/e2e_test.go b/test/e2e/apisix/e2e_test.go index ea814157..03fe0ca6 100644 --- a/test/e2e/apisix/e2e_test.go +++ b/test/e2e/apisix/e2e_test.go @@ -24,7 +24,8 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - _ "github.com/apache/apisix-ingress-controller/test/e2e/crds" + _ "github.com/apache/apisix-ingress-controller/test/e2e/crds/v1alpha1" + _ "github.com/apache/apisix-ingress-controller/test/e2e/crds/v2" "github.com/apache/apisix-ingress-controller/test/e2e/framework" _ "github.com/apache/apisix-ingress-controller/test/e2e/gatewayapi" _ "github.com/apache/apisix-ingress-controller/test/e2e/ingress" diff --git a/test/e2e/crds/backendtrafficpolicy.go b/test/e2e/crds/v1alpha1/backendtrafficpolicy.go similarity index 99% rename from test/e2e/crds/backendtrafficpolicy.go rename to test/e2e/crds/v1alpha1/backendtrafficpolicy.go index 82b88a20..d91888c5 100644 --- a/test/e2e/crds/backendtrafficpolicy.go +++ b/test/e2e/crds/v1alpha1/backendtrafficpolicy.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package gatewayapi +package v1alpha1 import ( "fmt" diff --git a/test/e2e/crds/consumer.go b/test/e2e/crds/v1alpha1/consumer.go similarity index 99% rename from test/e2e/crds/consumer.go rename to test/e2e/crds/v1alpha1/consumer.go index 26b8554f..d2db2a5b 100644 --- a/test/e2e/crds/consumer.go +++ b/test/e2e/crds/v1alpha1/consumer.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package gatewayapi +package v1alpha1 import ( "fmt" diff --git a/test/e2e/crds/gatewayproxy.go b/test/e2e/crds/v1alpha1/gatewayproxy.go similarity index 99% rename from test/e2e/crds/gatewayproxy.go rename to test/e2e/crds/v1alpha1/gatewayproxy.go index 70773f6f..10cca3ea 100644 --- a/test/e2e/crds/gatewayproxy.go +++ b/test/e2e/crds/v1alpha1/gatewayproxy.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package gatewayapi +package v1alpha1 import ( "context" diff --git a/test/e2e/apisix/basic.go b/test/e2e/crds/v2/basic.go similarity index 99% rename from test/e2e/apisix/basic.go rename to test/e2e/crds/v2/basic.go index 245419f1..1d16a9f7 100644 --- a/test/e2e/apisix/basic.go +++ b/test/e2e/crds/v2/basic.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package apisix +package v2 import ( . "github.com/onsi/ginkgo/v2" diff --git a/test/e2e/apisix/consumer.go b/test/e2e/crds/v2/consumer.go similarity index 79% rename from test/e2e/apisix/consumer.go rename to test/e2e/crds/v2/consumer.go index 29ceb667..ee243fb1 100644 --- a/test/e2e/apisix/consumer.go +++ b/test/e2e/crds/v2/consumer.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package apisix +package v2 import ( "fmt" @@ -275,9 +275,6 @@ spec: ` ) - request := func(path string, username, password string) int { - return s.NewAPISIXClient().GET(path).WithBasicAuth(username, password).WithHost("httpbin").Expect().Raw().StatusCode - } It("Basic tests", func() { By("apply ApisixRoute") applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, defaultApisixRoute) @@ -286,19 +283,50 @@ spec: applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, basicAuth) By("verify ApisixRoute with ApisixConsumer") - Eventually(request).WithArguments("/get", "invalid-username", "invalid-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized)) - - Eventually(request).WithArguments("/get", "test-user", "test-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin", + BasicAuth: &scaffold.BasicAuth{ + Username: "invalid-username", + Password: "invalid-password", + }, + Check: scaffold.WithExpectedStatus(http.StatusUnauthorized), + }) + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin", + BasicAuth: &scaffold.BasicAuth{ + Username: "test-user", + Password: "test-password", + }, + Check: scaffold.WithExpectedStatus(http.StatusOK), + }) By("Delete ApisixConsumer") err := s.DeleteResource("ApisixConsumer", "test-consumer") Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixConsumer") - Eventually(request).WithArguments("/get", "test-user", "test-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized)) + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin", + BasicAuth: &scaffold.BasicAuth{ + Username: "test-user", + Password: "test-password", + }, + Check: scaffold.WithExpectedStatus(http.StatusUnauthorized), + }) By("delete ApisixRoute") err = s.DeleteResource("ApisixRoute", "default") Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixRoute") - Eventually(request).WithArguments("/headers", "", "").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin", + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + }) }) It("SecretRef tests", func() { @@ -313,25 +341,70 @@ spec: applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, basicAuthWithSecret) By("verify ApisixRoute with ApisixConsumer") - Eventually(request).WithArguments("/get", "", "").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized)) - Eventually(request).WithArguments("/get", "foo", "bar").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin", + Check: scaffold.WithExpectedStatus(http.StatusUnauthorized), + }) + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin", + BasicAuth: &scaffold.BasicAuth{ + Username: "foo", + Password: "bar", + }, + Check: scaffold.WithExpectedStatus(http.StatusOK), + }) By("update Secret") err = s.CreateResourceFromString(secretUpdated) Expect(err).ShouldNot(HaveOccurred(), "updating Secret for ApisixConsumer") - - Eventually(request).WithArguments("/get", "foo", "bar").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized)) - Eventually(request).WithArguments("/get", "foo-new-user", "bar-new-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin", + BasicAuth: &scaffold.BasicAuth{ + Username: "foo", + Password: "bar", + }, + Check: scaffold.WithExpectedStatus(http.StatusUnauthorized), + }) + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin", + BasicAuth: &scaffold.BasicAuth{ + Username: "foo-new-user", + Password: "bar-new-password", + }, + Check: scaffold.WithExpectedStatus(http.StatusOK), + }) By("Delete ApisixConsumer") err = s.DeleteResource("ApisixConsumer", "test-consumer") Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixConsumer") - Eventually(request).WithArguments("/get", "foo-new-user", "bar-new-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized)) + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin", + BasicAuth: &scaffold.BasicAuth{ + Username: "foo-new-user", + Password: "bar-new-password", + }, + Check: scaffold.WithExpectedStatus(http.StatusUnauthorized), + }) By("delete ApisixRoute") err = s.DeleteResource("ApisixRoute", "default") Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixRoute") - Eventually(request).WithArguments("/get", "", "").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) + s.RequestAssert(&scaffold.RequestAssert{ + Method: "GET", + Path: "/get", + Host: "httpbin", + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + }) }) }) }) diff --git a/test/e2e/apisix/globalrule.go b/test/e2e/crds/v2/globalrule.go similarity index 99% rename from test/e2e/apisix/globalrule.go rename to test/e2e/crds/v2/globalrule.go index 0e3f2f41..738d43e0 100644 --- a/test/e2e/apisix/globalrule.go +++ b/test/e2e/crds/v2/globalrule.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package apisix +package v2 import ( "fmt" diff --git a/test/e2e/apisix/pluginconfig.go b/test/e2e/crds/v2/pluginconfig.go similarity index 99% rename from test/e2e/apisix/pluginconfig.go rename to test/e2e/crds/v2/pluginconfig.go index 2c4c27fc..589427eb 100644 --- a/test/e2e/apisix/pluginconfig.go +++ b/test/e2e/crds/v2/pluginconfig.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package apisix +package v2 import ( "fmt" diff --git a/test/e2e/apisix/route.go b/test/e2e/crds/v2/route.go similarity index 97% rename from test/e2e/apisix/route.go rename to test/e2e/crds/v2/route.go index c921a17e..ce1b9864 100644 --- a/test/e2e/apisix/route.go +++ b/test/e2e/crds/v2/route.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package apisix +package v2 import ( "context" @@ -235,7 +235,22 @@ spec: match: paths: - /* - 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" + filter_func: | + function(vars) + local core = require ('apisix.core') + local body, err = core.request.get_body() + if not body then + return false + end + local data, err = core.json.decode(body) + if not data then + return false + end + if data['foo'] == 'bar' then + return true + end + return false + end backends: - serviceName: httpbin-service-e2e-test servicePort: 80 diff --git a/test/e2e/apisix/status.go b/test/e2e/crds/v2/status.go similarity index 99% rename from test/e2e/apisix/status.go rename to test/e2e/crds/v2/status.go index 1193bd69..d1fadc28 100644 --- a/test/e2e/apisix/status.go +++ b/test/e2e/crds/v2/status.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package apisix +package v2 import ( "fmt" diff --git a/test/e2e/apisix/tls.go b/test/e2e/crds/v2/tls.go similarity index 99% rename from test/e2e/apisix/tls.go rename to test/e2e/crds/v2/tls.go index b81020b4..56f9cc89 100644 --- a/test/e2e/apisix/tls.go +++ b/test/e2e/crds/v2/tls.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package apisix +package v2 import ( "context"