@@ -23,6 +23,7 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
23
23
24
24
kube::golang::setup_env
25
25
kube::golang::setup_gomaxprocs
26
+ kube::util::require-jq
26
27
27
28
# start the cache mutation detector by default so that cache mutators will be found
28
29
KUBE_CACHE_MUTATION_DETECTOR=" ${KUBE_CACHE_MUTATION_DETECTOR:- true} "
@@ -32,28 +33,26 @@ export KUBE_CACHE_MUTATION_DETECTOR
32
33
KUBE_PANIC_WATCH_DECODE_ERROR=" ${KUBE_PANIC_WATCH_DECODE_ERROR:- true} "
33
34
export KUBE_PANIC_WATCH_DECODE_ERROR
34
35
35
- kube::test::find_dirs () {
36
+ kube::test::find_go_packages () {
36
37
(
37
38
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(/.*)?$'
57
56
)
58
57
}
59
58
@@ -147,9 +146,6 @@ goflags=()
147
146
148
147
# Filter out arguments that start with "-" and move them to goflags.
149
148
testcases=()
150
- # if the user passed no target in, we can skip slow normalization.
151
- normalize=" true"
152
-
153
149
for arg; do
154
150
if [[ " ${arg} " == -* ]]; then
155
151
goflags+=(" ${arg} " )
@@ -158,11 +154,10 @@ for arg; do
158
154
fi
159
155
done
160
156
if [[ ${# testcases[@]} -eq 0 ]]; then
161
- normalize=" false"
162
- kube::util::read-array testcases < <( kube::test::find_dirs)
163
- fi
164
-
165
- if [[ " ${normalize} " == " true" ]]; then
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.
166
161
# This can be slow!
167
162
kube::log::status " Normalizing Go targets"
168
163
kube::util::read-array testcases < <( kube::golang::normalize_go_targets " ${testcases[@]} " )
0 commit comments