helm-charts/charts/library/common-test/tests/route/values_test.yaml
2024-03-08 08:51:40 +01:00

346 lines
9.6 KiB
YAML

---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: route values
templates:
- common.yaml
tests:
- it: setting gateway should pass
set:
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
asserts:
- documentIndex: &HTTPRouteDocument 1
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.parentRefs[0].name
value: parentName
- documentIndex: *HTTPRouteDocument
equal:
path: spec.parentRefs[0].namespace
value: parentNamespace
- it: custom host and path should pass
set:
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
hostnames:
- chart-test.local
asserts:
- documentIndex: &HTTPRouteDocument 1
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.hostnames[0]
value: chart-test.local
- it: custom host with template
set:
route.main:
parentRefs:
- name: parentName
namespace: parentNamespace
hostnames:
- "{{ .Release.Name }}.local"
asserts:
- documentIndex: &HTTPRouteDocument 1
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.hostnames[0]
value: RELEASE-NAME.local
- it: path matches should only be used for HTTPRoutes and GRPCRoutes
set:
route:
main:
kind: HTTPRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
kind: Service
weight: 1
matches:
- path:
type: PathPrefix
value: /test
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
timeouts:
backendRequest: 30s
grpc:
kind: GRPCRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
kind: Service
weight: 1
matches:
- path:
type: PathPrefix
value: /test
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
tcp:
kind: TCPRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
kind: Service
weight: 1
matches:
- path:
type: PathPrefix
value: /test
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
tls:
kind: TLSRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
kind: Service
weight: 1
matches:
- path:
type: PathPrefix
value: /test
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
udp:
kind: UDPRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
kind: Service
weight: 1
matches:
- path:
type: PathPrefix
value: /test
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
asserts:
- documentIndex: &GRPCRouteDocument 1
isKind:
of: GRPCRoute
- documentIndex: *GRPCRouteDocument
equal:
path: spec.rules[0].matches
value:
- path:
type: PathPrefix
value: /test
- documentIndex: *GRPCRouteDocument
equal:
path: spec.rules[0].filters
value:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
- documentIndex: &HTTPRouteDocument 2
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.rules[0].matches
value:
- path:
type: PathPrefix
value: /test
- documentIndex: *HTTPRouteDocument
equal:
path: spec.rules[0].filters
value:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: ""
- documentIndex: &TCPRouteDocument 3
isKind:
of: TCPRoute
- documentIndex: *TCPRouteDocument
notExists:
path: spec.rules[0].matches
- documentIndex: *TCPRouteDocument
notExists:
path: spec.rules[0].filters
- documentIndex: &TLSRouteDocument 4
isKind:
of: TLSRoute
- documentIndex: *TLSRouteDocument
notExists:
path: spec.rules[0].matches
- documentIndex: *TLSRouteDocument
notExists:
path: spec.rules[0].filters
- documentIndex: &UDPRouteDocument 5
isKind:
of: UDPRoute
- documentIndex: *UDPRouteDocument
notExists:
path: spec.rules[0].matches
- documentIndex: *UDPRouteDocument
notExists:
path: spec.rules[0].filters
- documentIndex: *UDPRouteDocument
notExists:
path: spec.rules[0].timeouts
- it: hostnames shouldn't be used for TCPRoutes and UDPRoutes
set:
route:
main:
enabled: true
kind: TCPRoute
hostnames:
- chart-test.local
parentRefs:
- name: parentName
namespace: parentNamespace
udp:
enabled: true
kind: UDPRoute
hostnames:
- chart-test.local
parentRefs:
- name: parentName
namespace: parentNamespace
asserts:
- documentIndex: &TCPRouteDocument 1
isKind:
of: TCPRoute
- documentIndex: *TCPRouteDocument
notExists:
path: spec.hostnames
- documentIndex: &UDPRouteDocument 2
isKind:
of: UDPRoute
- documentIndex: *UDPRouteDocument
notExists:
path: spec.hostnames
- it: sectionName in parentRefs should be optional
set:
route:
main:
enabled: true
parentRefs:
- name: parentName
namespace: parentNamespace
second:
enabled: true
parentRefs:
- name: parentName
namespace: parentNamespace
sectionName: parentSection
asserts:
- documentIndex: &HTTPRouteDocumentFirst 1
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocumentFirst
notExists:
path: spec.parentRefs[0].sectionName
- documentIndex: &HTTPRouteDocumentSecond 2
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocumentSecond
equal:
path: spec.parentRefs[0].sectionName
value: parentSection
- it: timeouts should only be used for HTTPRoutes
set:
route:
main:
enabled: true
kind: HTTPRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
timeouts:
backendRequest: 30s
grpc:
enabled: true
kind: GRPCRoute
parentRefs:
- name: parentName
namespace: parentNamespace
rules:
- backendRefs:
- name: test
namespace: test
matches:
- path:
type: PathPrefix
value: /test
timeouts:
backendRequest: 10s
asserts:
- documentIndex: &GRPCRouteDocument 1
isKind:
of: GRPCRoute
- documentIndex: *GRPCRouteDocument
notExists:
path: spec.rules[0].timeouts.backendRequest
- documentIndex: &HTTPRouteDocument 2
isKind:
of: HTTPRoute
- documentIndex: *HTTPRouteDocument
equal:
path: spec.rules[0].timeouts.backendRequest
value: 30s