Skip to content

Commit 3398343

Browse files
committed
Corrected bug with du in tests, added summary with huge annotations
1 parent 941cc05 commit 3398343

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

hooks/command

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,19 @@ if [ $has_errors -eq 0 ]; then
7878
fi
7979
elif ! check_size; then
8080
echo "--- :warning: Failures too large to annotate"
81-
echo "The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually."
82-
create_annotation=0
81+
82+
# creating a simplified version of the annotation
83+
mv "${annotation_path}" "${annotation_path}2"
84+
head -4 "${annotation_path}2" >"${annotation_path}"
85+
# || true is to avoid issues if no summary is found
86+
grep '<summary>' "${annotation_path}2" >>"${annotation_path}" || true
87+
88+
if ! check_size; then
89+
echo "The failures are too large to create a build annotation. Please inspect the failed JUnit artifacts manually."
90+
create_annotation=0
91+
else
92+
echo "The failures are too large to create complete annotation, using a simplified annotation"
93+
fi
8394
fi
8495

8596
if [ $create_annotation -ne 0 ]; then

tests/2-tests-1-failure.output

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Failures: 0
2+
Errors: 1
3+
Total tests: 2
4+
5+
<details>
6+
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in spec.models.account_spec</code></summary>
7+
8+
<p>expected: 250 got: 500 (compared using eql?)</p>
9+
10+
<pre><code>First line of failure output
11+
Second line of failure output</code></pre>
12+
13+
</details>

tests/command.bats

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export annotation_input="tests/tmp/annotation.input"
161161
run "$PWD/hooks/command"
162162

163163
assert_success
164-
assert_output --partial "No tests errors"
164+
assert_output --partial "No test errors"
165165
assert_output --partial "Will create annotation anyways"
166166

167167
unstub mktemp
@@ -178,7 +178,7 @@ export annotation_input="tests/tmp/annotation.input"
178178
refute_output --partial ":junit:"
179179
}
180180

181-
@test "fails if the annotation is larger than 1MB" {
181+
@test "fails if the annotation is larger than 1MB even after summary" {
182182
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
183183

184184
stub mktemp \
@@ -187,7 +187,8 @@ export annotation_input="tests/tmp/annotation.input"
187187

188188
# 1KB over the 1MB size limit of annotations
189189
stub du \
190-
"-k \* : echo 1025 \$2"
190+
"-k \* : echo 1025$'\t'\$2" \
191+
"-k \* : echo 1025$'\t'\$2"
191192

192193
stub buildkite-agent \
193194
"artifact download \* \* : echo Downloaded artifact \$3 to \$4"
@@ -200,13 +201,47 @@ export annotation_input="tests/tmp/annotation.input"
200201
assert_success
201202

202203
assert_output --partial "Failures too large to annotate"
204+
assert_output --partial "failures are too large to create a build annotation"
203205

204206
unstub docker
205207
unstub du
206208
unstub buildkite-agent
207209
unstub mktemp
208210
}
209211

212+
@test "creates summary annotation if original is larger than 1MB" {
213+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
214+
215+
stub mktemp \
216+
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
217+
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"
218+
219+
# 1KB over the 1MB size limit of annotations
220+
stub du \
221+
"-k \* : echo 1025$'\t'\$2" \
222+
"-k \* : echo 10$'\t'\$2"
223+
224+
stub buildkite-agent \
225+
"artifact download \* \* : echo Downloaded artifact \$3 to \$4" \
226+
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
227+
228+
stub docker \
229+
"--log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : cat tests/2-tests-1-failure.output && exit 64"
230+
231+
run "$PWD/hooks/command"
232+
233+
assert_success
234+
235+
assert_output --partial "Failures too large to annotate"
236+
assert_output --partial "using a simplified annotation"
237+
assert_equal "5 ${annotation_input}" "$(wc -l "${annotation_input}" | cut -f 1)"
238+
239+
unstub docker
240+
unstub du
241+
unstub buildkite-agent
242+
unstub mktemp
243+
rm "${annotation_input}"
244+
}
210245

211246
@test "returns an error if fail-build-on-error is true" {
212247
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
@@ -243,7 +278,8 @@ export annotation_input="tests/tmp/annotation.input"
243278

244279
# 1KB over the 1MB size limit of annotations
245280
stub du \
246-
"-k \* : echo 1025 \$2"
281+
"-k \* : echo 1025$'\t'\$2" \
282+
"-k \* : echo 1025$'\t'\$2"
247283

248284
stub buildkite-agent \
249285
"artifact download \* \* : echo Downloaded artifact \$3 to \$4"

0 commit comments

Comments
 (0)