1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#!/bin/sh
# Copyright (c) Contributors to the Apptainer project, established as
# Apptainer a Series of LF Projects LLC.
# For website terms of use, trademark policy, privacy policy and other
# project policies see https://lfprojects.org/policies
# shellcheck disable=SC2317
set -e
info() {
printf 'I: %s\n' "$*"
}
error() {
printf 'E: %s\n' "$*"
}
gotestsum_runner() {
gotestsum \
--jsonfile "${junitOutput}.json" \
--format "${gotestrunner_format}" \
--raw-command \
-- \
"${GO}" test -json "$@"
}
gotestsum_postprocess() {
touch "${junitOutput}.json"
gotestsum \
--junitfile "${junitOutput}" \
--raw-command \
-- \
cat "${junitOutput}.json"
}
gotest_runner() {
"${GO}" test "$@"
}
gotest_postprocess() {
true
}
export GOFLAGS='@GOFLAGS@'
export GO111MODULE='@GO111MODULE@'
GO='@GO@'
GO_TAGS='@GO_TAGS@'
verbose=false
use_gotestsum=false
junitOutput=
gotestrunner_format=standard-quiet
test_runner=gotest_runner
test_postprocess=gotest_postprocess
skip=false
for arg in "$@" ; do
shift
if ${skip} ; then
skip=false
continue
fi
case "${arg}" in
-sudo)
# prepare sudo execution
sudo_exec='-exec @SUDO_SCRIPT@'
if [ `id -u` = 0 ]; then
error "Run $0 as user when specifying -sudo. Abort."
exit 1
fi
if ! command -v sudo > /dev/null 2>&1; then
error "sudo command not found in PATH. Abort."
exit 1
fi
# ask for password or reset the session timeout
if ! sudo -v; then
exit 1
fi
;;
-tags)
GO_TAGS="${GO_TAGS} ${1}"
skip=true
;;
-junit)
if ! command -v gotestsum > /dev/null 2>&1 ; then
error 'JUnit output requested but gotestsum not found in PATH. Abort.'
info ''
info 'Looked in the following directories, in order:'
info ''
IFS=:
for dir in ${PATH} ; do
info " ${dir}"
done
exit 1
fi
use_gotestsum=true
test_runner=gotestsum_runner
test_postprocess=gotestsum_postprocess
junitOutput="${1}"
skip=true
;;
-v|-verbose)
verbose=true
set -- "$@" -v
;;
*)
set -- "$@" "${arg}"
;;
esac
done
if ${use_gotestsum} ; then
if ${verbose} ; then
gotestrunner_format=standard-verbose
fi
fi
# capture exit code
rc=0
"${test_runner}" \
-count=1 \
-timeout=30m \
-tags "${GO_TAGS}" \
-cover \
${sudo_exec} \
"$@" ||
rc=$?
"${test_postprocess}"
# return original exit code
exit ${rc}
|