2018-04-16 12:31:44 -04:00
#!/usr/bin/env bash
2016-05-24 11:40:44 -04:00
# Copyright 2014 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
2019-03-28 03:29:34 -04:00
KUBE_ROOT = $( dirname " ${ BASH_SOURCE [0] } " ) /../..
2016-05-24 11:40:44 -04:00
source " ${ KUBE_ROOT } /hack/lib/init.sh "
2023-12-29 16:29:04 -05:00
kube::golang::setup_env
2024-09-19 14:00:58 -04:00
kube::util::require-jq
2016-05-24 11:40:44 -04:00
2016-06-21 10:26:38 -04:00
# start the cache mutation detector by default so that cache mutators will be found
KUBE_CACHE_MUTATION_DETECTOR = " ${ KUBE_CACHE_MUTATION_DETECTOR :- true } "
export KUBE_CACHE_MUTATION_DETECTOR
2017-05-19 16:18:25 -04:00
# panic the server on watch decode errors since they are considered coder mistakes
KUBE_PANIC_WATCH_DECODE_ERROR = " ${ KUBE_PANIC_WATCH_DECODE_ERROR :- true } "
export KUBE_PANIC_WATCH_DECODE_ERROR
2024-09-19 14:00:58 -04:00
kube::test::find_go_packages( ) {
2016-05-24 11:40:44 -04:00
(
2019-03-28 03:29:34 -04:00
cd " ${ KUBE_ROOT } "
2024-09-19 14:00:58 -04:00
# Get a list of all the modules in this workspace.
local -a workspace_module_patterns
kube::util::read-array workspace_module_patterns < <( go list -m -json | jq -r '.Path + "/..."' )
# Get a list of all packages which have test files, but filter out ones
# that we don't want to run by default (i.e. are not unit-tests).
go list -find \
-f '{{if or (gt (len .TestGoFiles) 0) (gt (len .XTestGoFiles) 0)}}{{.ImportPath}}{{end}}' \
" ${ workspace_module_patterns [@] } " \
| grep -vE \
-e '^k8s.io/kubernetes/third_party(/.*)?$' \
-e '^k8s.io/kubernetes/cmd/kubeadm/test(/.*)?$' \
-e '^k8s.io/kubernetes/test/e2e$' \
2025-07-14 12:35:52 -04:00
-e '^k8s.io/kubernetes/test/e2e_dra$' \
2024-09-19 14:00:58 -04:00
-e '^k8s.io/kubernetes/test/e2e_node(/.*)?$' \
-e '^k8s.io/kubernetes/test/e2e_kubeadm(/.*)?$' \
-e '^k8s.io/.*/test/integration(/.*)?$'
2016-05-24 11:40:44 -04:00
)
}
2025-08-18 08:33:57 -04:00
set -x
2021-06-10 02:33:24 -04:00
# TODO: This timeout should really be lower, this is a *long* time to test one
# package, however pkg/api/testing in particular will fail with a lower timeout
# currently. We should attempt to lower this over time.
2021-06-15 15:24:31 -04:00
KUBE_TIMEOUT = ${ KUBE_TIMEOUT :- -timeout=180s }
2016-05-24 11:40:44 -04:00
KUBE_COVER = ${ KUBE_COVER :- n } # set to 'y' to enable coverage collection
KUBE_COVERMODE = ${ KUBE_COVERMODE :- atomic }
2019-09-23 13:36:00 -04:00
# The directory to save test coverage reports to, if generating them. If unset,
# a semi-predictable temporary directory will be used.
KUBE_COVER_REPORT_DIR = " ${ KUBE_COVER_REPORT_DIR :- } "
2021-06-17 14:52:18 -04:00
# use KUBE_RACE="" to disable the race detector
# this is defaulted to "-race" in make test as well
# NOTE: DO NOT ADD A COLON HERE. KUBE_RACE="" is meaningful!
KUBE_RACE = ${ KUBE_RACE - "-race" }
2016-05-24 11:40:44 -04:00
# Set to the goveralls binary path to report coverage results to Coveralls.io.
KUBE_GOVERALLS_BIN = ${ KUBE_GOVERALLS_BIN :- }
# once we have multiple group supports
# Create a junit-style XML test report in this directory if set.
KUBE_JUNIT_REPORT_DIR = ${ KUBE_JUNIT_REPORT_DIR :- }
2018-12-19 18:17:13 -05:00
# If KUBE_JUNIT_REPORT_DIR is unset, and ARTIFACTS is set, then have them match.
if [ [ -z " ${ KUBE_JUNIT_REPORT_DIR :- } " && -n " ${ ARTIFACTS :- } " ] ] ; then
export KUBE_JUNIT_REPORT_DIR = " ${ ARTIFACTS } "
fi
2016-05-24 11:40:44 -04:00
# Set to 'y' to keep the verbose stdout from tests when KUBE_JUNIT_REPORT_DIR is
# set.
KUBE_KEEP_VERBOSE_TEST_OUTPUT = ${ KUBE_KEEP_VERBOSE_TEST_OUTPUT :- n }
2024-11-18 06:44:34 -05:00
# Set to 'false' to disable reduction of the JUnit file to only the top level tests.
KUBE_PRUNE_JUNIT_TESTS = ${ KUBE_PRUNE_JUNIT_TESTS :- true }
2016-05-24 11:40:44 -04:00
2025-08-18 08:33:57 -04:00
set +x
2016-05-24 11:40:44 -04:00
kube::test::usage( ) {
kube::log::usage_from_stdin <<EOF
usage: $0 [ OPTIONS] [ TARGETS]
OPTIONS:
-p <number> : number of parallel workers, must be >= 1
EOF
}
isnum( ) {
[ [ " $1 " = ~ ^[ 0-9] +$ ] ]
}
PARALLEL = " ${ PARALLEL :- 1 } "
while getopts "hp:i:" opt ; do
2019-01-18 13:17:16 -05:00
case ${ opt } in
2016-05-24 11:40:44 -04:00
h)
kube::test::usage
exit 0
; ;
p)
2019-01-21 17:11:58 -05:00
PARALLEL = " ${ OPTARG } "
2016-05-24 11:40:44 -04:00
if ! isnum " ${ PARALLEL } " || [ [ " ${ PARALLEL } " -le 0 ] ] ; then
kube::log::usage " ' $0 ': argument to -p must be numeric and greater than 0 "
kube::test::usage
exit 1
fi
; ;
i)
kube::log::usage " ' $0 ': use GOFLAGS='-count <num-iterations>' "
kube::test::usage
exit 1
; ;
2019-03-28 03:29:34 -04:00
:)
kube::log::usage " Option - ${ OPTARG } <value> "
2016-05-24 11:40:44 -04:00
kube::test::usage
exit 1
; ;
2019-03-28 03:29:34 -04:00
?)
2016-05-24 11:40:44 -04:00
kube::test::usage
exit 1
; ;
esac
done
shift $(( OPTIND - 1 ))
# Use eval to preserve embedded quoted strings.
test: filter "go test" output with gotestsum instead of grep
Filtering the output with grep leads to hard to read log output, e.g. from
pull-kubernetes-unit:
+++ [0613 15:32:48] Running tests without code coverage and with -race
{"Time":"2024-06-13T15:33:47.845457374Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Test":"TestCreateMasterAuditPolicy","Output":" /tmp/configure-helper-test47992121/kube-env: line 1: `}'\n"}
{"Time":"2024-06-13T15:33:49.053732803Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Output":"ok \tk8s.io/kubernetes/cluster/gce/cos\t2.906s\n"}
We can do better than that. When feeding the output of the "go test" command(s)
into gotestsum *while it runs*, we can use --format=standard-quiet (= normal go
test output) or --format=standard-verbose (= `go test -v`) when FULL_LOG is
requested to get nicer output.
This works when testing everything at once. This was said to be not possible
when doing coverage profiling. But recent Go no longer has that limitation, so
the xargs trick gets removed. All that we need to do for coverage profiling is
to add some additional parameters and the conversion to HTML.
2024-06-14 10:24:38 -04:00
#
# KUBE_TEST_ARGS contains arguments for `go test` (like -short)
# and may end with `-args <arguments for test binary>`, so it
# has to be passed to `go test` at the end of the invocation.
2019-03-28 03:29:34 -04:00
testargs = ( )
2016-05-24 11:40:44 -04:00
eval " testargs=( ${ KUBE_TEST_ARGS :- } ) "
test: filter "go test" output with gotestsum instead of grep
Filtering the output with grep leads to hard to read log output, e.g. from
pull-kubernetes-unit:
+++ [0613 15:32:48] Running tests without code coverage and with -race
{"Time":"2024-06-13T15:33:47.845457374Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Test":"TestCreateMasterAuditPolicy","Output":" /tmp/configure-helper-test47992121/kube-env: line 1: `}'\n"}
{"Time":"2024-06-13T15:33:49.053732803Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Output":"ok \tk8s.io/kubernetes/cluster/gce/cos\t2.906s\n"}
We can do better than that. When feeding the output of the "go test" command(s)
into gotestsum *while it runs*, we can use --format=standard-quiet (= normal go
test output) or --format=standard-verbose (= `go test -v`) when FULL_LOG is
requested to get nicer output.
This works when testing everything at once. This was said to be not possible
when doing coverage profiling. But recent Go no longer has that limitation, so
the xargs trick gets removed. All that we need to do for coverage profiling is
to add some additional parameters and the conversion to HTML.
2024-06-14 10:24:38 -04:00
# gotestsum --format value
2025-03-20 07:09:44 -04:00
# "standard-quiet" let's some stderr log messages through, "pkgname-and-test-fails" is similar and doesn't (https://github.com/kubernetes/kubernetes/issues/130934#issuecomment-2739957840).
gotestsum_format = pkgname-and-test-fails
2019-02-07 06:04:43 -05:00
if [ [ -n " ${ FULL_LOG :- } " ] ] ; then
test: filter "go test" output with gotestsum instead of grep
Filtering the output with grep leads to hard to read log output, e.g. from
pull-kubernetes-unit:
+++ [0613 15:32:48] Running tests without code coverage and with -race
{"Time":"2024-06-13T15:33:47.845457374Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Test":"TestCreateMasterAuditPolicy","Output":" /tmp/configure-helper-test47992121/kube-env: line 1: `}'\n"}
{"Time":"2024-06-13T15:33:49.053732803Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Output":"ok \tk8s.io/kubernetes/cluster/gce/cos\t2.906s\n"}
We can do better than that. When feeding the output of the "go test" command(s)
into gotestsum *while it runs*, we can use --format=standard-quiet (= normal go
test output) or --format=standard-verbose (= `go test -v`) when FULL_LOG is
requested to get nicer output.
This works when testing everything at once. This was said to be not possible
when doing coverage profiling. But recent Go no longer has that limitation, so
the xargs trick gets removed. All that we need to do for coverage profiling is
to add some additional parameters and the conversion to HTML.
2024-06-14 10:24:38 -04:00
gotestsum_format = standard-verbose
2019-02-07 06:04:43 -05:00
fi
test: filter "go test" output with gotestsum instead of grep
Filtering the output with grep leads to hard to read log output, e.g. from
pull-kubernetes-unit:
+++ [0613 15:32:48] Running tests without code coverage and with -race
{"Time":"2024-06-13T15:33:47.845457374Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Test":"TestCreateMasterAuditPolicy","Output":" /tmp/configure-helper-test47992121/kube-env: line 1: `}'\n"}
{"Time":"2024-06-13T15:33:49.053732803Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Output":"ok \tk8s.io/kubernetes/cluster/gce/cos\t2.906s\n"}
We can do better than that. When feeding the output of the "go test" command(s)
into gotestsum *while it runs*, we can use --format=standard-quiet (= normal go
test output) or --format=standard-verbose (= `go test -v`) when FULL_LOG is
requested to get nicer output.
This works when testing everything at once. This was said to be not possible
when doing coverage profiling. But recent Go no longer has that limitation, so
the xargs trick gets removed. All that we need to do for coverage profiling is
to add some additional parameters and the conversion to HTML.
2024-06-14 10:24:38 -04:00
goflags = ( )
2016-05-24 11:40:44 -04:00
# Filter out arguments that start with "-" and move them to goflags.
testcases = ( )
for arg; do
if [ [ " ${ arg } " = = -* ] ] ; then
goflags += ( " ${ arg } " )
else
testcases += ( " ${ arg } " )
fi
done
if [ [ ${# testcases [@] } -eq 0 ] ] ; then
2024-09-19 14:00:58 -04:00
# If the user passed no targets in, we want ~everything.
kube::util::read-array testcases < <( kube::test::find_go_packages)
else
# If the user passed targets, we should normalize them.
2024-09-24 15:02:54 -04:00
# This can be slow for large numbers of inputs.
2024-09-19 13:44:50 -04:00
kube::log::status "Normalizing Go targets"
kube::util::read-array testcases < <( kube::golang::normalize_go_targets " ${ testcases [@] } " )
fi
2016-05-24 11:40:44 -04:00
set -- " ${ testcases [@]+ ${ testcases [@] } } "
2019-03-28 03:29:34 -04:00
if [ [ -n " ${ KUBE_RACE } " ] ] ; then
goflags += ( " ${ KUBE_RACE } " )
fi
2016-05-24 11:40:44 -04:00
junitFilenamePrefix( ) {
if [ [ -z " ${ KUBE_JUNIT_REPORT_DIR } " ] ] ; then
echo ""
return
fi
mkdir -p " ${ KUBE_JUNIT_REPORT_DIR } "
2020-01-10 10:22:20 -05:00
echo " ${ KUBE_JUNIT_REPORT_DIR } /junit_ $( kube::util::sortable_date) "
2016-05-24 11:40:44 -04:00
}
test: filter "go test" output with gotestsum instead of grep
Filtering the output with grep leads to hard to read log output, e.g. from
pull-kubernetes-unit:
+++ [0613 15:32:48] Running tests without code coverage and with -race
{"Time":"2024-06-13T15:33:47.845457374Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Test":"TestCreateMasterAuditPolicy","Output":" /tmp/configure-helper-test47992121/kube-env: line 1: `}'\n"}
{"Time":"2024-06-13T15:33:49.053732803Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Output":"ok \tk8s.io/kubernetes/cluster/gce/cos\t2.906s\n"}
We can do better than that. When feeding the output of the "go test" command(s)
into gotestsum *while it runs*, we can use --format=standard-quiet (= normal go
test output) or --format=standard-verbose (= `go test -v`) when FULL_LOG is
requested to get nicer output.
This works when testing everything at once. This was said to be not possible
when doing coverage profiling. But recent Go no longer has that limitation, so
the xargs trick gets removed. All that we need to do for coverage profiling is
to add some additional parameters and the conversion to HTML.
2024-06-14 10:24:38 -04:00
installTools( ) {
2019-07-31 15:22:50 -04:00
if ! command -v gotestsum >/dev/null 2>& 1; then
2024-03-02 17:27:33 -05:00
kube::log::status "gotestsum not found; installing from ./hack/tools"
2025-02-14 12:08:30 -05:00
GOTOOLCHAIN = " $( kube::golang::hack_tools_gotoolchain) " go -C " ${ KUBE_ROOT } /hack/tools " install gotest.tools/gotestsum
2016-05-24 11:40:44 -04:00
fi
2019-07-31 15:22:50 -04:00
2022-03-29 12:05:03 -04:00
if ! command -v prune-junit-xml >/dev/null 2>& 1; then
2024-03-02 17:27:33 -05:00
kube::log::status "prune-junit-xml not found; installing from ./cmd"
go -C " ${ KUBE_ROOT } /cmd/prune-junit-xml " install .
2022-03-29 12:05:03 -04:00
fi
2016-05-24 11:40:44 -04:00
}
runTests( ) {
local junit_filename_prefix
junit_filename_prefix = $( junitFilenamePrefix)
test: filter "go test" output with gotestsum instead of grep
Filtering the output with grep leads to hard to read log output, e.g. from
pull-kubernetes-unit:
+++ [0613 15:32:48] Running tests without code coverage and with -race
{"Time":"2024-06-13T15:33:47.845457374Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Test":"TestCreateMasterAuditPolicy","Output":" /tmp/configure-helper-test47992121/kube-env: line 1: `}'\n"}
{"Time":"2024-06-13T15:33:49.053732803Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Output":"ok \tk8s.io/kubernetes/cluster/gce/cos\t2.906s\n"}
We can do better than that. When feeding the output of the "go test" command(s)
into gotestsum *while it runs*, we can use --format=standard-quiet (= normal go
test output) or --format=standard-verbose (= `go test -v`) when FULL_LOG is
requested to get nicer output.
This works when testing everything at once. This was said to be not possible
when doing coverage profiling. But recent Go no longer has that limitation, so
the xargs trick gets removed. All that we need to do for coverage profiling is
to add some additional parameters and the conversion to HTML.
2024-06-14 10:24:38 -04:00
installTools
# Enable coverage data collection?
local cover_msg
local COMBINED_COVER_PROFILE
if [ [ ${ KUBE_COVER } = ~ ^[ yY] $ ] ] ; then
cover_msg = "with code coverage"
if [ [ -z " ${ KUBE_COVER_REPORT_DIR } " ] ] ; then
cover_report_dir = " /tmp/k8s_coverage/ $( kube::util::sortable_date) "
else
cover_report_dir = " ${ KUBE_COVER_REPORT_DIR } "
fi
kube::log::status " Saving coverage output in ' ${ cover_report_dir } ' "
mkdir -p " ${ @+ ${ @/#/ ${ cover_report_dir } / } } "
COMBINED_COVER_PROFILE = " ${ cover_report_dir } /combined-coverage.out "
goflags += ( -cover -covermode= " ${ KUBE_COVERMODE } " -coverprofile= " ${ COMBINED_COVER_PROFILE } " )
else
cover_msg = "without code coverage"
fi
# Keep the raw JSON output in addition to the JUnit file?
local jsonfile = ""
if [ [ -n " ${ junit_filename_prefix } " ] ] && [ [ ${ KUBE_KEEP_VERBOSE_TEST_OUTPUT } = ~ ^[ yY] $ ] ] ; then
jsonfile = " ${ junit_filename_prefix } .stdout "
2016-05-24 11:40:44 -04:00
fi
test: filter "go test" output with gotestsum instead of grep
Filtering the output with grep leads to hard to read log output, e.g. from
pull-kubernetes-unit:
+++ [0613 15:32:48] Running tests without code coverage and with -race
{"Time":"2024-06-13T15:33:47.845457374Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Test":"TestCreateMasterAuditPolicy","Output":" /tmp/configure-helper-test47992121/kube-env: line 1: `}'\n"}
{"Time":"2024-06-13T15:33:49.053732803Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Output":"ok \tk8s.io/kubernetes/cluster/gce/cos\t2.906s\n"}
We can do better than that. When feeding the output of the "go test" command(s)
into gotestsum *while it runs*, we can use --format=standard-quiet (= normal go
test output) or --format=standard-verbose (= `go test -v`) when FULL_LOG is
requested to get nicer output.
This works when testing everything at once. This was said to be not possible
when doing coverage profiling. But recent Go no longer has that limitation, so
the xargs trick gets removed. All that we need to do for coverage profiling is
to add some additional parameters and the conversion to HTML.
2024-06-14 10:24:38 -04:00
kube::log::status " Running tests ${ cover_msg } ${ KUBE_RACE : + " and with ${ KUBE_RACE } " } "
2025-08-18 08:33:57 -04:00
kube::log::run gotestsum --format= " ${ gotestsum_format } " \
test: filter "go test" output with gotestsum instead of grep
Filtering the output with grep leads to hard to read log output, e.g. from
pull-kubernetes-unit:
+++ [0613 15:32:48] Running tests without code coverage and with -race
{"Time":"2024-06-13T15:33:47.845457374Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Test":"TestCreateMasterAuditPolicy","Output":" /tmp/configure-helper-test47992121/kube-env: line 1: `}'\n"}
{"Time":"2024-06-13T15:33:49.053732803Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Output":"ok \tk8s.io/kubernetes/cluster/gce/cos\t2.906s\n"}
We can do better than that. When feeding the output of the "go test" command(s)
into gotestsum *while it runs*, we can use --format=standard-quiet (= normal go
test output) or --format=standard-verbose (= `go test -v`) when FULL_LOG is
requested to get nicer output.
This works when testing everything at once. This was said to be not possible
when doing coverage profiling. But recent Go no longer has that limitation, so
the xargs trick gets removed. All that we need to do for coverage profiling is
to add some additional parameters and the conversion to HTML.
2024-06-14 10:24:38 -04:00
--jsonfile= " ${ jsonfile } " \
--junitfile= " ${ junit_filename_prefix : + " ${ junit_filename_prefix } .xml " } " \
--raw-command \
-- \
go test -json \
" ${ goflags [@] : + ${ goflags [@] } } " \
" ${ KUBE_TIMEOUT } " \
2024-09-19 13:44:50 -04:00
" $@ " \
test: filter "go test" output with gotestsum instead of grep
Filtering the output with grep leads to hard to read log output, e.g. from
pull-kubernetes-unit:
+++ [0613 15:32:48] Running tests without code coverage and with -race
{"Time":"2024-06-13T15:33:47.845457374Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Test":"TestCreateMasterAuditPolicy","Output":" /tmp/configure-helper-test47992121/kube-env: line 1: `}'\n"}
{"Time":"2024-06-13T15:33:49.053732803Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Output":"ok \tk8s.io/kubernetes/cluster/gce/cos\t2.906s\n"}
We can do better than that. When feeding the output of the "go test" command(s)
into gotestsum *while it runs*, we can use --format=standard-quiet (= normal go
test output) or --format=standard-verbose (= `go test -v`) when FULL_LOG is
requested to get nicer output.
This works when testing everything at once. This was said to be not possible
when doing coverage profiling. But recent Go no longer has that limitation, so
the xargs trick gets removed. All that we need to do for coverage profiling is
to add some additional parameters and the conversion to HTML.
2024-06-14 10:24:38 -04:00
" ${ testargs [@] : + ${ testargs [@] } } " \
&& rc = $? || rc = $?
if [ [ -n " ${ junit_filename_prefix } " ] ] ; then
2024-11-18 06:44:34 -05:00
prune-junit-xml -prune-tests= " ${ KUBE_PRUNE_JUNIT_TESTS } " " ${ junit_filename_prefix } .xml "
test: filter "go test" output with gotestsum instead of grep
Filtering the output with grep leads to hard to read log output, e.g. from
pull-kubernetes-unit:
+++ [0613 15:32:48] Running tests without code coverage and with -race
{"Time":"2024-06-13T15:33:47.845457374Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Test":"TestCreateMasterAuditPolicy","Output":" /tmp/configure-helper-test47992121/kube-env: line 1: `}'\n"}
{"Time":"2024-06-13T15:33:49.053732803Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Output":"ok \tk8s.io/kubernetes/cluster/gce/cos\t2.906s\n"}
We can do better than that. When feeding the output of the "go test" command(s)
into gotestsum *while it runs*, we can use --format=standard-quiet (= normal go
test output) or --format=standard-verbose (= `go test -v`) when FULL_LOG is
requested to get nicer output.
This works when testing everything at once. This was said to be not possible
when doing coverage profiling. But recent Go no longer has that limitation, so
the xargs trick gets removed. All that we need to do for coverage profiling is
to add some additional parameters and the conversion to HTML.
2024-06-14 10:24:38 -04:00
fi
2021-06-18 01:57:10 -04:00
test: filter "go test" output with gotestsum instead of grep
Filtering the output with grep leads to hard to read log output, e.g. from
pull-kubernetes-unit:
+++ [0613 15:32:48] Running tests without code coverage and with -race
{"Time":"2024-06-13T15:33:47.845457374Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Test":"TestCreateMasterAuditPolicy","Output":" /tmp/configure-helper-test47992121/kube-env: line 1: `}'\n"}
{"Time":"2024-06-13T15:33:49.053732803Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Output":"ok \tk8s.io/kubernetes/cluster/gce/cos\t2.906s\n"}
We can do better than that. When feeding the output of the "go test" command(s)
into gotestsum *while it runs*, we can use --format=standard-quiet (= normal go
test output) or --format=standard-verbose (= `go test -v`) when FULL_LOG is
requested to get nicer output.
This works when testing everything at once. This was said to be not possible
when doing coverage profiling. But recent Go no longer has that limitation, so
the xargs trick gets removed. All that we need to do for coverage profiling is
to add some additional parameters and the conversion to HTML.
2024-06-14 10:24:38 -04:00
if [ [ ${ KUBE_COVER } = ~ ^[ yY] $ ] ] ; then
coverage_html_file = " ${ cover_report_dir } /combined-coverage.html "
go tool cover -html= " ${ COMBINED_COVER_PROFILE } " -o= " ${ coverage_html_file } "
kube::log::status " Combined coverage report: ${ coverage_html_file } "
2019-09-23 13:36:00 -04:00
fi
test: filter "go test" output with gotestsum instead of grep
Filtering the output with grep leads to hard to read log output, e.g. from
pull-kubernetes-unit:
+++ [0613 15:32:48] Running tests without code coverage and with -race
{"Time":"2024-06-13T15:33:47.845457374Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Test":"TestCreateMasterAuditPolicy","Output":" /tmp/configure-helper-test47992121/kube-env: line 1: `}'\n"}
{"Time":"2024-06-13T15:33:49.053732803Z","Action":"output","Package":"k8s.io/kubernetes/cluster/gce/cos","Output":"ok \tk8s.io/kubernetes/cluster/gce/cos\t2.906s\n"}
We can do better than that. When feeding the output of the "go test" command(s)
into gotestsum *while it runs*, we can use --format=standard-quiet (= normal go
test output) or --format=standard-verbose (= `go test -v`) when FULL_LOG is
requested to get nicer output.
This works when testing everything at once. This was said to be not possible
when doing coverage profiling. But recent Go no longer has that limitation, so
the xargs trick gets removed. All that we need to do for coverage profiling is
to add some additional parameters and the conversion to HTML.
2024-06-14 10:24:38 -04:00
return " ${ rc } "
2016-05-24 11:40:44 -04:00
}
reportCoverageToCoveralls( ) {
if [ [ ${ KUBE_COVER } = ~ ^[ yY] $ ] ] && [ [ -x " ${ KUBE_GOVERALLS_BIN } " ] ] ; then
kube::log::status " Reporting coverage results to Coveralls for service ${ CI_NAME :- } "
${ KUBE_GOVERALLS_BIN } -coverprofile= " ${ COMBINED_COVER_PROFILE } " \
${ CI_NAME : + " -service= ${ CI_NAME } " } \
${ COVERALLS_REPO_TOKEN : + " -repotoken= ${ COVERALLS_REPO_TOKEN } " } \
|| true
fi
}
checkFDs( ) {
# several unittests panic when httptest cannot open more sockets
# due to the low default files limit on OS X. Warn about low limit.
2019-03-28 03:29:34 -04:00
local fileslimit
fileslimit = " $( ulimit -n) "
2019-01-18 13:17:16 -05:00
if [ [ ${ fileslimit } -lt 1000 ] ] ; then
echo " WARNING: ulimit -n (files) should be at least 1000, is ${ fileslimit } , may cause test failure " ;
2016-05-24 11:40:44 -04:00
fi
}
checkFDs
2019-12-13 11:53:35 -05:00
runTests " $@ "
2016-05-24 11:40:44 -04:00
# We might run the tests for multiple versions, but we want to report only
# one of them to coveralls. Here we report coverage from the last run.
reportCoverageToCoveralls