Updating test-go.sh to be able to run tests twice - for v1beta1 and 3

This commit is contained in:
nikhiljindal 2015-03-19 17:21:08 -07:00
parent f584069573
commit 5e4ab8e045
3 changed files with 116 additions and 84 deletions

View File

@ -2,9 +2,12 @@ sudo: false
language: go language: go
go: matrix:
- 1.4 include:
- 1.3 - go: 1.4
env: KUBE_TEST_API_VERSIONS="v1beta1"
- go: 1.3
env: KUBE_TEST_API_VERSIONS="v1beta3"
install: install:
- if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi - if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
@ -18,10 +21,10 @@ install:
- GOPATH=$PWD/Godeps/_workspace:$GOPATH go install ./... - GOPATH=$PWD/Godeps/_workspace:$GOPATH go install ./...
script: script:
- KUBE_RACE="-race" KUBE_COVER="y" KUBE_GOVERALLS_BIN="$HOME/gopath/bin/goveralls" KUBE_TIMEOUT='-timeout 300s' KUBE_COVERPROCS=8 ./hack/test-go.sh -- -p=2 - KUBE_RACE="-race" KUBE_COVER="y" KUBE_GOVERALLS_BIN="$HOME/gopath/bin/goveralls" KUBE_TIMEOUT='-timeout 300s' KUBE_COVERPROCS=8 KUBE_TEST_API_VERSIONS=$KUBE_TEST_API_VERSIONS ./hack/test-go.sh -- -p=2
- PATH=$HOME/gopath/bin:./third_party/etcd:$PATH ./hack/test-cmd.sh - PATH=$HOME/gopath/bin:./third_party/etcd:$PATH ./hack/test-cmd.sh
- PATH=$HOME/gopath/bin:./third_party/etcd:$PATH ./hack/verify-gendocs.sh - PATH=$HOME/gopath/bin:./third_party/etcd:$PATH ./hack/verify-gendocs.sh
- PATH=$HOME/gopath/bin:./third_party/etcd:$PATH ./hack/test-integration.sh - PATH=$HOME/gopath/bin:./third_party/etcd:$PATH KUBE_TEST_API_VERSIONS=$KUBE_TEST_API_VERSIONS ./hack/test-integration.sh
notifications: notifications:
irc: "chat.freenode.net#google-containers" irc: "chat.freenode.net#google-containers"

View File

