Improve bash formatting.

This commit is contained in:
Katharine Berry 2018-08-30 16:18:15 -07:00
parent 6afc130340
commit 8fe6467013
2 changed files with 18 additions and 18 deletions

View File

@ -451,7 +451,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, 0 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_covered_binary() {
return $(kube::util::array_contains "$1" "${KUBE_COVERAGE_INSTRUMENTED_PACKAGES[@]}") return $(kube::util::array_contains "$1" "${KUBE_COVERAGE_INSTRUMENTED_PACKAGES[@]}")
@ -460,9 +460,9 @@ kube::golang::is_covered_binary() {
# Argument: the name of a Kubernetes package (e.g. k8s.io/kubernetes/cmd/kube-scheduler) # Argument: the name of a Kubernetes package (e.g. k8s.io/kubernetes/cmd/kube-scheduler)
# Echos the path to a dummy test used for coverage information. # Echos the path to a dummy test used for coverage information.
kube::golang::path_for_coverage_dummy_test() { kube::golang::path_for_coverage_dummy_test() {
local package=$1 local package="$1"
local path="${KUBE_GOPATH}/src/$package" local path="${KUBE_GOPATH}/src/${package}"
local name=$(basename "$package") local name=$(basename "${package}")
echo "$path/zz_autogenerated_${name}_test.go" echo "$path/zz_autogenerated_${name}_test.go"
} }
@ -471,8 +471,8 @@ kube::golang::path_for_coverage_dummy_test() {
# This unit test will invoke the package's standard entry point when run. # This unit test will invoke the package's standard entry point when run.
kube::golang::create_coverage_dummy_test() { kube::golang::create_coverage_dummy_test() {
local package="$1" local package="$1"
local name="$(basename "$package")" local name="$(basename "${package}")"
cat <<EOF > $(kube::golang::path_for_coverage_dummy_test "$package") cat <<EOF > $(kube::golang::path_for_coverage_dummy_test "${package}")
package main package main
import ( import (
"testing" "testing"
@ -483,7 +483,7 @@ func TestMain(m *testing.M) {
// Get coverage running // Get coverage running
coverage.InitCoverage("${name}") coverage.InitCoverage("${name}")
// Go! // Go!
main() main()
// Make sure we actually write the profiling information to disk, if we make it here. // Make sure we actually write the profiling information to disk, if we make it here.
@ -495,10 +495,10 @@ EOF
} }
# Argument: the name of a Kubernetes package (e.g. k8s.io/kubernetes/cmd/kube-scheduler). # Argument: the name of a Kubernetes package (e.g. k8s.io/kubernetes/cmd/kube-scheduler).
# Deletes a test generated by kube::golang::create_coverage_dumy_test. # Deletes a test generated by kube::golang::create_coverage_dummy_test.
kube::golang::delete_coverage_dummy_test() { kube::golang::delete_coverage_dummy_test() {
local package=$1 local package="$1"
rm $(kube::golang::path_for_coverage_dummy_test "$package") rm $(kube::golang::path_for_coverage_dummy_test "${package}")
} }
# Arguments: a list of kubernetes packages to build. # Arguments: a list of kubernetes packages to build.
@ -513,18 +513,18 @@ 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_covered_binary "${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}"
go test -c -o "$(kube::golang::outfile_for_binary "$package" "$platform")" \ go test -c -o "$(kube::golang::outfile_for_binary "${package}" "${platform}")" \
-covermode count \ -covermode count \
-coverpkg k8s.io/... \ -coverpkg k8s.io/... \
"${build_args[@]}" \ "${build_args[@]}" \
-tags coverage \ -tags coverage \
"$package" "${package}"
kube::golang::delete_coverage_dummy_test "$package" kube::golang::delete_coverage_dummy_test "${package}"
else else
uncovered+=("$package") uncovered+=("${package}")
fi fi
done done
if [[ "${#uncovered[@]}" != 0 ]]; then if [[ "${#uncovered[@]}" != 0 ]]; then

View File

@ -25,7 +25,7 @@ kube::util::array_contains() {
local element local element
shift shift
for element; do for element; do
if [[ "$element" == "$search" ]]; then if [[ "${element}" == "${search}" ]]; then
return 0 return 0
fi fi
done done