Skip to content

Commit ca1e726

Browse files
committed
Reworking tests for more readability and better codes style
1 parent 0d25aeb commit ca1e726

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

tests/templates/kuttl/smoke/31-assert.yaml

+27-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,30 @@ commands:
77
# Test envOverrides
88
#
99
- script: |
10-
kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "COMMON_HEADER_VAR = "group-value""
11-
kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "ROLE_FOOTER_VAR = "role-value""
12-
if [ -z "$(kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "ROLE_HEADER_VAR = \"role-value\"")" ]; then (echo "Success, ROLE_HEADER_VAR not present") else { echo "Failure, ROLE_HEADER_VAR present"; exit 1; } fi
13-
kubectl -n $NAMESPACE get sts superset-node-default -o yaml | yq -e '.spec.template.spec.containers[] | select (.name == "superset") | .env[] | select (.name == "COMMON_VAR" and .value == "group-value")'
14-
kubectl -n $NAMESPACE get sts superset-node-default -o yaml | yq -e '.spec.template.spec.containers[] | select (.name == "superset") | .env[] | select (.name == "GROUP_VAR" and .value == "group-value")'
15-
kubectl -n $NAMESPACE get sts superset-node-default -o yaml | yq -e '.spec.template.spec.containers[] | select (.name == "superset") | .env[] | select (.name == "ROLE_VAR" and .value == "role-value")'
10+
#!/usr/bin/env bash
11+
set -euo pipefail
12+
13+
# Config Test Data
14+
SUPERSET_CONFIG=$(
15+
kubectl -n "$NAMESPACE" get cm superset-node-default -o yaml \
16+
| yq -e '.data["superset_config.py"]'
17+
)
18+
19+
# Config Test Assertions
20+
echo "$SUPERSET_CONFIG" | grep 'COMMON_HEADER_VAR = "group-value"'
21+
echo "$SUPERSET_CONFIG" | grep 'ROLE_FOOTER_VAR = "role-value"'
22+
echo "$SUPERSET_CONFIG" | grep -v 'ROLE_HEADER_VAR = "role-value"'
23+
24+
# STS Spec Test Data
25+
SUPERSET_NODE_DEFAULT_STS=$(kubectl -n "$NAMESPACE" get sts superset-node-default -o yaml)
26+
YQ_FILTER='
27+
.spec.template.spec.containers[]
28+
| select(.name == "superset")
29+
| .env[]
30+
| select(.name == strenv(KEY) and .value == strenv(VALUE))
31+
'
32+
33+
# STS Spec Test Assertions
34+
echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="COMMON_VAR" VALUE="group-value" yq -e "$YQ_FILTER"
35+
echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="GROUP_VAR" VALUE="group-value" yq -e "$YQ_FILTER"
36+
echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="ROLE_VAR" VALUE="role-value" yq -e "$YQ_FILTER"

0 commit comments

Comments
 (0)