Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added coverage to make test #816

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 5 additions & 47 deletions hack/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,17 @@
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

junitFilenamePrefix() {
if [[ -z "${JUNIT_REPORT_DIR}" ]]; then
echo ""
return
fi
mkdir -p "${JUNIT_REPORT_DIR}"
DATE=$( date +%s | base64 | head -c 15 )
echo "${JUNIT_REPORT_DIR}/junit_$DATE"
}

function produce_junit_xmlreport {
local -r junit_filename_prefix=$1
if [[ -z "${junit_filename_prefix}" ]]; then
if [[ -z "${ARTIFACTS}" ]]; then
return
fi

local junit_xml_filename
junit_xml_filename="${junit_filename_prefix}.xml"

if ! command -v gotestsum >/dev/null 2>&1; then
echo "gotestsum not found; installing now"
go install gotest.tools/[email protected]
fi
export PATH=$GOBIN:$GOPATH/bin:$PATH
gotestsum --junitfile "${junit_xml_filename}" --raw-command cat "${junit_filename_prefix}"*.stdout
echo "Saved JUnit XML test report to ${junit_xml_filename}"
cp cover.out "${ARTIFACTS}/cover.out"
go tool cover -html="${ARTIFACTS}/cover.out" -o "${ARTIFACTS}/cover.html"
}

goTestFlags=""

##### Create a junit-style XML test report in this directory if set. #####
JUNIT_REPORT_DIR=${JUNIT_REPORT_DIR:-}

# If JUNIT_REPORT_DIR is unset, and ARTIFACTS is set, then have them match.
if [[ -z "${JUNIT_REPORT_DIR:-}" && -n "${ARTIFACTS:-}" ]]; then
export JUNIT_REPORT_DIR="${ARTIFACTS}"
fi

# Used to filter verbose test output.
go_test_grep_pattern=".*"

if [[ -n "${JUNIT_REPORT_DIR}" ]] ; then
goTestFlags+="-v "
goTestFlags+="-json "
# Show only summary lines by matching lines like "status package/test"
go_test_grep_pattern="^[^[:space:]]\+[[:space:]]\+[^[:space:]]\+/[^[[:space:]]\+"
fi

junit_filename_prefix=$(junitFilenamePrefix)

go test ${goTestFlags} -race ./cmd/... ./pkg/... | tee ${junit_filename_prefix:+"${junit_filename_prefix}.stdout"} | grep --binary-files=text "${go_test_grep_pattern}"
go test -v -race ./cmd/... ./pkg/... -coverprofile cover.out

produce_junit_xmlreport "${junit_filename_prefix}"
produce_junit_xmlreport