Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

CI: Specify tmpdir for running golang unit tests #870

Merged
merged 2 commits into from
Oct 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .ci/go-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ timeout_value=${KATA_GO_TEST_TIMEOUT:-30s}
# enabling the flag depending on the arch.
[ "$(go env GOARCH)" = "amd64" ] && race="-race"

# KATA_GO_TEST_FLAGS can be set to change the flags passed to "go test".
go_test_flags=${KATA_GO_TEST_FLAGS:-"-v $race -timeout $timeout_value"}

# Notes:
#
# - The vendor filtering is required for versions of go older than 1.9.
Expand Down Expand Up @@ -249,13 +246,21 @@ main()

[ -z "$test_packages" ] && echo "INFO: no golang code to test" && exit 0

# directory to use for temporary files
golang_tmp=$(mktemp -d)

# KATA_GO_TEST_FLAGS can be set to change the flags passed to "go test".
go_test_flags=${KATA_GO_TEST_FLAGS:-"-v $race -timeout $timeout_value -outputdir \"${golang_tmp}\""}

if [ "$1" = "html-coverage" ]; then
test_html_coverage
elif [ "$run_coverage" = yes ]; then
test_coverage
else
test_local
fi

[ -d "${golang_tmp}" ] && [ "${golang_tmp}" != "/" ] && rm -rf "${golang_tmp}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as the script has a -e set, would this be safer as a shell TRAP to catch the case where the tests fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did consider that but thought it would be better to leave the tmpfiles in the case of test failures as they might help us diagnose what went wrong.

}

main "$@"