Skip to content

Commit

Permalink
[pre-commit]Add shared kuttl pre-commit rules
Browse files Browse the repository at this point in the history
This pre-commit check ensures that no TestAsserts are defined in
our kuttl tests that are ignores by kuttl
  • Loading branch information
gibizer committed May 10, 2024
1 parent d7e6810 commit 067099e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- id: kuttl-single-test-assert
name: kuttl-single-test-assert
language: script
pass_filenames: false
entry: pre-commit-hooks/kuttl-single-test-assert.sh

14 changes: 14 additions & 0 deletions pre-commit-hooks/kuttl-single-test-assert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -euxo pipefail

# Ensure that there are no assert files with more than one TestAssert
# as the extra TestAsserts are silently ignored by kuttl
KUTTL_DIR=${1:-"./test/kuttl"}
! egrep -c --include='*.y*ml' -R -e 'kind: TestAssert' "$KUTTL_DIR" \
| grep -v ':0' | grep -v ':1'
ret=$?
if [ $ret -ne 0 ]; then
echo Kuttl only executes the last TestAssert in an assert file.
echo Combine the TestAsserts into a single one with a list of commands.
fi
exit $ret

0 comments on commit 067099e

Please sign in to comment.