forked from rpelisse/hera
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added initial bats tests and github action set up #7
Open
gaol
wants to merge
1
commit into
jboss-set:master
Choose a base branch
from
gaol:bats_ci
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: "CI" | ||
on: [push, pull_request] | ||
jobs: | ||
build: | ||
name: Tests Hera Scripts | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup BATS | ||
uses: mig4/setup-bats@v1 | ||
with: | ||
bats-version: 1.4.1 | ||
- name: Check out code | ||
uses: actions/checkout@v1 | ||
- name: Run ShellCheck and Bats tests | ||
run: ./tests/tests-suite.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea/ | ||
*.iml | ||
*.tap | ||
shellcheck.html | ||
*.shellcheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
source-path=. | ||
|
||
disable=SC1091 | ||
disable=SC2155 | ||
|
||
disable=SC2027 | ||
disable=SC2086 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
readonly SCRIPT_NAME='run.sh' | ||
source ./tests/tests-common.sh | ||
|
||
setup() { | ||
export WORKSPACE=$(mktemp -d) | ||
# run tests within workspace | ||
cd "${WORKSPACE}" | ||
} | ||
|
||
teardown() { | ||
deleteIfExist "${WORKSPACE}" | ||
} | ||
|
||
@test "No JOB_NAME Defined" { | ||
run "${SCRIPT}" | ||
[ "${status}" -eq 3 ] | ||
[ "${lines[0]}" = 'No JOB_NAME provided.' ] | ||
} | ||
|
||
@test "No BUILD_ID Defined" { | ||
export JOB_NAME="test" | ||
run "${SCRIPT}" | ||
[ "${status}" -eq 4 ] | ||
[ "${lines[0]}" = 'No BUILD_ID provided.' ] | ||
} | ||
|
||
@test "Run in container" { | ||
export JOB_NAME="test" | ||
export BUILD_ID="1" | ||
run "${SCRIPT}" | ||
[ "${status}" -eq 0 ] | ||
echo "$output" | grep 'ssh -o StrictHostKeyChecking=no [email protected] podman run' | ||
echo "$output" | grep ' --userns=keep-id -u 1000:1000' | ||
echo "$output" | grep ' --name automaton-slave-test-1' | ||
echo "$output" | grep ' --add-host=olympus:10.88.0.1' | ||
echo "$output" | grep ' -v /home/jenkins//.ssh/:/var/jenkins_home/.ssh/:ro' | ||
echo "$output" | grep ' -v /home/jenkins//.gitconfig:/var/jenkins_home/.gitconfig:ro' | ||
echo "$output" | grep ' -v /home/jenkins//.netrc:/var/jenkins_home/.netrc:ro' | ||
echo "$output" | grep ' -d localhost/automatons' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
echo "ssh ${@}" >&2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
|
||
debugBatsTest() { | ||
|
||
for i in "${!lines[@]}" | ||
do | ||
echo "${lines[${i}]}" | ||
done | ||
echo "${status}" | ||
} | ||
|
||
deleteIfExist() { | ||
local file=${1} | ||
|
||
if [ -n "${file}" -a -e "${file}" ]; then | ||
rm -rf "${file}" | ||
fi | ||
} | ||
|
||
setupDummyCommandHomeDir() { | ||
|
||
readonly DUMMY_COMMAND_DIR=${DUMMY_COMMAND_DIR:-$(mktemp -d)} | ||
export DUMMY_COMMAND_DIR | ||
trap 'deleteIfExist ${DUMMY_COMMAND_DIR}' EXIT | ||
export PATH="${DUMMY_COMMAND_DIR}":"${PATH}" | ||
|
||
} | ||
|
||
setupDummySSH() { | ||
export DUMMY_SSH=${DUMMY_SSH:-"$(pwd)/tests/"} | ||
export PATH="${DUMMY_SSH}":"${PATH}" | ||
} | ||
|
||
createDummyCommand() { | ||
local command=${1} | ||
|
||
if [ -z "${command}" ]; then | ||
echo "No command provided - abort." | ||
exit 1 | ||
fi | ||
local path_to_command="${DUMMY_COMMAND_DIR}/${command}" | ||
|
||
echo "echo ${command} \${@}" > "${path_to_command}" | ||
chmod +x "${path_to_command}" | ||
trap 'deleteIfExist ${path_to_command}' EXIT | ||
} | ||
|
||
createDummyBackgroundCommand() { | ||
createDummyCommand ${@} | ||
|
||
local path_to_command="${DUMMY_COMMAND_DIR}/${1}" | ||
# simple sleep 20 waits until end of sleep before being killed | ||
echo 'for i in {1...20}; do sleep 1; done' >> "${path_to_command}" | ||
echo 'echo done' >> "${path_to_command}" | ||
|
||
} | ||
|
||
setupDummyCommandHomeDir | ||
setupDummySSH | ||
|
||
if [ -z "${SCRIPT_NAME}" ]; then | ||
echo "No script name provided." | ||
exit 1 | ||
fi | ||
|
||
|
||
readonly SCRIPT_HOME=${SCRIPT_HOME:-$(pwd)} | ||
export HERA_HOME=${SCRIPT_HOME} | ||
readonly SCRIPT="${SCRIPT_HOME}/${SCRIPT_NAME}" | ||
|
||
if [ ! -d "${SCRIPT_HOME}" ]; then | ||
echo "Invalid home for ${SCRIPT_NAME}: ${SCRIPT_HOME}." | ||
exit 2 | ||
fi | ||
|
||
if [ ! -e "${SCRIPT}" ]; then | ||
echo "Invalid path to script: ${SCRIPT}." | ||
exit 3 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
|
||
dir_name="$(dirname "$0")" | ||
work_dir="$(cd "${dir_name}/.." && pwd)" | ||
|
||
runTests() { | ||
for tests in "${work_dir}"/tests/*.bats | ||
do | ||
local tests_file | ||
tests_file=$(basename "${tests}") | ||
if ! bats -t "${tests}" > "${work_dir}/tests/${tests_file%.bats}.tap"; then | ||
echo "${tests_file}" | ||
else | ||
rm "${work_dir}/tests/${tests_file%.bats}.tap" | ||
fi | ||
done | ||
} | ||
|
||
echo -n 'Run Tests...' | ||
test_results=$(runTests) | ||
if [ -n "${test_results}" ]; then | ||
for test_file in ${test_results} | ||
do | ||
echo -e "\nTest failures found in ${work_dir}/tests/${test_file}" | ||
cat "${work_dir}/tests/${test_file%.bats}.tap" | ||
done | ||
exit 1 | ||
fi | ||
echo 'Done - PASSED' | ||
echo '' | ||
|
||
|
||
runShellCheck() { | ||
for script in "${work_dir}"/*.sh | ||
do | ||
if ! shellcheck "${script}" > "${script}.shellcheck"; then | ||
echo "${script}" | ||
else | ||
rm "${script}.shellcheck" | ||
fi | ||
done | ||
} | ||
|
||
echo -n 'Run Shellcheck on scripts...' | ||
shellcheck_result=$(runShellCheck) | ||
if [ -n "${shellcheck_result}" ]; then | ||
for script_file in ${shellcheck_result} | ||
do | ||
echo -e "\nShellCheck violations are found in ${script_file}" | ||
cat "${script_file}.shellcheck" | ||
done | ||
exit 1 | ||
fi | ||
echo 'Done - PASSED' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gaol There seems to be quite a lot of code duplication from Harmonia's testsuite... I wonder if it would no be cleaner to have Jenkins checkout Harmonia inside the Hera folder and reuse the stuff... WDTK? |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be OK, but @rpelisse could you confirm this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spyrkob @gaol I'm not sure about this change, I've never seen$* before... What is the reason for this change? What does $ * that differs from ${@} ? In any case, I think it should be ${*}.