@@ -50,6 +50,8 @@ KUBE_COVERPROCS=${KUBE_COVERPROCS:-4}
50
50
KUBE_RACE=${KUBE_RACE:- } # use KUBE_RACE="-race" to enable race testing
51
51
# Set to the goveralls binary path to report coverage results to Coveralls.io.
52
52
KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:- }
53
+ # Comma separated list of API Versions that should be tested.
54
+ KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:- " v1beta1,v1beta3" }
53
55
54
56
kube::test::usage () {
55
57
kube::log::usage_from_stdin << EOF
@@ -109,87 +111,107 @@ if [[ ${#testcases[@]} -eq 0 ]]; then
109
111
fi
110
112
set -- " ${testcases[@]+${testcases[@]} } "
111
113
112
- # TODO: this should probably be refactored to avoid code duplication with the
113
- # coverage version.
114
- if [[ $iterations -gt 1 ]]; then
115
- if [[ $# -eq 0 ]]; then
116
- set -- $( kube::test::find_dirs)
114
+ runTests () {
115
+ # TODO: this should probably be refactored to avoid code duplication with the
116
+ # coverage version.
117
+ if [[ $iterations -gt 1 ]]; then
118
+ if [[ $# -eq 0 ]]; then
119
+ set -- $( kube::test::find_dirs)
120
+ fi
121
+ kube::log::status " Running ${iterations} times"
122
+ fails=0
123
+ for arg; do
124
+ trap ' exit 1' SIGINT
125
+ pkg=${KUBE_GO_PACKAGE} /${arg}
126
+ kube::log::status " ${pkg} "
127
+ # keep going, even if there are failures
128
+ pass=0
129
+ count=0
130
+ for i in $( seq 1 ${iterations} ) ; do
131
+ if go test " ${goflags[@]: +${goflags[@]} } " \
132
+ ${KUBE_RACE} ${KUBE_TIMEOUT} " ${pkg} " ; then
133
+ pass=$(( pass + 1 ))
134
+ else
135
+ fails=$(( fails + 1 ))
136
+ fi
137
+ count=$(( count + 1 ))
138
+ done 2>&1
139
+ kube::log::status " ${pass} / ${count} passed"
140
+ done
141
+ if [[ ${fails} -gt 0 ]]; then
142
+ return 1
143
+ else
144
+ return 0
145
+ fi
117
146
fi
118
- kube::log::status " Running ${iterations} times"
119
- fails=0
120
- for arg; do
121
- trap ' exit 1' SIGINT
122
- pkg=${KUBE_GO_PACKAGE} /${arg}
123
- kube::log::status " ${pkg} "
124
- # keep going, even if there are failures
125
- pass=0
126
- count=0
127
- for i in $( seq 1 ${iterations} ) ; do
128
- if go test " ${goflags[@]: +${goflags[@]} } " \
129
- ${KUBE_RACE} ${KUBE_TIMEOUT} " ${pkg} " ; then
130
- pass=$(( pass + 1 ))
131
- else
132
- fails=$(( fails + 1 ))
133
- fi
134
- count=$(( count + 1 ))
135
- done 2>&1
136
- kube::log::status " ${pass} / ${count} passed"
137
- done
138
- if [[ ${fails} -gt 0 ]]; then
139
- exit 1
140
- else
141
- exit 0
147
+
148
+ # If we're not collecting coverage, run all requested tests with one 'go test'
149
+ # command, which is much faster.
150
+ if [[ ! ${KUBE_COVER} =~ ^[yY]$ ]]; then
151
+ kube::log::status " Running unit tests without code coverage"
152
+ go test " ${goflags[@]: +${goflags[@]} } " \
153
+ ${KUBE_RACE} ${KUBE_TIMEOUT} " ${@ +${@/#/ ${KUBE_GO_PACKAGE} / } } "
154
+ return 0
142
155
fi
143
- fi
144
156
145
- # If we're not collecting coverage, run all requested tests with one 'go test'
146
- # command, which is much faster.
147
- if [[ ! ${KUBE_COVER} =~ ^[yY]$ ]]; then
148
- kube::log::status " Running unit tests without code coverage"
149
- go test " ${goflags[@]: +${goflags[@]} } " \
150
- ${KUBE_RACE} ${KUBE_TIMEOUT} " ${@ +${@/#/ ${KUBE_GO_PACKAGE} / } } "
151
- exit 0
152
- fi
157
+ # Create coverage report directories.
158
+ cover_report_dir=" /tmp/k8s_coverage/${KUBE_API_VERSION} /$( kube::util::sortable_date) "
159
+ cover_profile=" coverage.out" # Name for each individual coverage profile
160
+ kube::log::status " Saving coverage output in '${cover_report_dir} '"
161
+ mkdir -p " ${@ +${@/#/ ${cover_report_dir} / } } "
162
+
163
+ # Run all specified tests, collecting coverage results. Go currently doesn't
164
+ # support collecting coverage across multiple packages at once, so we must issue
165
+ # separate 'go test' commands for each package and then combine at the end.
166
+ # To speed things up considerably, we can at least use xargs -P to run multiple
167
+ # 'go test' commands at once.
168
+ printf " %s\n" " ${@ } " | xargs -I{} -n1 -P${KUBE_COVERPROCS} \
169
+ go test " ${goflags[@]: +${goflags[@]} } " \
170
+ ${KUBE_RACE} \
171
+ ${KUBE_TIMEOUT} \
172
+ -cover -covermode=" ${KUBE_COVERMODE} " \
173
+ -coverprofile=" ${cover_report_dir} /{}/${cover_profile} " \
174
+ " ${cover_params[@]+${cover_params[@]} } " \
175
+ " ${KUBE_GO_PACKAGE} /{}"
176
+
177
+ COMBINED_COVER_PROFILE=" ${cover_report_dir} /combined-coverage.out"
178
+ {
179
+ # The combined coverage profile needs to start with a line indicating which
180
+ # coverage mode was used (set, count, or atomic). This line is included in
181
+ # each of the coverage profiles generated when running 'go test -cover', but
182
+ # we strip these lines out when combining so that there's only one.
183
+ echo " mode: ${KUBE_COVERMODE} "
184
+
185
+ # Include all coverage reach data in the combined profile, but exclude the
186
+ # 'mode' lines, as there should be only one.
187
+ for x in ` find " ${cover_report_dir} " -name " ${cover_profile} " ` ; do
188
+ cat $x | grep -h -v " ^mode:" || true
189
+ done
190
+ } > " ${COMBINED_COVER_PROFILE} "
191
+
192
+ coverage_html_file=" ${cover_report_dir} /combined-coverage.html"
193
+ go tool cover -html=" ${COMBINED_COVER_PROFILE} " -o=" ${coverage_html_file} "
194
+ kube::log::status " Combined coverage report: ${coverage_html_file} "
195
+ }
153
196
154
- # Create coverage report directories.
155
- cover_report_dir=" /tmp/k8s_coverage/$( kube::util::sortable_date) "
156
- cover_profile=" coverage.out" # Name for each individual coverage profile
157
- kube::log::status " Saving coverage output in '${cover_report_dir} '"
158
- mkdir -p " ${@ +${@/#/ ${cover_report_dir} / } } "
159
-
160
- # Run all specified tests, collecting coverage results. Go currently doesn't
161
- # support collecting coverage across multiple packages at once, so we must issue
162
- # separate 'go test' commands for each package and then combine at the end.
163
- # To speed things up considerably, we can at least use xargs -P to run multiple
164
- # 'go test' commands at once.
165
- printf " %s\n" " ${@ } " | xargs -I{} -n1 -P${KUBE_COVERPROCS} \
166
- go test " ${goflags[@]: +${goflags[@]} } " \
167
- ${KUBE_RACE} \
168
- ${KUBE_TIMEOUT} \
169
- -cover -covermode=" ${KUBE_COVERMODE} " \
170
- -coverprofile=" ${cover_report_dir} /{}/${cover_profile} " \
171
- " ${cover_params[@]+${cover_params[@]} } " \
172
- " ${KUBE_GO_PACKAGE} /{}"
173
-
174
- combined_cover_profile=" ${cover_report_dir} /combined-coverage.out"
175
- {
176
- # The combined coverage profile needs to start with a line indicating which
177
- # coverage mode was used (set, count, or atomic). This line is included in
178
- # each of the coverage profiles generated when running 'go test -cover', but
179
- # we strip these lines out when combining so that there's only one.
180
- echo " mode: ${KUBE_COVERMODE} "
181
-
182
- # Include all coverage reach data in the combined profile, but exclude the
183
- # 'mode' lines, as there should be only one.
184
- for x in ` find " ${cover_report_dir} " -name " ${cover_profile} " ` ; do
185
- cat $x | grep -h -v " ^mode:" || true
186
- done
187
- } > " ${combined_cover_profile} "
188
-
189
- coverage_html_file=" ${cover_report_dir} /combined-coverage.html"
190
- go tool cover -html=" ${combined_cover_profile} " -o=" ${coverage_html_file} "
191
- kube::log::status " Combined coverage report: ${coverage_html_file} "
192
-
193
- if [[ -x " ${KUBE_GOVERALLS_BIN} " ]]; then
194
- ${KUBE_GOVERALLS_BIN} -coverprofile=" ${combined_cover_profile} " || true
195
- fi
197
+ runTestsForVersion () {
198
+ export KUBE_API_VERSION=" $1 "
199
+ runTests " ${@: 2} "
200
+ }
201
+
202
+ reportCoverageToCoveralls () {
203
+ if [[ -x " ${KUBE_GOVERALLS_BIN} " ]]; then
204
+ ${KUBE_GOVERALLS_BIN} -coverprofile=" ${COMBINED_COVER_PROFILE} " || true
205
+ fi
206
+ }
207
+
208
+ # Convert the CSV to an array of API versions to test
209
+ IFS=' ,' read -a apiVersions <<< ${KUBE_TEST_API_VERSIONS}
210
+ for apiVersion in " ${apiVersions[@]} " ; do
211
+ echo " Running tests for APIVersion: $apiVersion "
212
+ runTestsForVersion $apiVersion " ${@ } "
213
+ done
214
+
215
+ # We might run the tests for multiple versions, but we want to report only
216
+ # one of them to coveralls. Here we report coverage from the last run.
217
+ reportCoverageToCoveralls
0 commit comments