@@ -31,16 +31,17 @@ export annotation_tmp="tests/tmp/junit-annotation"
31
31
32
32
assert_success
33
33
34
- assert_output --partial " Annotation added"
34
+ assert_output --partial " Annotation added with context junit and style error "
35
35
36
36
unstub mktemp
37
37
unstub buildkite-agent
38
38
unstub docker
39
39
}
40
40
41
- @test " returns an error if fail-build-on-error is true" {
41
+
42
+ @test " can define a special context" {
42
43
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS=" junits/*.xml"
43
- export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=true
44
+ export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT= " junit_custom_context "
44
45
45
46
stub mktemp \
46
47
" -d \* : mkdir -p '$artifacts_tmp '; echo '$artifacts_tmp '" \
@@ -55,19 +56,17 @@ export annotation_tmp="tests/tmp/junit-annotation"
55
56
56
57
run " $PWD /hooks/command"
57
58
58
- assert_failure
59
+ assert_success
59
60
61
+ assert_output --partial " Annotation added with context junit_custom_context"
62
+
60
63
unstub mktemp
61
64
unstub buildkite-agent
62
65
unstub docker
63
66
}
64
-
65
- @test " can pass through optional params" {
67
+ @test " can pass through optional job uuid file pattern" {
66
68
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS=" junits/*.xml"
67
69
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=" custom_(*)_pattern.xml"
68
- export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=" file"
69
- export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=false
70
- export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT=" junit_custom_context"
71
70
72
71
stub mktemp \
73
72
" -d \* : mkdir -p '$artifacts_tmp '; echo '$artifacts_tmp '" \
@@ -91,6 +90,33 @@ export annotation_tmp="tests/tmp/junit-annotation"
91
90
unstub docker
92
91
}
93
92
93
+ @test " can pass through optional failure format" {
94
+ export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS=" junits/*.xml"
95
+ export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT=" junit_custom_context"
96
+ export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=" file"
97
+
98
+ stub mktemp \
99
+ " -d \* : mkdir -p '$artifacts_tmp '; echo '$artifacts_tmp '" \
100
+ " -d \* : mkdir -p '$annotation_tmp '; echo '$annotation_tmp '"
101
+
102
+ stub buildkite-agent \
103
+ " artifact download \* \* : echo Downloaded artifact \$ 3 to \$ 4" \
104
+ " annotate --context \* --style \* : cat >'${annotation_tmp} /annotation.input'; echo Annotation added with context \$ 3 and style \$ 5, content saved"
105
+
106
+ stub docker \
107
+ " --log-level error run --rm --volume \* --volume \* --env \* --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT='file' --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo '<details>Failure</details>' && exit 64"
108
+
109
+ run " $PWD /hooks/command"
110
+
111
+ assert_success
112
+
113
+ assert_output --partial " Annotation added"
114
+
115
+ unstub mktemp
116
+ unstub buildkite-agent
117
+ unstub docker
118
+ }
119
+
94
120
@test " doesn't create annotation unless there's failures" {
95
121
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS=" junits/*.xml"
96
122
@@ -150,6 +176,31 @@ export annotation_tmp="tests/tmp/junit-annotation"
150
176
unstub mktemp
151
177
}
152
178
179
+
180
+ @test " returns an error if fail-build-on-error is true" {
181
+ export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS=" junits/*.xml"
182
+ export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=true
183
+
184
+ stub mktemp \
185
+ " -d \* : mkdir -p '$artifacts_tmp '; echo '$artifacts_tmp '" \
186
+ " -d \* : mkdir -p '$annotation_tmp '; echo '$annotation_tmp '"
187
+
188
+ stub buildkite-agent \
189
+ " artifact download \* \* : echo Downloaded artifact \$ 3 to \$ 4" \
190
+ " annotate --context \* --style \* : cat >'${annotation_tmp} /annotation.input'; echo Annotation added with context \$ 3 and style \$ 5, content saved"
191
+
192
+ stub docker \
193
+ " --log-level error run --rm --volume \* --volume \* --env \* --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo '<details>Failure</details>' && exit 64"
194
+
195
+ run " $PWD /hooks/command"
196
+
197
+ assert_failure
198
+
199
+ unstub mktemp
200
+ unstub buildkite-agent
201
+ unstub docker
202
+ }
203
+
153
204
@test " returns an error if fail-build-on-error is true and annotation is too large" {
154
205
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS=" junits/*.xml"
155
206
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=true
0 commit comments