Skip to content

Commit

Permalink
Split junit test output into separate dir
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Mar 3, 2024
1 parent b31f3f4 commit 4e8f787
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,18 @@ jobs:
--results-dir=./test/server/reports/junit
kosli attest generic "${IMAGE_NAME}" \
--attachments=./test/server/reports \
--attachments=./test/server/reports/coverage \
--name=runner.unit-test-branch-coverage \
--user-data=./test/server/reports/coverage.json
--user-data=./test/server/reports/coverage/summary.json
kosli attest junit "${IMAGE_NAME}" \
--name=runner.integration-test \
--results-dir=./test/client/reports/junit
kosli attest generic "${IMAGE_NAME}" \
--attachments=./test/client/reports \
--attachments=./test/client/reports/coverage \
--name=runner.integration-test-branch-coverage \
--user-data=./test/client/reports/coverage.json
--user-data=./test/client/reports/coverage/summary.json
snyk-container-scan:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/main_staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,18 @@ jobs:
--results-dir=./test/server/reports/junit
kosli attest generic "${IMAGE_NAME}" \
--attachments=./test/server/reports \
--attachments=./test/server/reports/coverage \
--name=runner.unit-test-branch-coverage \
--user-data=./test/server/reports/coverage.json
--user-data=./test/server/reports/coverage/summary.json
kosli attest junit "${IMAGE_NAME}" \
--name=runner.integration-test \
--results-dir=./test/client/reports/junit
kosli attest generic "${IMAGE_NAME}" \
--attachments=./test/client/reports \
--attachments=./test/client/reports/coverage \
--name=runner.integration-test-branch-coverage \
--user-data=./test/client/reports/coverage.json
--user-data=./test/client/reports/coverage/summary.json
snyk-container-scan:
Expand Down
18 changes: 9 additions & 9 deletions sh/test_in_containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ run_tests()
# So tar-piping out.

local -r HOST_TEST_DIR="$(repo_root)/test/${TYPE}" # where to extract to. untar will create reports/ dir
local -r HOST_REPORTS_DIR="${HOST_TEST_DIR}/reports" # where files will be
local -r HOST_REPORTS_DIR="${HOST_TEST_DIR}/reports" # where files will be

rm "${HOST_REPORTS_DIR}/${TEST_LOG}" 2> /dev/null || true
rm "${HOST_REPORTS_DIR}/index.html" 2> /dev/null || true
rm "${HOST_REPORTS_DIR}/coverage.json" 2> /dev/null || true
rm "${HOST_REPORTS_DIR}/${TEST_LOG}" 2> /dev/null || true
rm "${HOST_REPORTS_DIR}/coverage/index.html" 2> /dev/null || true
rm "${HOST_REPORTS_DIR}/coverage/summary.json" 2> /dev/null || true

docker exec \
"${CONTAINER_NAME}" \
Expand All @@ -90,8 +90,8 @@ run_tests()

# Check we generated expected files.
exit_non_zero_unless_file_exists "${HOST_REPORTS_DIR}/${TEST_LOG}"
exit_non_zero_unless_file_exists "${HOST_REPORTS_DIR}/index.html"
exit_non_zero_unless_file_exists "${HOST_REPORTS_DIR}/coverage.json"
exit_non_zero_unless_file_exists "${HOST_REPORTS_DIR}/coverage/index.html"
exit_non_zero_unless_file_exists "${HOST_REPORTS_DIR}/coverage/summary.json"

# Check metrics limits file exists
exit_non_zero_unless_file_exists "${HOST_TEST_DIR}/max_metrics.json"
Expand All @@ -107,11 +107,11 @@ run_tests()
--env CODE_DIR="${CODE_DIR}" \
--env TEST_DIR="${TEST_DIR}" \
--volume ${HOST_REPORTS_DIR}/${TEST_LOG}:${CONTAINER_TMP_DIR}/${TEST_LOG}:ro \
--volume ${HOST_REPORTS_DIR}/coverage.json:${CONTAINER_TMP_DIR}/coverage.json:ro \
--volume ${HOST_REPORTS_DIR}/coverage/summary.json:${CONTAINER_TMP_DIR}/summary.json:ro \
--volume ${HOST_TEST_DIR}/max_metrics.json:${CONTAINER_TMP_DIR}/max_metrics.json:ro \
cyberdojo/check-test-metrics:latest \
"${CONTAINER_TMP_DIR}/${TEST_LOG}" \
"${CONTAINER_TMP_DIR}/coverage.json" \
"${CONTAINER_TMP_DIR}/summary.json" \
"${CONTAINER_TMP_DIR}/max_metrics.json" \
| tee -a "${HOST_REPORTS_DIR}/${TEST_LOG}"

Expand All @@ -122,7 +122,7 @@ run_tests()
# Tell caller where the coverage files are...

echo "${TYPE} test coverage at "
echo "$(abs_filename "${HOST_REPORTS_DIR}/index.html")"
echo "$(abs_filename "${HOST_REPORTS_DIR}/coverage/index.html")"
echo "${TYPE} test status == ${STATUS}"
if [ "${STATUS}" != 0 ]; then
echo Docker logs "${CONTAINER_NAME}"
Expand Down
2 changes: 1 addition & 1 deletion test/id58_test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'minitest/ci'
require_relative 'require_code'

Minitest::Ci.report_dir = "#{ENV['COVERAGE_ROOT']}/junit"
Minitest::Ci.report_dir = ENV['REPORTS_ROOT'] + '/junit'

class Id58TestBase < Minitest::Test

Expand Down
2 changes: 1 addition & 1 deletion test/lib/coverage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def runner_nocov_token
SimpleCov.start do
enable_coverage :branch
filters.clear
coverage_dir(ENV['COVERAGE_ROOT'])
coverage_dir(ENV['REPORTS_ROOT'] + '/coverage')
nocov_token(runner_nocov_token)
# add_group('debug') { |src| puts src.filename; false }
code_dir = ENV['CODE_DIR']
Expand Down
7 changes: 4 additions & 3 deletions test/lib/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -Eeu

readonly MY_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export COVERAGE_ROOT="${1}" # eg /tmp/reports
export REPORTS_ROOT="${1}" # eg /tmp/reports
readonly TEST_LOG="${2}" # eg test.run.log
readonly TYPE="${3}" # eg client|server
shift; shift; shift
Expand All @@ -16,8 +16,9 @@ require '${MY_DIR}/coverage.rb'
}"

export RUBYOPT='-W2'
mkdir -p ${COVERAGE_ROOT}
mkdir -p ${REPORTS_ROOT}/coverage
mkdir -p ${REPORTS_ROOT}/junit

set +e
ruby -e "${SCRIPT}" -- ${TEST_ARGS[@]} 2>&1 | tee ${COVERAGE_ROOT}/${TEST_LOG}
ruby -e "${SCRIPT}" -- ${TEST_ARGS[@]} 2>&1 | tee ${REPORTS_ROOT}/${TEST_LOG}
set -e
2 changes: 1 addition & 1 deletion test/lib/simplecov-json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def output_filepath
end

def output_filename
'coverage.json'
'summary.json'
end

def output_message(result)
Expand Down

0 comments on commit 4e8f787

Please sign in to comment.