File: go-test.in

package info (click to toggle)
singularity-container 4.0.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 21,672 kB
  • sloc: asm: 3,857; sh: 2,125; ansic: 1,677; awk: 414; makefile: 110; python: 99
file content (165 lines) | stat: -rw-r--r-- 2,512 bytes parent folder | download | duplicates (2)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/sh

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
			;;

		-e2e_groups)
		    e2e_groups="${1}"
			skip=true
			;;

		-e2e_tests)
			e2e_tests="${1}"
			skip=true
			;;

		*)
			set -- "$@" "${arg}"
			;;
	esac
done

if ${use_gotestsum} ; then
	if ${verbose} ; then
		gotestrunner_format=standard-verbose
	fi
fi

if ${use_gotestsum} ; then
	if ${verbose} ; then
		gotestrunner_format=standard-verbose
	fi
fi

if  [ -n "${e2e_groups}" ] ; then
	set -- "$@" "-e2e_groups"
	set -- "$@" "${e2e_groups}"
fi

if  [ -n "${e2e_tests}" ] ; then
	set -- "$@" "-e2e_tests"
	set -- "$@" "${e2e_tests}"
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}