@ -50,6 +50,8 @@ KUBE_COVERPROCS=${KUBE_COVERPROCS:-4}
KUBE_RACE=${KUBE_RACE:-} # use KUBE_RACE="-race" to enable race testing 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. # Set to the goveralls binary path to report coverage results to Coveralls.io.
KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-} 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::test::usage() {
kube::log::usage_from_stdin <<EOF kube::log::usage_from_stdin <<EOF
@ -109,9 +111,10 @@ if [[ ${#testcases[@]} -eq 0 ]]; then
fi fi
set -- "${testcases[@]+${testcases[@]}}" set -- "${testcases[@]+${testcases[@]}}"
# TODO: this should probably be refactored to avoid code duplication with the runTests() {
# coverage version. # TODO: this should probably be refactored to avoid code duplication with the
if [[ $iterations -gt 1 ]]; then # coverage version.
if [[ $iterations -gt 1 ]]; then
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
set -- $(kube::test::find_dirs) set -- $(kube::test::find_dirs)
fi fi
@ -136,33 +139,33 @@ if [[ $iterations -gt 1 ]]; then
kube::log::status "${pass} / ${count} passed" kube::log::status "${pass} / ${count} passed"
done done
if [[ ${fails} -gt 0 ]]; then if [[ ${fails} -gt 0 ]]; then
exit 1 return 1
else else
exit 0 return 0
fi
fi fi
fi
# If we're not collecting coverage, run all requested tests with one 'go test' # If we're not collecting coverage, run all requested tests with one 'go test'
# command, which is much faster. # command, which is much faster.
if [[ ! ${KUBE_COVER} =~ ^[yY]$ ]]; then if [[ ! ${KUBE_COVER} =~ ^[yY]$ ]]; then
kube::log::status "Running unit tests without code coverage" kube::log::status "Running unit tests without code coverage"
go test "${goflags[@]:+${goflags[@]}}" \ go test "${goflags[@]:+${goflags[@]}}" \
${KUBE_RACE} ${KUBE_TIMEOUT} "${@+${@/#/${KUBE_GO_PACKAGE}/}}" ${KUBE_RACE} ${KUBE_TIMEOUT} "${@+${@/#/${KUBE_GO_PACKAGE}/}}"
exit 0 return 0
fi fi
# Create coverage report directories. # Create coverage report directories.
cover_report_dir="/tmp/k8s_coverage/$(kube::util::sortable_date)" cover_report_dir="/tmp/k8s_coverage/${KUBE_API_VERSION}/$(kube::util::sortable_date)"
cover_profile="coverage.out" # Name for each individual coverage profile cover_profile="coverage.out" # Name for each individual coverage profile
kube::log::status "Saving coverage output in '${cover_report_dir}'" kube::log::status "Saving coverage output in '${cover_report_dir}'"
mkdir -p "${@+${@/#/${cover_report_dir}/}}" mkdir -p "${@+${@/#/${cover_report_dir}/}}"
# Run all specified tests, collecting coverage results. Go currently doesn't # Run all specified tests, collecting coverage results. Go currently doesn't
# support collecting coverage across multiple packages at once, so we must issue # 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. # 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 # To speed things up considerably, we can at least use xargs -P to run multiple
# 'go test' commands at once. # 'go test' commands at once.
printf "%s\n" "${@}" | xargs -I{} -n1 -P${KUBE_COVERPROCS} \ printf "%s\n" "${@}" | xargs -I{} -n1 -P${KUBE_COVERPROCS} \
go test "${goflags[@]:+${goflags[@]}}" \ go test "${goflags[@]:+${goflags[@]}}" \
${KUBE_RACE} \ ${KUBE_RACE} \
${KUBE_TIMEOUT} \ ${KUBE_TIMEOUT} \
@ -171,8 +174,8 @@ printf "%s\n" "${@}" | xargs -I{} -n1 -P${KUBE_COVERPROCS} \
"${cover_params[@]+${cover_params[@]}}" \ "${cover_params[@]+${cover_params[@]}}" \
"${KUBE_GO_PACKAGE}/{}" "${KUBE_GO_PACKAGE}/{}"
combined_cover_profile="${cover_report_dir}/combined-coverage.out" COMBINED_COVER_PROFILE="${cover_report_dir}/combined-coverage.out"
{ {
# The combined coverage profile needs to start with a line indicating which # 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 # 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 # each of the coverage profiles generated when running 'go test -cover', but
@ -184,12 +187,31 @@ combined_cover_profile="${cover_report_dir}/combined-coverage.out"
for x in `find "${cover_report_dir}" -name "${cover_profile}"`; do for x in `find "${cover_report_dir}" -name "${cover_profile}"`; do
cat $x | grep -h -v "^mode:" || true cat $x | grep -h -v "^mode:" || true
done done
} >"${combined_cover_profile}" } >"${COMBINED_COVER_PROFILE}"
coverage_html_file="${cover_report_dir}/combined-coverage.html" coverage_html_file="${cover_report_dir}/combined-coverage.html"
go tool cover -html="${combined_cover_profile}" -o="${coverage_html_file}" go tool cover -html="${COMBINED_COVER_PROFILE}" -o="${coverage_html_file}"
kube::log::status "Combined coverage report: ${coverage_html_file}" kube::log::status "Combined coverage report: ${coverage_html_file}"
}
if [[ -x "${KUBE_GOVERALLS_BIN}" ]]; then runTestsForVersion() {
${KUBE_GOVERALLS_BIN} -coverprofile="${combined_cover_profile}" || true export KUBE_API_VERSION="$1"
fi runTests "${@:2}"
}
reportCoverageToCoveralls() {
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

View File

@ -24,6 +24,9 @@ set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh" source "${KUBE_ROOT}/hack/lib/init.sh"
# Comma separated list of API Versions that should be tested.
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1beta1,v1beta3"}
cleanup() { cleanup() {
kube::etcd::cleanup kube::etcd::cleanup
@ -36,6 +39,7 @@ runTests() {
kube::log::status "Running integration test cases" kube::log::status "Running integration test cases"
KUBE_GOFLAGS="-tags 'integration no-docker' " \ KUBE_GOFLAGS="-tags 'integration no-docker' " \
KUBE_RACE="-race" \ KUBE_RACE="-race" \
KUBE_TEST_API_VERSIONS="$1" \
"${KUBE_ROOT}/hack/test-go.sh" test/integration "${KUBE_ROOT}/hack/test-go.sh" test/integration
kube::log::status "Running integration test scenario" kube::log::status "Running integration test scenario"
@ -50,5 +54,8 @@ runTests() {
# Run cleanup to stop etcd on interrupt or other kill signal. # Run cleanup to stop etcd on interrupt or other kill signal.
trap cleanup EXIT trap cleanup EXIT
runTests "v1beta1" # Convert the CSV to an array of API versions to test
runTests "v1beta3" IFS=',' read -a apiVersions <<< ${KUBE_TEST_API_VERSIONS}
for apiVersion in "${apiVersions[@]}"; do
runTests $apiVersion
done