Skip to content

Commit fd92191

Browse files
obezpalkoclaude
andcommitted
test: add helm-unittest tests for all chart templates
31 tests across 5 suites: - deployment: image tag fallback, namespace scoping, all operator args - rbac: Role/RoleBinding are namespace-scoped, correct verbs on all resources - gateway: create flag, namespace, className, allowedRoutes, port - gatewayclass: create flag, controllerName, keep annotation - serviceaccount: create flag, custom name, namespace CI: lint and unit tests run before publish (oci job needs test job). Makefile: helm-lint and helm-test targets added. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 883ac3a commit fd92191

File tree

7 files changed

+279
-1
lines changed

7 files changed

+279
-1
lines changed

.github/workflows/helm.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,30 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13+
test:
14+
name: Lint and unit test
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
19+
steps:
20+
- uses: actions/checkout@v6
21+
22+
- name: Install Helm
23+
run: curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
24+
25+
- name: Install helm-unittest plugin
26+
run: helm plugin install https://github.com/helm-unittest/helm-unittest
27+
28+
- name: Lint
29+
run: helm lint charts/envoy-router
30+
31+
- name: Unit tests
32+
run: helm unittest charts/envoy-router
33+
1334
oci:
1435
name: Publish to GHCR (OCI)
36+
needs: test
1537
runs-on: ubuntu-latest
1638
permissions:
1739
contents: read

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ENVOY_GATEWAY_VERSION ?= v1.7.1
44
CHART_NAMESPACE ?= envoy-router
55

66
.PHONY: build test lint tidy docker-build docker-push \
7-
envoy-gateway-install install upgrade uninstall
7+
envoy-gateway-install install upgrade uninstall helm-test helm-lint
88

99
build:
1010
go build -o bin/manager ./cmd/main.go
@@ -24,6 +24,12 @@ docker-build:
2424
docker-push: docker-build
2525
docker push $(IMAGE_REPO):$(IMAGE_TAG)
2626

