Writing bats tests for scripts used in the charts project contribute
The following are notes and conventions used for creating bats tests for the GitLab chart.
Naming and structure
Bats test files should be placed in the same directory as the shell script they are testing, with the same file name using .bats
extension instead of .sh
.
./scripts/ci/pin_image_digests.sh # Script to be tested
./scripts/ci/pin_image_digests.bats # Bats tests
This convention makes it easy to find bats test files alongside the scripts they are testing.
Filtering bats tests
To aid in development it is possible to filter which tests are executed by
passing the -f
flag to regex match by test case names.
The following example will run only tests with “rendering” in their name.
bats scripts/ci/pin_image_digests.bats -f 'rendering'
Tests can also be filtered by tag, see bats documentation for examples.
Viewing output of run commands
When writing or debugging tests, running bats with the --verbose-run
flag will print $output
to the screen.
This is often helpful when debugging regex matches, and is used when running bats in CI.
Docs
Edit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Feature availability and product trials
View pricing to see all GitLab tiers and features, or to upgrade.
Try GitLab for free with access to all features for 30 days.
Get help
If you didn't find what you were looking for, search the docs.
If you want help with something specific and could use community support, post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab subscription).
Request support