Skip to content

Commit

Permalink
Move coverage reporting to separate script
Browse files Browse the repository at this point in the history
  • Loading branch information
gl-johnson committed Dec 27, 2022
1 parent 9a3b482 commit 1e59e36
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Nothing should go in this section, please add to the latest unreleased version
(and update the corresponding date), or add a new version.

## [1.7.16] - 2022-12-27

## [1.7.15] - 2022-09-22

### Security
Expand Down
9 changes: 7 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,14 @@ pipeline {
stage('Unit tests') {
steps {
sh './bin/test_unit'
sh 'cp ./test/unit-test-output/c.out ./c.out'
}
post {
always {
sh './bin/coverage'
sh 'cp ./test/unit-test-output/c.out ./c.out'

junit 'test/unit-test-output/junit.xml'
junit 'test/unit-test-output/junit.xml'
}
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions bin/coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -eo pipefail

current_dir=$("$(dirname "$0")"/abspath)
toplevel_dir=$current_dir/..
junit_output_dir=test/unit-test-output

function main() {
format_output
}

function format_output() {
# Format output
docker run --rm \
--volume "$toplevel_dir"/:/secretless \
--workdir "/secretless/$junit_output_dir" \
secretless-unit-test-runner:latest \
sh -exc "
rm -f junit.xml
# Format test output XML
cat junit.output | go-junit-report > junit.xml
# Format coverage output XML
gocov convert c.out | gocov-xml > coverage.xml"
}

main
19 changes: 0 additions & 19 deletions bin/test_unit
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function main() {
retrieve_cyberark_ca_cert
build_ut_docker_image
run_unit_tests
format_output
}

function build_ut_docker_image() {
Expand All @@ -24,7 +23,6 @@ function build_ut_docker_image() {

function run_unit_tests() {
echo "Running unit tests..."
set +e
mkdir -p "$junit_output_dir"
rm -f "$junit_output_dir/*"

Expand All @@ -46,23 +44,6 @@ function run_unit_tests() {
./pkg/... \
| tee -a "./$junit_output_dir/junit.output"
echo "Unit test exit status: $?"
set -e
}

function format_output() {
# Format output
docker run --rm \
--volume "$toplevel_dir"/:/secretless \
--workdir "/secretless/$junit_output_dir" \
secretless-unit-test-runner:latest \
sh -exc "
rm -f junit.xml
# Format test output XML
cat junit.output | go-junit-report > junit.xml
# Format coverage output XML
gocov convert c.out | gocov-xml > coverage.xml"
}

main

0 comments on commit 1e59e36

Please sign in to comment.