Skip to content

Commit e170196

Browse files
committed
Split out option tests to be independent from each other
1 parent ba12980 commit e170196

File tree

1 file changed

+60
-9
lines changed

1 file changed

+60
-9
lines changed

tests/command.bats

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ export annotation_tmp="tests/tmp/junit-annotation"
3131

3232
assert_success
3333

34-
assert_output --partial "Annotation added"
34+
assert_output --partial "Annotation added with context junit and style error"
3535

3636
unstub mktemp
3737
unstub buildkite-agent
3838
unstub docker
3939
}
4040

41-
@test "returns an error if fail-build-on-error is true" {
41+
42+
@test "can define a special context" {
4243
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"
4445

4546
stub mktemp \
4647
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
@@ -55,19 +56,17 @@ export annotation_tmp="tests/tmp/junit-annotation"
5556

5657
run "$PWD/hooks/command"
5758

58-
assert_failure
59+
assert_success
5960

61+
assert_output --partial "Annotation added with context junit_custom_context"
62+
6063
unstub mktemp
6164
unstub buildkite-agent
6265
unstub docker
6366
}
64-
65-
@test "can pass through optional params" {
67+
@test "can pass through optional job uuid file pattern" {
6668
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
6769
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"
7170

7271
stub mktemp \
7372
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
@@ -91,6 +90,33 @@ export annotation_tmp="tests/tmp/junit-annotation"
9190
unstub docker
9291
}
9392

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+
94120
@test "doesn't create annotation unless there's failures" {
95121
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
96122

@@ -150,6 +176,31 @@ export annotation_tmp="tests/tmp/junit-annotation"
150176
unstub mktemp
151177
}
152178

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+
153204
@test "returns an error if fail-build-on-error is true and annotation is too large" {
154205
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
155206
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=true

0 commit comments

Comments
 (0)