Skip to content

Commit 1b2ed5a

Browse files
authored
Merge pull request #20873 from ivanvc/remove-golang-test-short-environment-variable
Replace GOLANG_TEST_SHORT with testing.Short()
2 parents 8a4955b + 3e57a17 commit 1b2ed5a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

client/pkg/testutil/testutil.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package testutil
1717

1818
import (
19+
"flag"
20+
"log"
1921
"net/url"
2022
"os"
2123
"runtime"
@@ -100,10 +102,13 @@ func SkipTestIfShortMode(t TB, reason string) {
100102
// ExitInShortMode closes the current process (with 0) if the short test mode detected.
101103
//
102104
// To be used in Test-main, where test context (testing.TB) is not available.
103-
//
104-
// Requires custom env-variable (GOLANG_TEST_SHORT) apart of `go test --short flag`.
105105
func ExitInShortMode(reason string) {
106-
if os.Getenv("GOLANG_TEST_SHORT") == "true" {
106+
// Calling testing.Short() requires flags to be parsed before.
107+
if !flag.Parsed() {
108+
flag.Parse()
109+
}
110+
if testing.Short() {
111+
log.Println(reason)
107112
os.Exit(0)
108113
}
109114
}

scripts/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function run_unit_tests {
130130
local pkgs="${1:-./...}"
131131
shift 1
132132
# shellcheck disable=SC2068 #For context see - https://github.com/etcd-io/etcd/pull/16433#issuecomment-1684312755
133-
GOLANG_TEST_SHORT=true go_test "${pkgs}" "parallel" : -short -timeout="${TIMEOUT:-3m}" ${COMMON_TEST_FLAGS[@]:-} ${RUN_ARG[@]:-} "$@"
133+
go_test "${pkgs}" "parallel" : -short -timeout="${TIMEOUT:-3m}" ${COMMON_TEST_FLAGS[@]:-} ${RUN_ARG[@]:-} "$@"
134134
}
135135

136136
function unit_pass {
@@ -309,7 +309,7 @@ function cov_pass {
309309

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

0 commit comments

Comments
 (0)