Skip to content

Commit 5f38450

Browse files
committed
Correct output saving annotation
1 parent e170196 commit 5f38450

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

tests/command.bats

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ load "${BATS_PLUGIN_PATH}/load.bash"
1010

1111
export artifacts_tmp="tests/tmp/junit-artifacts"
1212
export annotation_tmp="tests/tmp/junit-annotation"
13-
13+
export annotation_input="tests/tmp/annotation.input"
1414

1515
@test "runs the annotator and creates the annotation" {
1616
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
@@ -22,7 +22,7 @@ export annotation_tmp="tests/tmp/junit-annotation"
2222

2323
stub buildkite-agent \
2424
"artifact download \* \* : echo Downloaded artifact \$3 to \$4" \
25-
"annotate --context \* --style \* : cat >'${annotation_tmp}/annotation.input'; echo Annotation added with context \$3 and style \$5, content saved"
25+
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
2626

2727
stub docker \
2828
"--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"
@@ -32,10 +32,12 @@ export annotation_tmp="tests/tmp/junit-annotation"
3232
assert_success
3333

3434
assert_output --partial "Annotation added with context junit and style error"
35-
35+
assert_equal "$(cat "${annotation_input}")" '<details>Failure</details>'
36+
3637
unstub mktemp
3738
unstub buildkite-agent
3839
unstub docker
40+
rm "${annotation_input}"
3941
}
4042

4143

@@ -49,7 +51,7 @@ export annotation_tmp="tests/tmp/junit-annotation"
4951

5052
stub buildkite-agent \
5153
"artifact download \* \* : echo Downloaded artifact \$3 to \$4" \
52-
"annotate --context \* --style \* : cat >'${annotation_tmp}/annotation.input'; echo Annotation added with context \$3 and style \$5, content saved"
54+
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
5355

5456
stub docker \
5557
"--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"
@@ -63,6 +65,7 @@ export annotation_tmp="tests/tmp/junit-annotation"
6365
unstub mktemp
6466
unstub buildkite-agent
6567
unstub docker
68+
rm "${annotation_input}"
6669
}
6770
@test "can pass through optional job uuid file pattern" {
6871
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
@@ -74,7 +77,7 @@ export annotation_tmp="tests/tmp/junit-annotation"
7477

7578
stub buildkite-agent \
7679
"artifact download \* \* : echo Downloaded artifact \$3 to \$4" \
77-
"annotate --context \* --style \* : cat >'${annotation_tmp}/annotation.input'; echo Annotation added with context \$3 and style \$5, content saved"
80+
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
7881

7982
stub docker \
8083
"--log-level error run --rm --volume \* --volume \* --env BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN='custom_(*)_pattern.xml' --env \* --env \* ruby:2.7-alpine ruby /src/bin/annotate /junits : echo '<details>Failure</details>' && exit 64"
@@ -88,11 +91,11 @@ export annotation_tmp="tests/tmp/junit-annotation"
8891
unstub mktemp
8992
unstub buildkite-agent
9093
unstub docker
94+
rm "${annotation_input}"
9195
}
9296

9397
@test "can pass through optional failure format" {
9498
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
95-
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT="junit_custom_context"
9699
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT="file"
97100

98101
stub mktemp \
@@ -101,7 +104,7 @@ export annotation_tmp="tests/tmp/junit-annotation"
101104

102105
stub buildkite-agent \
103106
"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"
107+
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
105108

106109
stub docker \
107110
"--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"
@@ -115,6 +118,7 @@ export annotation_tmp="tests/tmp/junit-annotation"
115118
unstub mktemp
116119
unstub buildkite-agent
117120
unstub docker
121+
rm "${annotation_input}"
118122
}
119123

120124
@test "doesn't create annotation unless there's failures" {
@@ -187,7 +191,7 @@ export annotation_tmp="tests/tmp/junit-annotation"
187191

188192
stub buildkite-agent \
189193
"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"
194+
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
191195

192196
stub docker \
193197
"--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"
@@ -199,6 +203,7 @@ export annotation_tmp="tests/tmp/junit-annotation"
199203
unstub mktemp
200204
unstub buildkite-agent
201205
unstub docker
206+
rm "${annotation_input}"
202207
}
203208

204209
@test "returns an error if fail-build-on-error is true and annotation is too large" {

0 commit comments

Comments
 (0)