Add coverage checks
This commit adds a makefile target for generating a report for unit test coverage. It also adds the coverage_check tool to assert that the actual test coverage meets the specified requirement. This also improves various aspects of the testing utilities: * The "test" package has been renamed to "testutil" * The "Objs" member has been removed from the CmdTest object * The "Cmd" member has been added to the CmdTest object. This allows testing of multiple variants of a root airshipctl command Finally, this commit includes additional tests for root.go. These are required in order to meet the required coverage threshold. Change-Id: Id48343166c0488c543a405ec3143e4a75355ba43changes/37/670337/7
parent
7c8ee26de4
commit
1c999e2095
@ -0,0 +1,20 @@
|
||||
airshipctl is a unified entrypoint to various airship components
|
||||
|
||||
Usage:
|
||||
airshipctl [command]
|
||||
|
||||
Available Commands:
|
||||
argo argo is the command line interface to Argo
|
||||
bootstrap bootstraps airshipctl
|
||||
completion Generate autocompletions script for the specified shell (bash or zsh)
|
||||
help Help about any command
|
||||
kubeadm kubeadm: easily bootstrap a secure Kubernetes cluster
|
||||
kubectl kubectl controls the Kubernetes cluster manager
|
||||
kustomize Build a kustomization target from a directory or a remote url.
|
||||
version Show the version number of airshipctl
|
||||
|
||||
Flags:
|
||||
--debug enable verbose output
|
||||
-h, --help help for airshipctl
|
||||
|
||||
Use "airshipctl [command] --help" for more information about a command.
|
@ -0,0 +1,15 @@
|
||||
airshipctl is a unified entrypoint to various airship components
|
||||
|
||||
Usage:
|
||||
airshipctl [command]
|
||||
|
||||
Available Commands:
|
||||
bootstrap bootstraps airshipctl
|
||||
help Help about any command
|
||||
version Show the version number of airshipctl
|
||||
|
||||
Flags:
|
||||
--debug enable verbose output
|
||||
-h, --help help for airshipctl
|
||||
|
||||
Use "airshipctl [command] --help" for more information about a command.
|
@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
if [[ $# -ne 1 ]]; then
|
||||
printf "Usage: %s <coverfile>\n" "$0"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
cover_file=$1
|
||||
min_coverage=80
|
||||
|
||||
coverage_report=$(go tool cover -func="$cover_file")
|
||||
printf "%s\n" "$coverage_report"
|
||||
|
||||
coverage_float=$(awk "/^total:/ { print \$3 }" <<< "$coverage_report")
|
||||
coverage_int=${coverage_float%.*}
|
||||
|
||||
if (( "$coverage_int" < "$min_coverage" )) ; then
|
||||
printf "FAIL: Test coverage is at %s, which does not meet the required coverage (%s%%)\n" "$coverage_float" "$min_coverage"
|
||||
exit 1
|
||||
else
|
||||
printf "SUCCESS: Test coverage is at %s, which meets the required coverage (%s%%)\n" "$coverage_float" "$min_coverage"
|
||||
fi
|
Loading…
Reference in New Issue