Address review comments.

This commit is contained in:
Katharine Berry 2018-08-31 10:49:36 -07:00
parent 9d499cd005
commit 0fb4b920b5
2 changed files with 4 additions and 6 deletions

View File

@ -453,7 +453,7 @@ kube::golang::outfile_for_binary() {
# Argument: the name of a Kubernetes package. # Argument: the name of a Kubernetes package.
# Returns 0 if the binary can be built with coverage, 1 otherwise. # Returns 0 if the binary can be built with coverage, 1 otherwise.
# NB: this ignores whether coverage is globally enabled or not. # 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[@]}") 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 if [[ -n "${build_with_coverage:-}" ]]; then
local -a uncovered=() local -a uncovered=()
for package in "$@"; do 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..." V=2 kube::log::info "Building ${package} with coverage..."
kube::golang::create_coverage_dummy_test "${package}" kube::golang::create_coverage_dummy_test "${package}"

View File

@ -49,8 +49,8 @@ func InitCoverage(name string) {
coverageFile = "/tmp/k8s-" + name + ".cov" coverageFile = "/tmp/k8s-" + name + ".cov"
} }
// Set up the unit test framework with the arguments we want. // Set up the unit test framework with the required arguments to activate test coverage.
flag.CommandLine.Parse([]string{"-test.coverprofile=" + tempCoveragePath()}) flag.CommandLine.Parse([]string{"-test.coverprofile", tempCoveragePath()})
// Begin periodic logging // Begin periodic logging
go wait.Forever(FlushCoverage, flushInterval) 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 // This gets us atomic updates from the perspective of another process trying to access
// the file. // the file.
if err := os.Rename(tempCoveragePath(), coverageFile); err != nil { 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()) glog.Errorf("Couldn't move coverage file from %s to %s", coverageFile, tempCoveragePath())
} }
} }