-
Notifications
You must be signed in to change notification settings - Fork 38.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating test-go.sh and test-integration.sh to be able to run the tests for multiple API versions #5687
Merged
Merged
Updating test-go.sh and test-integration.sh to be able to run the tests for multiple API versions #5687
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,8 @@ KUBE_COVERPROCS=${KUBE_COVERPROCS:-4} | |
KUBE_RACE=${KUBE_RACE:-} # use KUBE_RACE="-race" to enable race testing | ||
# Set to the goveralls binary path to report coverage results to Coveralls.io. | ||
KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-} | ||
# Comma separated list of API Versions that should be tested. | ||
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1beta1,v1beta3"} | ||
|
||
kube::test::usage() { | ||
kube::log::usage_from_stdin <<EOF | ||
|
@@ -109,87 +111,107 @@ if [[ ${#testcases[@]} -eq 0 ]]; then | |
fi | ||
set -- "${testcases[@]+${testcases[@]}}" | ||
|
||
# TODO: this should probably be refactored to avoid code duplication with the | ||
# coverage version. | ||
if [[ $iterations -gt 1 ]]; then | ||
if [[ $# -eq 0 ]]; then | ||
set -- $(kube::test::find_dirs) | ||
runTests() { | ||
# TODO: this should probably be refactored to avoid code duplication with the | ||
# coverage version. | ||
if [[ $iterations -gt 1 ]]; then | ||
if [[ $# -eq 0 ]]; then | ||
set -- $(kube::test::find_dirs) | ||
fi | ||
kube::log::status "Running ${iterations} times" | ||
fails=0 | ||
for arg; do | ||
trap 'exit 1' SIGINT | ||
pkg=${KUBE_GO_PACKAGE}/${arg} | ||
kube::log::status "${pkg}" | ||
# keep going, even if there are failures | ||
pass=0 | ||
count=0 | ||
for i in $(seq 1 ${iterations}); do | ||
if go test "${goflags[@]:+${goflags[@]}}" \ | ||
${KUBE_RACE} ${KUBE_TIMEOUT} "${pkg}"; then | ||
pass=$((pass + 1)) | ||
else | ||
fails=$((fails + 1)) | ||
fi | ||
count=$((count + 1)) | ||
done 2>&1 | ||
kube::log::status "${pass} / ${count} passed" | ||
done | ||
if [[ ${fails} -gt 0 ]]; then | ||
return 1 | ||
else | ||
return 0 | ||
fi | ||
fi | ||
kube::log::status "Running ${iterations} times" | ||
fails=0 | ||
for arg; do | ||
trap 'exit 1' SIGINT | ||
pkg=${KUBE_GO_PACKAGE}/${arg} | ||
kube::log::status "${pkg}" | ||
# keep going, even if there are failures | ||
pass=0 | ||
count=0 | ||
for i in $(seq 1 ${iterations}); do | ||
if go test "${goflags[@]:+${goflags[@]}}" \ | ||
${KUBE_RACE} ${KUBE_TIMEOUT} "${pkg}"; then | ||
pass=$((pass + 1)) | ||
else | ||
fails=$((fails + 1)) | ||
fi | ||
count=$((count + 1)) | ||
done 2>&1 | ||
kube::log::status "${pass} / ${count} passed" | ||
done | ||
if [[ ${fails} -gt 0 ]]; then | ||
exit 1 | ||
else | ||
exit 0 | ||
|
||
# If we're not collecting coverage, run all requested tests with one 'go test' | ||
# command, which is much faster. | ||
if [[ ! ${KUBE_COVER} =~ ^[yY]$ ]]; then | ||
kube::log::status "Running unit tests without code coverage" | ||
go test "${goflags[@]:+${goflags[@]}}" \ | ||
${KUBE_RACE} ${KUBE_TIMEOUT} "${@+${@/#/${KUBE_GO_PACKAGE}/}}" | ||
return 0 | ||
fi | ||
fi | ||
|
||
# If we're not collecting coverage, run all requested tests with one 'go test' | ||
# command, which is much faster. | ||
if [[ ! ${KUBE_COVER} =~ ^[yY]$ ]]; then | ||
kube::log::status "Running unit tests without code coverage" | ||
go test "${goflags[@]:+${goflags[@]}}" \ | ||
${KUBE_RACE} ${KUBE_TIMEOUT} "${@+${@/#/${KUBE_GO_PACKAGE}/}}" | ||
exit 0 | ||
fi | ||
# Create coverage report directories. | ||
cover_report_dir="/tmp/k8s_coverage/${KUBE_API_VERSION}/$(kube::util::sortable_date)" | ||
cover_profile="coverage.out" # Name for each individual coverage profile | ||
kube::log::status "Saving coverage output in '${cover_report_dir}'" | ||
mkdir -p "${@+${@/#/${cover_report_dir}/}}" | ||
|
||
# Run all specified tests, collecting coverage results. Go currently doesn't | ||
# support collecting coverage across multiple packages at once, so we must issue | ||
# separate 'go test' commands for each package and then combine at the end. | ||
# To speed things up considerably, we can at least use xargs -P to run multiple | ||
# 'go test' commands at once. | ||
printf "%s\n" "${@}" | xargs -I{} -n1 -P${KUBE_COVERPROCS} \ | ||
go test "${goflags[@]:+${goflags[@]}}" \ | ||
${KUBE_RACE} \ | ||
${KUBE_TIMEOUT} \ | ||
-cover -covermode="${KUBE_COVERMODE}" \ | ||
-coverprofile="${cover_report_dir}/{}/${cover_profile}" \ | ||
"${cover_params[@]+${cover_params[@]}}" \ | ||
"${KUBE_GO_PACKAGE}/{}" | ||
|
||
COMBINED_COVER_PROFILE="${cover_report_dir}/combined-coverage.out" | ||
{ | ||
# The combined coverage profile needs to start with a line indicating which | ||
# coverage mode was used (set, count, or atomic). This line is included in | ||
# each of the coverage profiles generated when running 'go test -cover', but | ||
# we strip these lines out when combining so that there's only one. | ||
echo "mode: ${KUBE_COVERMODE}" | ||
|
||
# Include all coverage reach data in the combined profile, but exclude the | ||
# 'mode' lines, as there should be only one. | ||
for x in `find "${cover_report_dir}" -name "${cover_profile}"`; do | ||
cat $x | grep -h -v "^mode:" || true | ||
done | ||
} >"${COMBINED_COVER_PROFILE}" | ||
|
||
coverage_html_file="${cover_report_dir}/combined-coverage.html" | ||
go tool cover -html="${COMBINED_COVER_PROFILE}" -o="${coverage_html_file}" | ||
kube::log::status "Combined coverage report: ${coverage_html_file}" | ||
} | ||
|
||
# Create coverage report directories. | ||
cover_report_dir="/tmp/k8s_coverage/$(kube::util::sortable_date)" | ||
cover_profile="coverage.out" # Name for each individual coverage profile | ||
kube::log::status "Saving coverage output in '${cover_report_dir}'" | ||
mkdir -p "${@+${@/#/${cover_report_dir}/}}" | ||
|
||
# Run all specified tests, collecting coverage results. Go currently doesn't | ||
# support collecting coverage across multiple packages at once, so we must issue | ||
# separate 'go test' commands for each package and then combine at the end. | ||
# To speed things up considerably, we can at least use xargs -P to run multiple | ||
# 'go test' commands at once. | ||
printf "%s\n" "${@}" | xargs -I{} -n1 -P${KUBE_COVERPROCS} \ | ||
go test "${goflags[@]:+${goflags[@]}}" \ | ||
${KUBE_RACE} \ | ||
${KUBE_TIMEOUT} \ | ||
-cover -covermode="${KUBE_COVERMODE}" \ | ||
-coverprofile="${cover_report_dir}/{}/${cover_profile}" \ | ||
"${cover_params[@]+${cover_params[@]}}" \ | ||
"${KUBE_GO_PACKAGE}/{}" | ||
|
||
combined_cover_profile="${cover_report_dir}/combined-coverage.out" | ||
{ | ||
# The combined coverage profile needs to start with a line indicating which | ||
# coverage mode was used (set, count, or atomic). This line is included in | ||
# each of the coverage profiles generated when running 'go test -cover', but | ||
# we strip these lines out when combining so that there's only one. | ||
echo "mode: ${KUBE_COVERMODE}" | ||
|
||
# Include all coverage reach data in the combined profile, but exclude the | ||
# 'mode' lines, as there should be only one. | ||
for x in `find "${cover_report_dir}" -name "${cover_profile}"`; do | ||
cat $x | grep -h -v "^mode:" || true | ||
done | ||
} >"${combined_cover_profile}" | ||
|
||
coverage_html_file="${cover_report_dir}/combined-coverage.html" | ||
go tool cover -html="${combined_cover_profile}" -o="${coverage_html_file}" | ||
kube::log::status "Combined coverage report: ${coverage_html_file}" | ||
|
||
if [[ -x "${KUBE_GOVERALLS_BIN}" ]]; then | ||
${KUBE_GOVERALLS_BIN} -coverprofile="${combined_cover_profile}" || true | ||
fi | ||
runTestsForVersion() { | ||
export KUBE_API_VERSION="$1" | ||
runTests "${@:2}" | ||
} | ||
|
||
reportCoverageToCoveralls() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if factoring this out into its own subroutine was really necessary. |
||
if [[ -x "${KUBE_GOVERALLS_BIN}" ]]; then | ||
${KUBE_GOVERALLS_BIN} -coverprofile="${COMBINED_COVER_PROFILE}" || true | ||
fi | ||
} | ||
|
||
# Convert the CSV to an array of API versions to test | ||
IFS=',' read -a apiVersions <<< ${KUBE_TEST_API_VERSIONS} | ||
for apiVersion in "${apiVersions[@]}"; do | ||
echo "Running tests for APIVersion: $apiVersion" | ||
runTestsForVersion $apiVersion "${@}" | ||
done | ||
|
||
# We might run the tests for multiple versions, but we want to report only | ||
# one of them to coveralls. Here we report coverage from the last run. | ||
reportCoverageToCoveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference, here is the relevant documentation: http://docs.travis-ci.com/user/build-configuration/#Explicit-inclusion-of-jobs-into-the-build-matrix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was there any particular pattern to using v1beta3 with go1.3 and v1beta1 with go1.4? or were they just semi-randomly chosen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular pattern.
Chosen randomly.