Skip to content

Commit

Permalink
CI: report compliance of unit-tests to Kosli (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Dec 2, 2023
1 parent d86de66 commit 7196220
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 26 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/sub_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ jobs:

- name: Run tests, save results to evidence.json file, report to Kosli flow
run: |
./sh/run_tests_with_coverage.sh
source ./sh/run_tests_with_coverage.sh
if run_tests_with_coverage; then KOSLI_COMPLIANT=true; else KOSLI_COMPLIANT=false; fi
kosli report evidence artifact generic cyberdojo/${{ env.KOSLI_FLOW }}:${{ inputs.IMAGE_TAG }} \
--artifact-type=docker \
--compliant=${KOSLI_COMPLIANT} \
--description="server & client branch-coverage reports" \
--name=branch-coverage \
--user-data=./test/reports/evidence.json
Expand Down
2 changes: 1 addition & 1 deletion sh/build_tagged_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ source "${SH_DIR}/augmented_docker_compose.sh"
# - - - - - - - - - - - - - - - - - - - - - -
build_tagged_images()
{
if [ "${1:-}" == server ]; then
if [ "${1:-}" = server ]; then
local -r target=differ_server
fi
echo
Expand Down
6 changes: 3 additions & 3 deletions sh/containers_up_healthy_and_clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ exit_non_zero_unless_started_cleanly()
#DOCKER_LOG=$(strip_known_warning "${DOCKER_LOG}" "${SHADOW_WARNING}")

echo "Checking if ${SERVICE_NAME} started cleanly."
local -r top5=$(echo "${DOCKER_LOG}" | head -5)
if [ "${top5}" == "$(clean_top_5)" ]; then
local -r log_top5=$(echo "${DOCKER_LOG}" | head -5)
if [ "${log_top5}" = "$(clean_top_5)" ]; then
echo "${SERVICE_NAME} started cleanly."
else
echo "${SERVICE_NAME} did not start cleanly."
Expand All @@ -83,7 +83,7 @@ exit_non_zero_unless_started_cleanly()
# - - - - - - - - - - - - - - - - - - -
clean_top_5()
{
# 1st 6 lines on Puma
# 1st 5 lines on Puma
local -r L1="Puma starting in single mode..."
local -r L2='* Puma version: 6.4.0 (ruby 3.2.2-p53) ("The Eagle of Durango")'
local -r L3="* Min threads: 0"
Expand Down
2 changes: 1 addition & 1 deletion sh/exit_zero_if_build_only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ exit_zero_if_build_only()
# - - - - - - - - - - - - - - - - - - - - - - - - - -
build_only_arg()
{
[ "${1:-}" == '--build-only' ] || [ "${1:-}" == '-bo' ]
[ "${1:-}" = '--build-only' ] || [ "${1:-}" = '-bo' ]
}
2 changes: 1 addition & 1 deletion sh/exit_zero_if_demo_only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exit_zero_if_demo_only()
# - - - - - - - - - - - - - - - - - - - - - - - - - -
demo_only_arg()
{
[ "${1:-}" == '--demo-only' ] || [ "${1:-}" == '-do' ]
[ "${1:-}" = '--demo-only' ] || [ "${1:-}" = '-do' ]
}

# - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
2 changes: 1 addition & 1 deletion sh/exit_zero_if_show_help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ EOF
# - - - - - - - - - - - - - - - - - - - - - - - - - -
show_help_arg()
{
[ "${1:-}" == '--help' ] || [ "${1:-}" == '-h' ]
[ "${1:-}" = '--help' ] || [ "${1:-}" = '-h' ]
}
20 changes: 12 additions & 8 deletions sh/run_tests_with_coverage.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -Eeu

export ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
export ROOT_DIR="$(git rev-parse --show-toplevel)"
export SH_DIR="${ROOT_DIR}/sh"

source "${SH_DIR}/containers_down.sh"
Expand All @@ -10,13 +10,17 @@ source "${SH_DIR}/copy_in_saver_test_data.sh"
source "${SH_DIR}/lib.sh"
source "${SH_DIR}/on_ci_upgrade_docker_compose.sh"
source "${SH_DIR}/test_in_containers.sh"

source "${SH_DIR}/echo_versioner_env_vars.sh"
export $(echo_versioner_env_vars)

on_ci_upgrade_docker_compose
server_up_healthy_and_clean
client_up_healthy_and_clean "$@"
copy_in_saver_test_data
test_in_containers "$@"
write_test_evidence_json
run_tests_with_coverage()
{
exit_code=0
on_ci_upgrade_docker_compose
server_up_healthy_and_clean
client_up_healthy_and_clean "$@"
copy_in_saver_test_data
test_in_containers "$@" || exit_code=$?
write_test_evidence_json
return ${exit_code}
}
21 changes: 11 additions & 10 deletions sh/test_in_containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - -
test_in_containers()
{
if [ "${1:-}" == 'client' ]; then
local exit_code=0
if [ "${1:-}" = 'client' ]; then
shift
run_client_tests "${@:-}"
elif [ "${1:-}" == 'server' ]; then
run_client_tests "${@:-}" || exit_code=$?
elif [ "${1:-}" = 'server' ]; then
shift
run_server_tests "${@:-}"
run_server_tests "${@:-}" || exit_code=$?
else
run_server_tests "${@:-}"
run_client_tests "${@:-}"
run_server_tests "${@:-}" || exit_code=$?
run_client_tests "${@:-}" || exit_code=$?
fi
echo All passed
return ${exit_code}
}

# - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand All @@ -21,7 +22,7 @@ run_client_tests()
run_tests \
"${CYBER_DOJO_DIFFER_CLIENT_USER}" \
"${CYBER_DOJO_DIFFER_CLIENT_CONTAINER_NAME}" \
client "${@:-}";
client "${@:-}"
}

# - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand All @@ -30,7 +31,7 @@ run_server_tests()
run_tests \
"${CYBER_DOJO_DIFFER_SERVER_USER}" \
"${CYBER_DOJO_DIFFER_SERVER_CONTAINER_NAME}" \
server "${@:-}";
server "${@:-}"
}

# - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -66,7 +67,7 @@ run_tests()
# Extract test-run results and coverage data from the container.
# You can't [docker cp] from a tmpfs, so tar-piping coverage out

if [ "${TYPE}" == server ]; then
if [ "${TYPE}" = server ]; then
local -r HOST_TEST_DIR="${ROOT_DIR}/test"
else
local -r HOST_TEST_DIR="${ROOT_DIR}/client/test"
Expand Down

0 comments on commit 7196220

Please sign in to comment.