From 4e8f787cd5074d1cfe2d850a20e000a3a193cf24 Mon Sep 17 00:00:00 2001 From: JonJagger Date: Sun, 3 Mar 2024 05:08:02 +0000 Subject: [PATCH] Split junit test output into separate dir --- .github/workflows/main.yml | 8 ++++---- .github/workflows/main_staging.yml | 8 ++++---- sh/test_in_containers.sh | 18 +++++++++--------- test/id58_test_base.rb | 2 +- test/lib/coverage.rb | 2 +- test/lib/run.sh | 7 ++++--- test/lib/simplecov-json.rb | 2 +- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 590a068d..dbe8e25b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: diff --git a/.github/workflows/main_staging.yml b/.github/workflows/main_staging.yml index f44adaca..bb532703 100644 --- a/.github/workflows/main_staging.yml +++ b/.github/workflows/main_staging.yml @@ -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: diff --git a/sh/test_in_containers.sh b/sh/test_in_containers.sh index f47a7373..2f5e4b81 100755 --- a/sh/test_in_containers.sh +++ b/sh/test_in_containers.sh @@ -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}" \ @@ -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" @@ -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}" @@ -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}" diff --git a/test/id58_test_base.rb b/test/id58_test_base.rb index 1b0f31ed..12e443ac 100644 --- a/test/id58_test_base.rb +++ b/test/id58_test_base.rb @@ -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 diff --git a/test/lib/coverage.rb b/test/lib/coverage.rb index 32401f8b..70cefcef 100644 --- a/test/lib/coverage.rb +++ b/test/lib/coverage.rb @@ -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'] diff --git a/test/lib/run.sh b/test/lib/run.sh index 6178883b..c90eead7 100755 --- a/test/lib/run.sh +++ b/test/lib/run.sh @@ -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 @@ -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 diff --git a/test/lib/simplecov-json.rb b/test/lib/simplecov-json.rb index 9944c54d..c0204591 100644 --- a/test/lib/simplecov-json.rb +++ b/test/lib/simplecov-json.rb @@ -38,7 +38,7 @@ def output_filepath end def output_filename - 'coverage.json' + 'summary.json' end def output_message(result)