Skip to content

Conversation

Maleware
Copy link
Member

Description

adds tests as a follow up to #530

Definition of Done Checklist

  • Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant
  • Please make sure all these things are done and tick the boxes
# Author
- [ ] Changes are OpenShift compatible
- [ ] CRD changes approved
- [ ] CRD documentation for all fields, following the [style guide](https://docs.stackable.tech/home/nightly/contributor/docs/style-guide).
- [ ] Helm chart can be installed and deployed operator works
- [ ] Integration tests passed (for non trivial changes)
- [ ] Changes need to be "offline" compatible
# Reviewer
- [ ] Code contains useful comments
- [ ] Code contains useful logging statements
- [ ] (Integration-)Test cases added
- [ ] Documentation added or updated. Follows the [style guide](https://docs.stackable.tech/home/nightly/contributor/docs/style-guide).
- [ ] Changelog updated
- [ ] Cargo.toml only contains references to git tags (not specific commits or branches)
# Acceptance
- [ ] Feature Tracker has been updated
- [ ] Proper release label has been added
- [ ] [Roadmap](https://github.com/orgs/stackabletech/projects/25/views/1) has been updated

@Maleware Maleware marked this pull request as ready for review August 26, 2024 18:02
@Maleware Maleware self-assigned this Aug 26, 2024
@sbernauer sbernauer requested a review from razvan August 27, 2024 08:03
@sbernauer sbernauer changed the title Adding tests for file_header and footer test: Adding tests for file_header and footer Aug 27, 2024
@sbernauer sbernauer changed the title test: Adding tests for file_header and footer test: Add tests for file_header and footer Aug 27, 2024
Copy link
Member

@NickLarsenNZ NickLarsenNZ left a 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
Copy link
Member

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.

Copy link
Member

@NickLarsenNZ NickLarsenNZ Aug 27, 2024

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.
Suggested change
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

Copy link
Member

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.

Copy link
Member

@NickLarsenNZ NickLarsenNZ Aug 27, 2024

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)

Copy link
Member

@NickLarsenNZ NickLarsenNZ left a 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).

Copy link
Member

@NickLarsenNZ NickLarsenNZ Aug 27, 2024

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"

Copy link
Member Author

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

Copy link
Member

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).

Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Granted: ca1e726

Copy link
Member

@sbernauer sbernauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

NickLarsenNZ

This comment was marked as outdated.

@Maleware Maleware added this pull request to the merge queue Aug 29, 2024
Merged via the queue into main with commit eaafa94 Aug 29, 2024
31 checks passed
@Maleware Maleware deleted the fix/file-header-footer-tests branch August 29, 2024 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants