diff --git a/hack/make-rules/test.sh b/hack/make-rules/test.sh index f7f0d812f76..02baf70b494 100755 --- a/hack/make-rules/test.sh +++ b/hack/make-rules/test.sh @@ -211,6 +211,41 @@ junitFilenamePrefix() { echo "${KUBE_JUNIT_REPORT_DIR}/junit_${KUBE_TEST_API_HASH}_$(kube::util::sortable_date)" } +verifyAndSuggestPackagePath() { + local specified_package_path="$1" + local alternative_package_path="$2" + local original_package_path="$3" + local suggestion_package_path="$4" + + if ! [ -d "$specified_package_path" ]; then + # Because k8s sets a localized $GOPATH for testing, seeing the actual + # directory can be confusing. Instead, just show $GOPATH if it exists in the + # $specified_package_path. + local printable_package_path=$(echo "$specified_package_path" | sed "s|$GOPATH|\$GOPATH|") + kube::log::error "specified test path '$printable_package_path' does not exist" + + if [ -d "$alternative_package_path" ]; then + kube::log::info "try changing \"$original_package_path\" to \"$suggestion_package_path\"" + fi + exit 1 + fi +} + +verifyPathsToPackagesUnderTest() { + local packages_under_test=($@) + + for package_path in "${packages_under_test[@]}"; do + local local_package_path="$package_path" + local go_package_path="$GOPATH/src/$package_path" + + if [[ "${package_path:0:2}" == "./" ]] ; then + verifyAndSuggestPackagePath "$local_package_path" "$go_package_path" "$package_path" "${package_path:2}" + else + verifyAndSuggestPackagePath "$go_package_path" "$local_package_path" "$package_path" "./$package_path" + fi + done +} + produceJUnitXMLReport() { local -r junit_filename_prefix=$1 if [[ -z "${junit_filename_prefix}" ]]; then @@ -237,6 +272,8 @@ runTests() { local junit_filename_prefix junit_filename_prefix=$(junitFilenamePrefix) + verifyPathsToPackagesUnderTest "$@" + # If we're not collecting coverage, run all requested tests with one 'go test' # command, which is much faster. if [[ ! ${KUBE_COVER} =~ ^[yY]$ ]]; then