Skip to content

Commit 63fc917

Browse files
authored
Merge pull request kubernetes#127480 from thockin/skip_test_target_normalization
Skip test target normalization
2 parents 9e157c5 + 8912df6 commit 63fc917

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

hack/make-rules/test.sh

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
2323

2424
kube::golang::setup_env
2525
kube::golang::setup_gomaxprocs
26+
kube::util::require-jq
2627

2728
# start the cache mutation detector by default so that cache mutators will be found
2829
KUBE_CACHE_MUTATION_DETECTOR="${KUBE_CACHE_MUTATION_DETECTOR:-true}"
@@ -32,28 +33,26 @@ export KUBE_CACHE_MUTATION_DETECTOR
3233
KUBE_PANIC_WATCH_DECODE_ERROR="${KUBE_PANIC_WATCH_DECODE_ERROR:-true}"
3334
export KUBE_PANIC_WATCH_DECODE_ERROR
3435

35-
kube::test::find_dirs() {
36+
kube::test::find_go_packages() {
3637
(
3738
cd "${KUBE_ROOT}"
38-
find -L . -not \( \
39-
\( \
40-
-path './_artifacts/*' \
41-
-o -path './_output/*' \
42-
-o -path './cmd/kubeadm/test/*' \
43-
-o -path './contrib/podex/*' \
44-
-o -path './release/*' \
45-
-o -path './target/*' \
46-
-o -path './test/e2e/e2e_test.go' \
47-
-o -path './test/e2e_node/*' \
48-
-o -path './test/e2e_kubeadm/*' \
49-
-o -path './test/integration/*' \
50-
-o -path './third_party/*' \
51-
-o -path './staging/*' \
52-
-o -path './vendor/*' \
53-
\) -prune \
54-
\) -name '*_test.go' -print0 | xargs -0n1 dirname | LC_ALL=C sort -u
55-
56-
find ./staging -name '*_test.go' -not -path '*/test/integration/*' -prune -print0 | xargs -0n1 dirname | LC_ALL=C sort -u
39+
40+
# Get a list of all the modules in this workspace.
41+
local -a workspace_module_patterns
42+
kube::util::read-array workspace_module_patterns < <(go list -m -json | jq -r '.Path + "/..."')
43+
44+
# Get a list of all packages which have test files, but filter out ones
45+
# that we don't want to run by default (i.e. are not unit-tests).
46+
go list -find \
47+
-f '{{if or (gt (len .TestGoFiles) 0) (gt (len .XTestGoFiles) 0)}}{{.ImportPath}}{{end}}' \
48+
"${workspace_module_patterns[@]}" \
49+
| grep -vE \
50+
-e '^k8s.io/kubernetes/third_party(/.*)?$' \
51+
-e '^k8s.io/kubernetes/cmd/kubeadm/test(/.*)?$' \
52+
-e '^k8s.io/kubernetes/test/e2e$' \
53+
-e '^k8s.io/kubernetes/test/e2e_node(/.*)?$' \
54+
-e '^k8s.io/kubernetes/test/e2e_kubeadm(/.*)?$' \
55+
-e '^k8s.io/.*/test/integration(/.*)?$'
5756
)
5857
}
5958

@@ -155,7 +154,13 @@ for arg; do
155154
fi
156155
done
157156
if [[ ${#testcases[@]} -eq 0 ]]; then
158-
kube::util::read-array testcases < <(kube::test::find_dirs)
157+
# If the user passed no targets in, we want ~everything.
158+
kube::util::read-array testcases < <(kube::test::find_go_packages)
159+
else
160+
# If the user passed targets, we should normalize them.
161+
# This can be slow!
162+
kube::log::status "Normalizing Go targets"
163+
kube::util::read-array testcases < <(kube::golang::normalize_go_targets "${testcases[@]}")
159164
fi
160165
set -- "${testcases[@]+${testcases[@]}}"
161166

@@ -190,11 +195,6 @@ runTests() {
190195

191196
installTools
192197

193-
# Try to normalize input names. This is slow!
194-
local -a targets
195-
kube::log::status "Normalizing Go targets"
196-
kube::util::read-array targets < <(kube::golang::normalize_go_targets "$@")
197-
198198
# Enable coverage data collection?
199199
local cover_msg
200200
local COMBINED_COVER_PROFILE
@@ -229,7 +229,7 @@ runTests() {
229229
go test -json \
230230
"${goflags[@]:+${goflags[@]}}" \
231231
"${KUBE_TIMEOUT}" \
232-
"${targets[@]}" \
232+
"$@" \
233233
"${testargs[@]:+${testargs[@]}}" \
234234
&& rc=$? || rc=$?
235235

0 commit comments

Comments
 (0)