Skip to content

Test style change#60

Open
audunmg wants to merge 3 commits into
mainfrom
test-style-change
Open

Test style change#60
audunmg wants to merge 3 commits into
mainfrom
test-style-change

Conversation

@audunmg
Copy link
Copy Markdown
Collaborator

@audunmg audunmg commented Dec 12, 2025

Test ergonomics aren't great, so let's improve it.

@audunmg
Copy link
Copy Markdown
Collaborator Author

audunmg commented Dec 12, 2025

Proposition 1: basically use bats syntax better.

use run to capture output in $output and check return status with $status when needed.

Everything printed in the test will be output when the test fails, so feel free to produce nice error messages.

Every line need to succeed for the test to succeed, so adding multiple commands to test things in a single test is OK as long as it makes sense.

@audunmg
Copy link
Copy Markdown
Collaborator Author

audunmg commented Dec 12, 2025

The second commit is not finished.

It's just a suggestion to have a bash function to create a shorter "helm template test", since that's most of the tests.

(it is what breaks tests right now in this PR)

}

helm_template_compare {
local valuefile="${BATS_TMPDIR}/values-${BATS_TEST_NUMBER}"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

smart!

@gquintard
Copy link
Copy Markdown
Collaborator

@briiians ^ this should simplify your tests

Comment thread varnish-enterprise/test/unit/_helpers.bash Outdated
briiians added a commit to briiians/helm-varnish that referenced this pull request Dec 16, 2025
Co-authored-by: briiians <125086365+briiians@users.noreply.github.com>
briiians added a commit to briiians/helm-varnish that referenced this pull request Dec 23, 2025
fixed conflicts

changed verbage in a comment

made tests for the repoType feature using the new test method from Audun in pr varnish#60
@audunmg
Copy link
Copy Markdown
Collaborator Author

audunmg commented Jan 30, 2026

I wanted to talk about this, but timezones and our schedules make it hard, so I'll make my case here:

  1. I sort-of like how the tests are written now. In the spirit of simplicity, this is something you can copypaste down to your command line, and run to see how it works, and I think that makes writing new tests easier.
    Sure, there's a lot of boilerplate, but it's pretty much identical.

  2. If we are going to change it and make it simpler and shorter, it should still be verbose enough to show what's going on.
    The point of the helm_template_compare was to show that you can make it short, but it was just an example. If we go down that route, I want to use getopt (or something) for that function so instead of

helm_template_compare 'argument' 'argument 2 ' 'argument 3' etc

I want to write

helm_template_compare --templatefile 'templates/something.tpl' --jq-pattern '.spec.template.spec[0].name' --result ''varnish-enterprise"

That way the meaning of the arguments are clear from reading the line, and I want it to be easy to run in the terminal to make writing tests easier. (for example by sourcing the _helpers.bash)

I believe the power and usefulness of using bats for testing is so that the tests are super easy to understand and write, and I don't want to lose that.

All of this is open for discussion, suggestions are more than welcome from anyone, and my mind is not set on any specific format, but I want it to be easy and maintainable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants