Skip to content

Commit

Permalink
Update test runner script
Browse files Browse the repository at this point in the history
- Modified test-runner script to take certain flags
- Test runner now validates input
- Fixed an issue with the `gitleaks.toml`
  • Loading branch information
BradleyBoutcher committed Sep 16, 2020
1 parent 610a3ad commit 9517144
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitleaks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ title = "ansible-conjur-collection gitleaks config"
files = ['''^\.?gitleaks.toml$''',
'''(.*?)(jpg|gif|doc|pdf|bin)$''',
'''(go.mod|go.sum)$''',
'''(*/tests/* ''',]
'''(.*/tests/.*)$ ''',]
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ pipeline {
agent { label 'executor-v2-large' }

steps {
sh './ci/test.sh conjur'
sh './ci/test.sh -d conjur'
junit 'tests/conjur/junit/*'
}
}

stage("Test Ansible-Conjur-Host-Identity") {
steps {
sh './ci/test.sh conjur-host-identity'
sh './ci/test.sh -d conjur-host-identity'
junit 'tests/conjur-host-identity/junit/*'
}
}
Expand Down
69 changes: 66 additions & 3 deletions ci/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
#!/bin/bash -ex
#!/bin/bash -x

cd "${PWD}/tests/${1}"
# Test runner for Ansible Conjur Collection

# Directories containing a `test.sh` file
test_directories=("conjur" "conjur-host-identity")

# Target directory that can be manually set by passing a value to the `-d` flag
target=""

# Print usage instructions
function help {
echo "Test runner for Ansible Conjur Collection"

echo "-a Run all test files in default test directories"
echo "-d <arg> Run test file in given directory. Valid options are: ${test_directories[*]} all"
echo "-h View help and available commands"
exit 1
}

# Run a `test.sh` file in a given subdirectory of the top-level `tests` directory
function run_test {
pushd "${PWD}/tests/${1}"
echo "Running tests for ${1}..."
./test.sh
popd
}

# Handles input to dictate wether all tests should be ran, or just one set
function handle_input {
if [[ ! -z ${target} ]]; then
for test_dir in "${test_directories[@]}"; do
if [[ ${target} == "${test_dir}" ]]; then
run_test ${target}
exit 0
fi
done
echo "Error: unrecognized test directory given: ${target}"
echo ""
help
else
echo "Running all tests..."
for test_dir in "${test_directories[@]}"; do
run_test "${test_dir}"
done
exit 0
fi
}

# Exit if no input given
if [[ $# -eq 0 ]] ; then
echo "Error: No test directory or flag given"
echo ""
help
fi

while getopts ahd: option; do
case "$option" in
a) handle_input
;;
d) target=${OPTARG}
handle_input
;;
h) help
;;
esac
done

./test.sh

0 comments on commit 9517144

Please sign in to comment.