Skip to content

Commit f6196ff

Browse files
authored
chore: differentiate the API versions for CRD testing (#2492)
* chore: differentiate the API versions for CRD testing * revert ingress.go * update test * update test
1 parent 7a6151c commit f6196ff

File tree

11 files changed

+116
-27
lines changed

11 files changed

+116
-27
lines changed

test/e2e/apisix/e2e_test.go

Lines changed: 2 additions & 1 deletion
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"

test/e2e/crds/backendtrafficpolicy.go renamed to test/e2e/crds/v1alpha1/backendtrafficpolicy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package gatewayapi
18+
package v1alpha1
1919

2020
import (
2121
"fmt"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package gatewayapi
18+
package v1alpha1
1919

2020
import (
2121
"fmt"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package gatewayapi
18+
package v1alpha1
1919

2020
import (
2121
"context"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package apisix
18+
package v2
1919

2020
import (
2121
. "github.com/onsi/ginkgo/v2"
Lines changed: 89 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package apisix
18+
package v2
1919

2020
import (
2121
"fmt"
@@ -275,9 +275,6 @@ spec:
275275
`
276276
)
277277

278-
request := func(path string, username, password string) int {
279-
return s.NewAPISIXClient().GET(path).WithBasicAuth(username, password).WithHost("httpbin").Expect().Raw().StatusCode
280-
}
281278
It("Basic tests", func() {
282279
By("apply ApisixRoute")
283280
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, defaultApisixRoute)
@@ -286,19 +283,50 @@ spec:
286283
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, basicAuth)
287284

288285
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))
290-
291-
Eventually(request).WithArguments("/get", "test-user", "test-password").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
286+
s.RequestAssert(&scaffold.RequestAssert{
287+
Method: "GET",
288+
Path: "/get",
289+
Host: "httpbin",
290+
BasicAuth: &scaffold.BasicAuth{
291+
Username: "invalid-username",
292+
Password: "invalid-password",
293+
},
294+
Check: scaffold.WithExpectedStatus(http.StatusUnauthorized),
295+
})
296+
s.RequestAssert(&scaffold.RequestAssert{
297+
Method: "GET",
298+
Path: "/get",
299+
Host: "httpbin",
300+
BasicAuth: &scaffold.BasicAuth{
301+
Username: "test-user",
302+
Password: "test-password",
303+
},
304+
Check: scaffold.WithExpectedStatus(http.StatusOK),
305+
})
292306

293307
By("Delete ApisixConsumer")
294308
err := s.DeleteResource("ApisixConsumer", "test-consumer")
295309
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))
310+
s.RequestAssert(&scaffold.RequestAssert{
311+
Method: "GET",
312+
Path: "/get",
313+
Host: "httpbin",
314+
BasicAuth: &scaffold.BasicAuth{
315+
Username: "test-user",
316+
Password: "test-password",
317+
},
318+
Check: scaffold.WithExpectedStatus(http.StatusUnauthorized),
319+
})
297320

298321
By("delete ApisixRoute")
299322
err = s.DeleteResource("ApisixRoute", "default")
300323
Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixRoute")
301-
Eventually(request).WithArguments("/headers", "", "").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound))
324+
s.RequestAssert(&scaffold.RequestAssert{
325+
Method: "GET",
326+
Path: "/get",
327+
Host: "httpbin",
328+
Check: scaffold.WithExpectedStatus(http.StatusNotFound),
329+
})
302330
})
303331

304332
It("SecretRef tests", func() {
@@ -313,25 +341,70 @@ spec:
313341
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "test-consumer"}, &apiv2.ApisixConsumer{}, basicAuthWithSecret)
314342

315343
By("verify ApisixRoute with ApisixConsumer")
316-
Eventually(request).WithArguments("/get", "", "").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusUnauthorized))
317-
Eventually(request).WithArguments("/get", "foo", "bar").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
344+
s.RequestAssert(&scaffold.RequestAssert{
345+
Method: "GET",
346+
Path: "/get",
347+
Host: "httpbin",
348+
Check: scaffold.WithExpectedStatus(http.StatusUnauthorized),
349+
})
350+
s.RequestAssert(&scaffold.RequestAssert{
351+
Method: "GET",
352+
Path: "/get",
353+
Host: "httpbin",
354+
BasicAuth: &scaffold.BasicAuth{
355+
Username: "foo",
356+
Password: "bar",
357+
},
358+
Check: scaffold.WithExpectedStatus(http.StatusOK),
359+
})
318360

319361
By("update Secret")
320362
err = s.CreateResourceFromString(secretUpdated)
321363
Expect(err).ShouldNot(HaveOccurred(), "updating Secret for ApisixConsumer")
322-
323-
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))
364+
s.RequestAssert(&scaffold.RequestAssert{
365+
Method: "GET",
366+
Path: "/get",
367+
Host: "httpbin",
368+
BasicAuth: &scaffold.BasicAuth{
369+
Username: "foo",
370+
Password: "bar",
371+
},
372+
Check: scaffold.WithExpectedStatus(http.StatusUnauthorized),
373+
})
374+
s.RequestAssert(&scaffold.RequestAssert{
375+
Method: "GET",
376+
Path: "/get",
377+
Host: "httpbin",
378+
BasicAuth: &scaffold.BasicAuth{
379+
Username: "foo-new-user",
380+
Password: "bar-new-password",
381+
},
382+
Check: scaffold.WithExpectedStatus(http.StatusOK),
383+
})
325384

326385
By("Delete ApisixConsumer")
327386
err = s.DeleteResource("ApisixConsumer", "test-consumer")
328387
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))
388+
s.RequestAssert(&scaffold.RequestAssert{
389+
Method: "GET",
390+
Path: "/get",
391+
Host: "httpbin",
392+
BasicAuth: &scaffold.BasicAuth{
393+
Username: "foo-new-user",
394+
Password: "bar-new-password",
395+
},
396+
Check: scaffold.WithExpectedStatus(http.StatusUnauthorized),
397+
})
330398

331399
By("delete ApisixRoute")
332400
err = s.DeleteResource("ApisixRoute", "default")
333401
Expect(err).ShouldNot(HaveOccurred(), "deleting ApisixRoute")
334-
Eventually(request).WithArguments("/get", "", "").WithTimeout(5 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound))
402+
s.RequestAssert(&scaffold.RequestAssert{
403+
Method: "GET",
404+
Path: "/get",
405+
Host: "httpbin",
406+
Check: scaffold.WithExpectedStatus(http.StatusNotFound),
407+
})
335408
})
336409
})
337410
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package apisix
18+
package v2
1919

2020
import (
2121
"fmt"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package apisix
18+
package v2
1919

2020
import (
2121
"fmt"
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package apisix
18+
package v2
1919

2020
import (
2121
"context"
@@ -235,7 +235,22 @@ spec:
235235
match:
236236
paths:
237237
- /*
238-
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"
238+
filter_func: |
239+
function(vars)
240+
local core = require ('apisix.core')
241+
local body, err = core.request.get_body()
242+
if not body then
243+
return false
244+
end
245+
local data, err = core.json.decode(body)
246+
if not data then
247+
return false
248+
end
249+
if data['foo'] == 'bar' then
250+
return true
251+
end
252+
return false
253+
end
239254
backends:
240255
- serviceName: httpbin-service-e2e-test
241256
servicePort: 80
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package apisix
18+
package v2
1919

2020
import (
2121
"fmt"

0 commit comments

Comments
 (0)