From 0fb4b920b5093a23a42fd5d9bc7f1fbad4156135 Mon Sep 17 00:00:00 2001 From: Katharine Berry Date: Fri, 31 Aug 2018 10:49:36 -0700 Subject: [PATCH] Address review comments. --- hack/lib/golang.sh | 4 ++-- pkg/util/coverage/coverage.go | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index a691194c9a3..04ec4874db8 100755 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -453,7 +453,7 @@ kube::golang::outfile_for_binary() { # Argument: the name of a Kubernetes package. # Returns 0 if the binary can be built with coverage, 1 otherwise. # NB: this ignores whether coverage is globally enabled or not. -kube::golang::is_covered_binary() { +kube::golang::is_instrumented_package() { return $(kube::util::array_contains "$1" "${KUBE_COVERAGE_INSTRUMENTED_PACKAGES[@]}") } @@ -514,7 +514,7 @@ kube::golang::build_some_binaries() { if [[ -n "${build_with_coverage:-}" ]]; then local -a uncovered=() for package in "$@"; do - if kube::golang::is_covered_binary "${package}"; then + if kube::golang::is_instrumented_package "${package}"; then V=2 kube::log::info "Building ${package} with coverage..." kube::golang::create_coverage_dummy_test "${package}" diff --git a/pkg/util/coverage/coverage.go b/pkg/util/coverage/coverage.go index cfb20c2e025..bf95ae4379c 100644 --- a/pkg/util/coverage/coverage.go +++ b/pkg/util/coverage/coverage.go @@ -49,8 +49,8 @@ func InitCoverage(name string) { coverageFile = "/tmp/k8s-" + name + ".cov" } - // Set up the unit test framework with the arguments we want. - flag.CommandLine.Parse([]string{"-test.coverprofile=" + tempCoveragePath()}) + // Set up the unit test framework with the required arguments to activate test coverage. + flag.CommandLine.Parse([]string{"-test.coverprofile", tempCoveragePath()}) // Begin periodic logging go wait.Forever(FlushCoverage, flushInterval) @@ -76,8 +76,6 @@ func FlushCoverage() { // This gets us atomic updates from the perspective of another process trying to access // the file. if err := os.Rename(tempCoveragePath(), coverageFile); err != nil { - // This should never fail, because we're in the same directory. There's also little that - // we can do if it does. glog.Errorf("Couldn't move coverage file from %s to %s", coverageFile, tempCoveragePath()) } }