@@ -344,4 +344,81 @@ export annotation_input="tests/tmp/annotation.input"
344
344
345
345
unstub mktemp
346
346
unstub buildkite-agent
347
+ }
348
+
349
+ @test " creates annotation with no failures but min tests triggers" {
350
+ export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS=" junits/*.xml"
351
+ export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_MIN_TESTS=1
352
+
353
+ stub mktemp \
354
+ " -d \* : mkdir -p '$artifacts_tmp '; echo '$artifacts_tmp '" \
355
+ " -d \* : mkdir -p '$annotation_tmp '; echo '$annotation_tmp '"
356
+
357
+ stub buildkite-agent \
358
+ " artifact download \* \* : echo Downloaded artifact \$ 3 to \$ 4" \
359
+ " annotate --context \* --style \* : cat >'${annotation_input} '; echo Annotation added with context \$ 3 and style \$ 5, content saved"
360
+
361
+ stub docker \
362
+ " --log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo 'Total tests: 0'"
363
+
364
+ run " $PWD /hooks/command"
365
+
366
+ assert_failure
367
+ assert_output --partial " Total tests: 0"
368
+ assert_output --partial " Less than 1 tests analyzed"
369
+ assert_equal " $( cat " ${annotation_input} " ) " ' Total tests: 0'
370
+
371
+ unstub mktemp
372
+ unstub buildkite-agent
373
+ unstub docker
374
+ }
375
+
376
+ @test " no failures and min-tests ok does not create annotation" {
377
+ export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS=" junits/*.xml"
378
+ export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_MIN_TESTS=12
379
+
380
+ stub mktemp \
381
+ " -d \* : mkdir -p '$artifacts_tmp '; echo '$artifacts_tmp '" \
382
+ " -d \* : mkdir -p '$annotation_tmp '; echo '$annotation_tmp '"
383
+
384
+ stub buildkite-agent \
385
+ " artifact download \* \* : echo Downloaded artifact \$ 3 to \$ 4"
386
+
387
+ stub docker \
388
+ " --log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo 'Total tests: 100'"
389
+
390
+ run " $PWD /hooks/command"
391
+
392
+ assert_success
393
+ assert_output --partial " Total tests: 100"
394
+ refute_output --partial " Less than 12 tests analyzed"
395
+
396
+ unstub mktemp
397
+ unstub buildkite-agent
398
+ unstub docker
399
+ }
400
+
401
+ @test " min-tests doesn't interfere with actual failures" {
402
+ export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS=" junits/*.xml"
403
+ export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_MIN_TESTS=10000
404
+
405
+ stub mktemp \
406
+ " -d \* : mkdir -p '$artifacts_tmp '; echo '$artifacts_tmp '" \
407
+ " -d \* : mkdir -p '$annotation_tmp '; echo '$annotation_tmp '"
408
+
409
+ stub buildkite-agent \
410
+ " artifact download \* \* : echo Downloaded artifact \$ 3 to \$ 4" \
411
+ " annotate --context \* --style \* : cat >'${annotation_input} '; echo Annotation added with context \$ 3 and style \$ 5, content saved"
412
+
413
+ stub docker \
414
+ " --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"
415
+
416
+ run " $PWD /hooks/command"
417
+
418
+ assert_success
419
+ assert_output --partial " Total tests: 2"
420
+
421
+ unstub mktemp
422
+ unstub buildkite-agent
423
+ unstub docker
347
424
}
0 commit comments