diff --git a/src/runtime/go-test.sh b/src/runtime/go-test.sh index 2f6f1865e6..a47fa32653 100755 --- a/src/runtime/go-test.sh +++ b/src/runtime/go-test.sh @@ -12,7 +12,6 @@ typeset -A long_options long_options=( [help]="Show usage" - [list]="List available packages" [package:]="Specify test package to run" ) @@ -25,23 +24,12 @@ timeout_value=${KATA_GO_TEST_TIMEOUT:-30s} # -race flag is not supported on s390x [ "$(go env GOARCH)" != "s390x" ] && race="-race" -# Notes: -# -# - The vendor filtering is required for versions of go older than 1.9. -# - The test package filtering is required since those packages need special setup. -all_test_packages=$(go list ./... 2>/dev/null |\ - grep -v "/vendor/" |\ - grep -v "github.com/kata-containers/agent/protocols/grpc" |\ - grep -v "github.com/kata-containers/tests/functional" |\ - grep -v "github.com/kata-containers/tests/integration/docker" \ - || true) - # The "master" coverage file that contains the coverage results for # all packages run under all scenarios. test_coverage_file="coverage.txt" -# Temporary coverage file created for a single package. The results in this -# file will be added to the master coverage file. +# Temporary coverage file created for a "go test" run. The results in +# this file will be added to the master coverage file. tmp_coverage_file="${test_coverage_file}.tmp" warn() @@ -90,11 +78,6 @@ Commands: EOF } -list_packages() -{ - echo "$all_test_packages" -} - # Run a command as either root or the current user (which might still be root). # # If the first argument is "root", run using sudo, else run as the current @@ -126,15 +109,9 @@ test_go_package() run_as_user "$user" go test "$go_test_flags" -covermode=atomic -coverprofile=$tmp_coverage_file "$pkg" - # Check for the temporary coverage file since if will - # not be generated unless a package actually contains - # tests. - if [ -f "${tmp_coverage_file}" ]; then - # Save these package test results into the - # master coverage file. - run_as_user "$user" tail -n +2 "$tmp_coverage_file" >> "$test_coverage_file" - rm -f "$tmp_coverage_file" - fi + # Merge test results into the master coverage file. + run_as_user "$user" tail -n +2 "$tmp_coverage_file" >> "$test_coverage_file" + rm -f "$tmp_coverage_file" } # Run all tests and generate a test coverage file. @@ -161,19 +138,15 @@ test_coverage() fi echo "INFO: Currently running as user '$(id -un)'" - for pkg in $test_packages; do - for user in $users; do - test_go_package "$pkg" "$user" - done + for user in $users; do + test_go_package "$package" "$user" done } # Run the tests locally test_local() { - for pkg in $test_packages; do - eval go test "$go_test_flags" "$pkg" - done + eval go test "$go_test_flags" "$package" } main() @@ -187,7 +160,7 @@ main() --longoptions="$long_option_names" \ -- "$@") - local package + package="./..." eval set -- "$args" [ $? -ne 0 ] && { usage >&2; exit 1; } @@ -196,7 +169,6 @@ main() do case "$1" in -h|--help) usage; exit 0 ;; - --list) list_packages; exit 0 ;; --package) package="$2"; shift 2;; --) shift; break ;; esac @@ -204,12 +176,6 @@ main() shift done - if [ -n "$package" ]; then - test_packages="$package" - else - test_packages="$all_test_packages" - fi - # Consume getopt cruft [ "$1" = "--" ] && shift @@ -220,8 +186,6 @@ main() run_coverage=yes fi - [ -z "$test_packages" ] && echo "INFO: no golang code to test" && exit 0 - local go_ldflags [ "$(go env GOARCH)" = s390x ] && go_ldflags="-extldflags -Wl,--s390-pgste"