27+
helm-lint:
28+
helm lint charts/envoy-router
29+
30+
helm-test:
31+
helm unittest charts/envoy-router
32+
2733
## Install Envoy Gateway CRDs and controller (prerequisite)
2834
envoy-gateway-install:
2935
helm install eg oci://docker.io/envoyproxy/gateway-helm \
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
suite: Deployment
2+
templates:
3+
- templates/deployment.yaml
4+
release:
5+
namespace: test-ns
6+
7+
tests:
8+
- it: is in release namespace
9+
asserts:
10+
- equal:
11+
path: metadata.namespace
12+
value: test-ns
13+
14+
- it: uses appVersion as image tag when image.tag is empty
15+
asserts:
16+
- equal:
17+
path: spec.template.spec.containers[0].image
18+
value: ghcr.io/comet-ml/envoy-router:0.1.0
19+
20+
- it: uses custom image tag when set
21+
set:
22+
image.tag: v1.2.3
23+
asserts:
24+
- equal:
25+
path: spec.template.spec.containers[0].image
26+
value: ghcr.io/comet-ml/envoy-router:v1.2.3
27+
28+
- it: sets --gateway-namespace to release namespace
29+
asserts:
30+
- contains:
31+
path: spec.template.spec.containers[0].args
32+
content: --gateway-namespace=test-ns
33+
34+
- it: sets --watch-namespace to release namespace
35+
asserts:
36+
- contains:
37+
path: spec.template.spec.containers[0].args
38+
content: --watch-namespace=test-ns
39+
40+
- it: sets --pod-port from values
41+
set:
42+
operator.podPort: 9090
43+
asserts:
44+
- contains:
45+
path: spec.template.spec.containers[0].args
46+
content: --pod-port=9090
47+
48+
- it: sets --gateway-name from values
49+
set:
50+
operator.gatewayName: my-gateway
51+
asserts:
52+
- contains:
53+
path: spec.template.spec.containers[0].args
54+
content: --gateway-name=my-gateway
55+
56+
- it: uses the correct service account
57+
asserts:
58+
- equal:
59+
path: spec.template.spec.serviceAccountName
60+
value: RELEASE-NAME-envoy-router
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
suite: Gateway
2+
templates:
3+
- templates/gateway.yaml
4+
release:
5+
namespace: test-ns
6+
7+
tests:
8+
- it: is created by default
9+
asserts:
10+
- hasDocuments:
11+
count: 1
12+
- isKind:
13+
of: Gateway
14+
15+
- it: is in release namespace
16+
asserts:
17+
- equal:
18+
path: metadata.namespace
19+
value: test-ns
20+
21+
- it: uses gateway.className
22+
asserts:
23+
- equal:
24+
path: spec.gatewayClassName
25+
value: envoy-router
26+
27+
- it: defaults allowedRoutes to Same
28+
asserts:
29+
- equal:
30+
path: spec.listeners[0].allowedRoutes.namespaces.from
31+
value: Same
32+
33+
- it: uses gateway.port for listener
34+
asserts:
35+
- equal:
36+
path: spec.listeners[0].port
37+
value: 80
38+
39+
- it: custom port is reflected in listener
40+
set:
41+
gateway.port: 8080
42+
asserts:
43+
- equal:
44+
path: spec.listeners[0].port
45+
value: 8080
46+
47+
- it: is not created when gateway.create is false
48+
set:
49+
gateway.create: false
50+
asserts:
51+
- hasDocuments:
52+
count: 0
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
suite: GatewayClass
2+
templates:
3+
- templates/gatewayclass.yaml
4+
release:
5+
namespace: test-ns
6+
7+
tests:
8+
- it: is created by default
9+
asserts:
10+
- hasDocuments:
11+
count: 1
12+
- isKind:
13+
of: GatewayClass
14+
15+
- it: references the Envoy Gateway controller
16+
asserts:
17+
- equal:
18+
path: spec.controllerName
19+
value: gateway.envoyproxy.io/gatewayclass-controller
20+
21+
- it: has helm keep annotation to survive namespace uninstall
22+
asserts:
23+
- equal:
24+
path: metadata.annotations["helm.sh/resource-policy"]
25+
value: keep
26+
27+
- it: uses gateway.className as name
28+
asserts:
29+
- equal:
30+
path: metadata.name
31+
value: envoy-router
32+
33+
- it: is not created when gateway.createClass is false
34+
set:
35+
gateway.createClass: false
36+
asserts:
37+
- hasDocuments:
38+
count: 0
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
suite: RBAC
2+
release:
3+
namespace: test-ns
4+
5+
tests:
6+
- it: Role is namespace-scoped (not ClusterRole)
7+
template: templates/role.yaml
8+
asserts:
9+
- isKind:
10+
of: Role
11+
- equal:
12+
path: metadata.namespace
13+
value: test-ns
14+
15+
- it: RoleBinding is namespace-scoped (not ClusterRoleBinding)
16+
template: templates/rolebinding.yaml
17+
asserts:
18+
- isKind:
19+
of: RoleBinding
20+
- equal:
21+
path: metadata.namespace
22+
value: test-ns
23+
24+
- it: RoleBinding references Role not ClusterRole
25+
template: templates/rolebinding.yaml
26+
asserts:
27+
- equal:
28+
path: roleRef.kind
29+
value: Role
30+
31+
- it: RoleBinding subject namespace matches release namespace
32+
template: templates/rolebinding.yaml
33+
asserts:
34+
- equal:
35+
path: subjects[0].namespace
36+
value: test-ns
37+
38+
- it: Role grants required verbs on pods
39+
template: templates/role.yaml
40+
asserts:
41+
- contains:
42+
path: rules
43+
content:
44+
apiGroups: [""]
45+
resources: ["pods"]
46+
verbs: ["get", "list", "watch", "update", "patch"]
47+
48+
- it: Role grants full CRUD on httproutes
49+
template: templates/role.yaml
50+
asserts:
51+
- contains:
52+
path: rules
53+
content:
54+
apiGroups: ["gateway.networking.k8s.io"]
55+
resources: ["httproutes"]
56+
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
57+
58+
- it: Role grants full CRUD on services and endpoints
59+
template: templates/role.yaml
60+
asserts:
61+
- contains:
62+
path: rules
63+
content:
64+
apiGroups: [""]
65+
resources: ["services", "endpoints"]
66+
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
suite: ServiceAccount
2+
templates:
3+
- templates/serviceaccount.yaml
4+
release:
5+
namespace: test-ns
6+
7+
tests:
8+
- it: is created by default
9+
asserts:
10+
- hasDocuments:
11+
count: 1
12+
- isKind:
13+
of: ServiceAccount
14+
15+
- it: is in release namespace
16+
asserts:
17+
- equal:
18+
path: metadata.namespace
19+
value: test-ns
20+
21+
- it: is not created when serviceAccount.create is false
22+
set:
23+
serviceAccount.create: false
24+
asserts:
25+
- hasDocuments:
26+
count: 0
27+
28+
- it: uses custom name when serviceAccount.name is set
29+
set:
30+
serviceAccount.name: my-sa
31+
asserts:
32+
- equal:
33+
path: metadata.name
34+
value: my-sa

0 commit comments

Comments
 (0)