-
-
Notifications
You must be signed in to change notification settings - Fork 3
test: Add tests for file_header and footer #533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will paste a suggestion shortly
@@ -7,6 +7,9 @@ commands: | |||
# Test envOverrides | |||
# | |||
- script: | | |||
kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "COMMON_HEADER_VAR = "group-value"" | |||
kubectl -n $NAMESPACE get cm superset-node-default -o yaml | yq -e '.data."superset_config.py"' | grep "ROLE_FOOTER_VAR = "role-value"" | |||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be simplified. Will paste an example in a moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Convert to multi-line for readability.
- Remove long inline command from
if [ .. ]
. - Refer to
superset_config.py
inside[]
instead of dotting it. - Use single quotes so we don't need to escape double quotes.
- Removed the subshell
()
and braces{}
from the then/else blocks. - Redirect failure message to STDERR.
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 | |
RESULT=$( | |
kubectl -n $NAMESPACE get cm superset-node-default -o yaml \ | |
| yq -e '.data["superset_config.py"]' \ | |
| grep 'ROLE_HEADER_VAR = "role-value"' | |
) | |
if [ -z "$RESULT" ]; then | |
echo "Success, ROLE_HEADER_VAR not present" | |
else | |
2>& echo "Failure, ROLE_HEADER_VAR present" | |
exit 1 | |
fi | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think the whole if block could be simplified by using grep -v
so the test looks more like the others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will post a separate comment with what I suggest the whole script should look like.
See: #533 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added my suggestion to make the whole test script more readable (I couldn't add Github suggestions as there were unchanged lines that I can't select).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my suggestion:
- Use bash and with strict mode (so failures before the last command cause the script to fail).
- Reduce calls to kubectl for the same resources.
- Simplify the assertions.
- Use single quotes for strings which don't need variable expansion.
- Template the yq filter (unfortunately the go yq works so much differently to the python one which works basically the same as jq... so there are no
--arg
options).
# - script: |
#!/usr/bin/env bash
set -euo pipefail
# Config Test Data
SUPERSET_CONFIG=$(
kubectl -n "$NAMESPACE" get cm superset-node-default -o yaml \
| yq -e '.data["superset_config.py"]'
)
# Config Test Assertions
echo "$SUPERSET_CONFIG" | grep 'COMMON_HEADER_VAR = "group-value"'
echo "$SUPERSET_CONFIG" | grep 'ROLE_FOOTER_VAR = "role-value"'
echo "$SUPERSET_CONFIG" | grep -v 'ROLE_HEADER_VAR = "role-value"'
# STS Spec Test Data
SUPERSET_NODE_DEFAULT_STS=$(kubectl -n "$NAMESPACE" get sts superset-node-default -o yaml)
YQ_FILTER='
.spec.template.spec.containers[]
| select(.name == "superset")
| .env[]
| select(.name == strenv(KEY) and .value == strenv(VALUE))
'
# STS Spec Test Assertions
echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="COMMON_VAR" VALUE="group-value" yq -e "$YQ_FILTER"
echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="GROUP_VAR" VALUE="group-value" yq -e "$YQ_FILTER"
echo "$SUPERSET_NODE_DEFAULT_STS" | KEY="ROLE_VAR" VALUE="role-value" yq -e "$YQ_FILTER"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion, it makes sense to me. However, we implemented such stuff here e.g. https://github.com/stackabletech/airflow-operator/pull/490/files and from myself https://github.com/stackabletech/airflow-operator/pull/493/files
As I said I like your suggestion, but fear our tests differ to much from one another and nobody is going to understand it anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see how it has been done, but to me they are unreadable. I think we should go with the readable option (it lessens the burden on reviewers too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First off: I don't have a strong opinion, but I would tend to agree with @NickLarsenNZ. I see your concerns @Maleware and I have the same ones (mono-repo would be much easier here), but I personally think readability is more important in this case (especially as @NickLarsenNZ already did the work of rewriting the script)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Granted: ca1e726
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
adds tests as a follow up to #530
Definition of Done Checklist
Author
Reviewer
Acceptance