@@ -37,6 +37,14 @@ import (
3737 "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
3838)
3939
40+ // helper to apply an HTTPRoute and run a list of request assertions
41+ func applyHTTPRouteAndAssert (s * scaffold.Scaffold , route string , asserts []scaffold.RequestAssert ) {
42+ s .ResourceApplied ("HTTPRoute" , "httpbin" , route , 1 )
43+ for i := range asserts {
44+ s .RequestAssert (& asserts [i ])
45+ }
46+ }
47+
4048var _ = Describe ("Test HTTPRoute" , Label ("networking.k8s.io" , "httproute" ), func () {
4149 s := scaffold .NewDefaultScaffold ()
4250
@@ -667,6 +675,112 @@ spec:
667675 Interval : time .Second * 2 ,
668676 })
669677 })
678+ It ("HTTPRoute with multiple hostnames" , func () {
679+ route := fmt .Sprintf (`
680+ apiVersion: gateway.networking.k8s.io/v1
681+ kind: HTTPRoute
682+ metadata:
683+ name: httpbin
684+ spec:
685+ parentRefs:
686+ - name: %s
687+ hostnames:
688+ - httpbin.example
689+ - httpbin2.example
690+ rules:
691+ - matches:
692+ - path:
693+ type: Exact
694+ value: /get
695+ backendRefs:
696+ - name: httpbin-service-e2e-test
697+ port: 80
698+ ` , s .Namespace ())
699+
700+ asserts := []scaffold.RequestAssert {
701+ {
702+ Method : "GET" ,
703+ Path : "/get" ,
704+ Host : "httpbin.example" ,
705+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
706+ Timeout : 30 * time .Second ,
707+ Interval : 2 * time .Second ,
708+ },
709+ {
710+ Method : "GET" ,
711+ Path : "/get" ,
712+ Host : "httpbin2.example" ,
713+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
714+ Timeout : 30 * time .Second ,
715+ Interval : 2 * time .Second ,
716+ },
717+ {
718+ Method : "GET" ,
719+ Path : "/get" ,
720+ Host : "httpbin3.example" ,
721+ Check : scaffold .WithExpectedStatus (http .StatusNotFound ),
722+ Timeout : 30 * time .Second ,
723+ Interval : 2 * time .Second ,
724+ },
725+ }
726+
727+ applyHTTPRouteAndAssert (s , route , asserts )
728+ })
729+
730+ It ("HTTPRoute with multiple matches in one rule" , func () {
731+ route := fmt .Sprintf (`
732+ apiVersion: gateway.networking.k8s.io/v1
733+ kind: HTTPRoute
734+ metadata:
735+ name: httpbin
736+ spec:
737+ parentRefs:
738+ - name: %s
739+ hostnames:
740+ - httpbin.example
741+ rules:
742+ - matches:
743+ - path:
744+ type: Exact
745+ value: /get
746+ - path:
747+ type: Exact
748+ value: /ip
749+ backendRefs:
750+ - name: httpbin-service-e2e-test
751+ port: 80
752+ ` , s .Namespace ())
753+
754+ asserts := []scaffold.RequestAssert {
755+ {
756+ Method : "GET" ,
757+ Path : "/get" ,
758+ Host : "httpbin.example" ,
759+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
760+ Timeout : 30 * time .Second ,
761+ Interval : 2 * time .Second ,
762+ },
763+ {
764+ Method : "GET" ,
765+ Path : "/ip" ,
766+ Host : "httpbin.example" ,
767+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
768+ Timeout : 30 * time .Second ,
769+ Interval : 2 * time .Second ,
770+ },
771+ {
772+ Method : "GET" ,
773+ Path : "/status" ,
774+ Host : "httpbin.example" ,
775+ Check : scaffold .WithExpectedStatus (http .StatusNotFound ),
776+ Timeout : 30 * time .Second ,
777+ Interval : 2 * time .Second ,
778+ },
779+ }
780+
781+ applyHTTPRouteAndAssert (s , route , asserts )
782+ })
783+
670784 })
671785
672786 Context ("HTTPRoute Rule Match" , func () {
0 commit comments