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