Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions test/e2e/gatewayapi/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ import (
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
)

// helper to apply an HTTPRoute and run a list of request assertions
func applyHTTPRouteAndAssert(s *scaffold.Scaffold, route string, asserts []scaffold.RequestAssert) {
s.ResourceApplied("HTTPRoute", "httpbin", route, 1)
for i := range asserts {
s.RequestAssert(&asserts[i])
}
}

var _ = Describe("Test HTTPRoute", Label("networking.k8s.io", "httproute"), func() {
s := scaffold.NewDefaultScaffold()

Expand Down Expand Up @@ -667,6 +675,112 @@ spec:
Interval: time.Second * 2,
})
})
It("HTTPRoute with multiple hostnames", func() {
route := fmt.Sprintf(`
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: httpbin
spec:
parentRefs:
- name: %s
hostnames:
- httpbin.example
- httpbin2.example
rules:
- matches:
- path:
type: Exact
value: /get
backendRefs:
- name: httpbin-service-e2e-test
port: 80
`, s.Namespace())

asserts := []scaffold.RequestAssert{
{
Method: "GET",
Path: "/get",
Host: "httpbin.example",
Check: scaffold.WithExpectedStatus(http.StatusOK),
Timeout: 30 * time.Second,
Interval: 2 * time.Second,
},
{
Method: "GET",
Path: "/get",
Host: "httpbin2.example",
Check: scaffold.WithExpectedStatus(http.StatusOK),
Timeout: 30 * time.Second,
Interval: 2 * time.Second,
},
{
Method: "GET",
Path: "/get",
Host: "httpbin3.example",
Check: scaffold.WithExpectedStatus(http.StatusNotFound),
Timeout: 30 * time.Second,
Interval: 2 * time.Second,
},
}

applyHTTPRouteAndAssert(s, route, asserts)
})

It("HTTPRoute with multiple matches in one rule", func() {
route := fmt.Sprintf(`
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: httpbin
spec:
parentRefs:
- name: %s
hostnames:
- httpbin.example
rules:
- matches:
- path:
type: Exact
value: /get
- path:
type: Exact
value: /ip
backendRefs:
- name: httpbin-service-e2e-test
port: 80
`, s.Namespace())

asserts := []scaffold.RequestAssert{
{
Method: "GET",
Path: "/get",
Host: "httpbin.example",
Check: scaffold.WithExpectedStatus(http.StatusOK),
Timeout: 30 * time.Second,
Interval: 2 * time.Second,
},
{
Method: "GET",
Path: "/ip",
Host: "httpbin.example",
Check: scaffold.WithExpectedStatus(http.StatusOK),
Timeout: 30 * time.Second,
Interval: 2 * time.Second,
},
{
Method: "GET",
Path: "/status",
Host: "httpbin.example",
Check: scaffold.WithExpectedStatus(http.StatusNotFound),
Timeout: 30 * time.Second,
Interval: 2 * time.Second,
},
}

applyHTTPRouteAndAssert(s, route, asserts)
})

})

Context("HTTPRoute Rule Match", func() {
Expand Down
Loading