Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions client/pkg/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package testutil

import (
"flag"
"log"
"net/url"
"os"
"runtime"
Expand Down Expand Up @@ -100,10 +102,13 @@ func SkipTestIfShortMode(t TB, reason string) {
// ExitInShortMode closes the current process (with 0) if the short test mode detected.
//
// To be used in Test-main, where test context (testing.TB) is not available.
//
// Requires custom env-variable (GOLANG_TEST_SHORT) apart of `go test --short flag`.
func ExitInShortMode(reason string) {
if os.Getenv("GOLANG_TEST_SHORT") == "true" {
// Calling testing.Short() requires flags to be parsed before.
if !flag.Parsed() {
flag.Parse()
}
if testing.Short() {
log.Println(reason)
os.Exit(0)
}
}
4 changes: 2 additions & 2 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ 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
GOLANG_TEST_SHORT=true go_test "${pkgs}" "parallel" : -short -timeout="${TIMEOUT:-3m}" ${COMMON_TEST_FLAGS[@]:-} ${RUN_ARG[@]:-} "$@"
go_test "${pkgs}" "parallel" : -short -timeout="${TIMEOUT:-3m}" ${COMMON_TEST_FLAGS[@]:-} ${RUN_ARG[@]:-} "$@"
}

function unit_pass {
Expand Down Expand Up @@ -309,7 +309,7 @@ function cov_pass {

log_callout "[$(date)] Collecting coverage from unit tests ..."
for m in $(module_dirs); do
GOLANG_TEST_SHORT=true run_for_module "${m}" go_test "./..." "parallel" "pkg_to_coverprofileflag unit_${m}" -short -timeout=30m \
run_for_module "${m}" go_test "./..." "parallel" "pkg_to_coverprofileflag unit_${m}" -short -timeout=30m \
"${gocov_build_flags[@]}" "$@" || failed="$failed unit"
done

Expand Down