Skip to content

Commit

Permalink
fix global.acls.manageSystemACLs tests
Browse files Browse the repository at this point in the history
Assuming that volumes will always be at a fixed positions in a list
volumes won't work. Use `select(.name ...` to find them.

Remove redundant queries/checks, and also change the names of local
variables so the tests read easier.
  • Loading branch information
eb4x committed Jun 29, 2022
1 parent 1bf051c commit 55046b8
Showing 1 changed file with 19 additions and 29 deletions.
48 changes: 19 additions & 29 deletions charts/consul/test/unit/client-daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1074,29 +1074,22 @@ load _helpers

@test "client/DaemonSet: aclconfig volume is created when global.acls.manageSystemACLs=true" {
cd `chart_dir`
local actual=$(helm template \
local volume_name=$(helm template \
-s templates/client-daemonset.yaml \
--set 'global.acls.manageSystemACLs=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.volumes[3].name == "aclconfig"' | tee /dev/stderr)
[ "${actual}" = "true" ]
yq -r '.spec.template.spec.volumes[] | select(.name == "aclconfig") | .name' | tee /dev/stderr)
[ "${volume_name}" = "aclconfig" ]
}

@test "client/DaemonSet: aclconfig volumeMount is created when global.acls.manageSystemACLs=true" {
cd `chart_dir`
local object=$(helm template \
local mount_path=$(helm template \
-s templates/client-daemonset.yaml \
--set 'global.acls.manageSystemACLs=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].volumeMounts[3]' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.name' | tee /dev/stderr)
[ "${actual}" = "aclconfig" ]

local actual=$(echo $object |
yq -r '.mountPath' | tee /dev/stderr)
[ "${actual}" = "/consul/aclconfig" ]
yq -r '.spec.template.spec.containers[] | select(.name == "consul") | .volumeMounts[] | select(.name == "aclconfig") | .mountPath' | tee /dev/stderr)
[ "${mount_path}" = "/consul/aclconfig" ]
}

@test "client/DaemonSet: command includes aclconfig dir when global.acls.manageSystemACLs=true" {
Expand Down Expand Up @@ -1234,37 +1227,34 @@ local actual=$(echo $object |

@test "client/DaemonSet: Adds consul login volume when ACLs are enabled" {
cd `chart_dir`
local object=$(helm template \
local volume=$(helm template \
-s templates/client-daemonset.yaml \
--set 'global.acls.manageSystemACLs=true' \
. | yq '.spec.template.spec.volumes[2]' | tee /dev/stderr)
local actual=$(echo $object |
. | yq '.spec.template.spec.volumes[] | select(.name == "consul-data")' | tee /dev/stderr)

local volume_name=$(echo $volume |
yq -r '.name' | tee /dev/stderr)
[ "${actual}" = "consul-data" ]
[ "${volume_name}" = "consul-data" ]

local actual=$(echo $object |
local volume_emptydir_medium=$(echo $volume |
yq -r '.emptyDir.medium' | tee /dev/stderr)
[ "${actual}" = "Memory" ]
[ "${volume_emptydir_medium}" = "Memory" ]
}

@test "client/DaemonSet: Adds consul login volumeMount to client container when ACLs are enabled" {
cd `chart_dir`
local object=$(helm template \
local volume_mount=$(helm template \
-s templates/client-daemonset.yaml \
--set 'global.acls.manageSystemACLs=true' \
. | yq '.spec.template.spec.containers[0].volumeMounts[2]' | tee /dev/stderr)
. | yq '.spec.template.spec.containers[] | select(.name == "consul") | .volumeMounts[] | select(.name == "consul-data")' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.name' | tee /dev/stderr)
[ "${actual}" = "consul-data" ]

local actual=$(echo $object |
local volume_mount_path=$(echo $volume_mount |
yq -r '.mountPath' | tee /dev/stderr)
[ "${actual}" = "/consul/login" ]
[ "${volume_mount_path}" = "/consul/login" ]

local actual=$(echo $object |
local volume_mount_ro=$(echo $volume_mount |
yq -r '.readOnly' | tee /dev/stderr)
[ "${actual}" = "true" ]
[ "${volume_mount_ro}" = "true" ]
}

@test "client/DaemonSet: Adds consul login volumeMount to acl-init init container when ACLs are enabled" {
Expand Down

0 comments on commit 55046b8

Please sign in to comment.