Skip to content

Commit

Permalink
Add unit test coverage for clusterrole + podsecuritypolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancoleman committed Oct 28, 2022
1 parent 5af4a55 commit f7c9e8f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions charts/consul/test/unit/api-gateway-controller-clusterrole.bats
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ load _helpers
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "apiGateway/ClusterRole: uses PodSecurityPolicy with apiGateway.enabled=true and global.enablePodSecurityPolicies=true" {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-controller-clusterrole.yaml \
--set 'global.enablePodSecurityPolicies=true' \
--set 'apiGateway.enabled=true' \
--set 'apiGateway.image=foo' \
. | tee /dev/stderr |
yq '.rules[] | select(.resourceNames[] == "release-name-consul-api-gateway-controller") | select(.resources[] == "podsecuritypolicies") | length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bats

load _helpers

@test "apiGateway/PodSecurityPolicy: disabled by default" {
cd `chart_dir`
assert_empty helm template \
-s templates/api-gateway-controller-podsecuritypolicy.yaml \
.
}

@test "apiGateway/PodSecurityPolicy: enabled with apiGateway.enabled=true and global.enablePodSecurityPolicies=true" {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-controller-podsecuritypolicy.yaml \
--set 'global.enablePodSecurityPolicies=true' \
--set 'apiGateway.enabled=true' \
--set 'apiGateway.image=foo' \
. | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

0 comments on commit f7c9e8f

Please sign in to comment.