-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Migrate unit tests to use Go workspace #20872
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,16 +125,13 @@ function build_pass { | |
|
|
||
| ################# REGULAR TESTS ################################################ | ||
|
|
||
| # run_unit_tests [pkgs] runs unit tests for a current module and givesn set of [pkgs] | ||
| function run_unit_tests { | ||
| local pkgs="${1:-./...}" | ||
| shift 1 | ||
| # shellcheck disable=SC2068 #For context see - https://github.com/etcd-io/etcd/pull/16433#issuecomment-1684312755 | ||
| go_test "${pkgs}" "parallel" : -short -timeout="${TIMEOUT:-3m}" ${COMMON_TEST_FLAGS[@]:-} ${RUN_ARG[@]:-} "$@" | ||
| } | ||
|
|
||
| function unit_pass { | ||
| run_for_modules run_unit_tests "$@" | ||
| run_for_all_workspace_modules \ | ||
|
Member
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 see there is also a function
Member
Author
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. Once we finish migrating all the Makefile targets, we can clean up the old functions. Right now, as I'm doing a staged migration, I can't do a cleanup yet. |
||
| run_go_tests -short \ | ||
| -timeout="${TIMEOUT:-3m}" \ | ||
| "${COMMON_TEST_FLAGS[@]}" \ | ||
| "${RUN_ARG[@]}" \ | ||
| "$@" | ||
| } | ||
|
|
||
| function integration_extra { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,6 +206,17 @@ function run_for_modules { | |
| fi | ||
| } | ||
|
|
||
| function get_junit_filename_prefix { | ||
| local junit_report_dir="$1" | ||
| if [[ -z "${junit_report_dir}" ]]; then | ||
| echo "" | ||
| return | ||
| fi | ||
|
|
||
| mkdir -p "${junit_report_dir}" | ||
| mktemp --dry-run "${junit_report_dir}/junit_XXXXXXXXXX" | ||
| } | ||
|
|
||
| junitFilenamePrefix() { | ||
| if [[ -z "${JUNIT_REPORT_DIR:-}" ]]; then | ||
| echo "" | ||
|
|
@@ -335,6 +346,96 @@ function go_test { | |
| fi | ||
| } | ||
|
|
||
| # run_go_tests_expanding_packages [arguments to pass to go test] | ||
| # Expands the packages in the list of arguments, i.e. ./... into a list of | ||
| # packages for that given module. Then, it calls run_go_tests with the expanded | ||
| # packages. | ||
| function run_go_tests_expanding_packages { | ||
| local packages=() | ||
| local args=() | ||
| for arg in "$@"; do | ||
| if [[ "${arg}" =~ ./ ]]; then | ||
| packages+=("${arg}") | ||
| else | ||
| args+=("${arg}") | ||
| fi | ||
| done | ||
|
|
||
| # Expanding patterns (like ./...) into list of packages | ||
| local unpacked_packages=() | ||
| while IFS='' read -r line; do unpacked_packages+=("$line"); done < <( | ||
| go list "${packages[@]}" | ||
| ) | ||
|
|
||
| run_go_tests "${unpacked_packages[@]}" "${args[@]}" | ||
| } | ||
|
Comment on lines
+349
to
+371
Member
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. This function isn't used at all. Why add it?
Member
Author
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. It's added for compatibility with the old |
||
|
|
||
| # run_go_test [arguments to pass to go test] | ||
| # The following environment variables affect how the tests run: | ||
| # - KEEP_GOING_TESTS: If set to true it will keep executing tests even after | ||
| # a failure. It collects all failures and reports them at | ||
| # the end, if there are failures the return code is 2. | ||
| # Defaults to false. | ||
| # - JUNIT_REPORT_DIR/ARTIFACTS: Enables collecting JUnit XML reports. | ||
| # - VERBOSE: Sets a verbose output. | ||
| # | ||
| # Example: | ||
| # KEEP_GOING_TESTS=true run_go_tests "./..." --short | ||
| # | ||
| # The function returns != 0 code in case of test failure. | ||
| function run_go_tests { | ||
| local go_test_flags=() | ||
|
|
||
| local packages=() | ||
| local args=() | ||
| for arg in "$@"; do | ||
| if [[ "${arg}" =~ ^\./ || "${arg}" =~ ^go\.etcd\.io/etcd ]]; then | ||
| packages+=("${arg}") | ||
| else | ||
| args+=("${arg}") | ||
| fi | ||
| done | ||
|
|
||
| local keep_going=${KEEP_GOING_TESTS:-false} | ||
|
|
||
| # If JUNIT_REPORT_DIR is unset, and ARTIFACTS is set, then have them match. | ||
| local junit_report_dir=${JUNIT_REPORT_DIR:-${ARTIFACTS:-}} | ||
|
|
||
| local go_test_grep_pattern=".*" | ||
| if [[ -n "${junit_report_dir}" ]]; then | ||
| # Show only summary lines by matching lines like "status package/test" | ||
| go_test_grep_pattern="^[^[:space:]]\+[[:space:]]\+[^[:space:]]\+/[^[[:space:]]\+" | ||
| fi | ||
|
|
||
| if [[ -n "${junit_report_dir}" || "${VERBOSE:-}" == "1" ]]; then | ||
| go_test_flags+=("-v" "-json") | ||
| fi | ||
|
|
||
| local failures=() | ||
| # execution of tests against packages: | ||
| for pkg in "${packages[@]}"; do | ||
| local cmd=(go test "${go_test_flags[@]}" "${pkg}" "${args[@]}") | ||
|
|
||
| local junit_filename_prefix | ||
| junit_filename_prefix=$(get_junit_filename_prefix "${junit_report_dir}") | ||
|
|
||
| if ! run env ETCD_VERIFY="${ETCD_VERIFY}" "${cmd[@]}" | tee ${junit_filename_prefix:+"${junit_filename_prefix}.stdout"} | grep --binary-files=text "${go_test_grep_pattern}" ; then | ||
| if [ "${keep_going}" = "true" ]; then | ||
| failures+=("${pkg}") | ||
| else | ||
| produce_junit_xmlreport "${junit_filename_prefix}" | ||
| return 2 | ||
| fi | ||
| fi | ||
| produce_junit_xmlreport "${junit_filename_prefix}" | ||
| done | ||
|
|
||
| if [ -n "${failures[*]}" ]; then | ||
| log_error -e "FAIL: Tests for following packages failed:\\n ${failures[*]}" | ||
| return 2 | ||
| fi | ||
| } | ||
|
|
||
| #### Other #### | ||
|
|
||
| # tool_exists [tool] [instruction] | ||
|
|
||
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.
Eventually you will remove the function
go_testseparately?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.
Yes, similar comment to #20872 (comment)