@@ -167,7 +167,7 @@ load "${BATS_PLUGIN_PATH}/load.bash"
167167
168168 unstub buildkite-agent
169169 unstub tar
170-
170+
171171 unset BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_FROM
172172 unset BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_TO
173173 unset BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED
@@ -193,7 +193,7 @@ load "${BATS_PLUGIN_PATH}/load.bash"
193193 assert_output --partial " Compressing file.log to file.zip"
194194 assert_output --partial " uploaded file.zip"
195195 refute_output --partial " uploaded file.log"
196-
196+
197197 unstub buildkite-agent
198198 unstub zip
199199
@@ -224,7 +224,7 @@ load "${BATS_PLUGIN_PATH}/load.bash"
224224 assert_output --partial " Compressing file.log to file.tgz"
225225 assert_output --partial " uploaded file.tgz"
226226 refute_output --partial " uploaded file.log"
227-
227+
228228 unstub buildkite-agent
229229 unstub tar
230230
@@ -349,7 +349,7 @@ load "${BATS_PLUGIN_PATH}/load.bash"
349349
350350 unstub buildkite-agent
351351 unstub zip
352-
352+
353353 unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_0_FROM
354354 unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_0_TO
355355 unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_1
@@ -429,4 +429,91 @@ load "${BATS_PLUGIN_PATH}/load.bash"
429429 unset BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_0_FROM
430430 unset BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_0_TO
431431 unset BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED
432- }
432+ }
433+
434+ @test " Post-command does not replace compressed file variables" {
435+ export RANDOM_VAR=" random-value"
436+ export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD=" test.log"
437+ export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED=" file-\$ {RANDOM_VAR}.zip"
438+
439+ touch " test.log"
440+
441+ stub buildkite-agent \
442+ " artifact upload \* : echo uploaded \$ 3"
443+
444+ stub zip \
445+ " -r \* \* : echo zipped \$ 3 into \$ 2"
446+
447+ run " $PWD /hooks/post-command"
448+
449+ assert_success
450+
451+ assert_output --partial " Compressing test.log to file-\$ {RANDOM_VAR}.zip"
452+ refute_output --partial " Compressing test.log to file-random-value.zip"
453+
454+ unstub buildkite-agent
455+ unstub zip
456+
457+ rm " test.log"
458+ }
459+
460+ @test " Post-command replaces compressed file variables" {
461+ export RANDOM_VAR=" random-value"
462+ export OTHER_VAR=" other-value"
463+ export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD=" test-\$ {OTHER_VAR}.log"
464+ export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED=" file-\$ {RANDOM_VAR}.zip"
465+ export BUILDKITE_PLUGIN_ARTIFACTS_EXPAND_UPLOAD_VARS=" true"
466+
467+ touch " test-other-value.log"
468+
469+ stub buildkite-agent \
470+ " artifact upload \* : echo uploaded \$ 3"
471+
472+ stub zip \
473+ " -r \* \* : echo zipped \$ 3 into \$ 2"
474+
475+ run " $PWD /hooks/post-command"
476+
477+ assert_success
478+
479+ assert_output --partial " Compressing test-other-value.log to file-random-value.zip"
480+
481+ unstub buildkite-agent
482+ unstub zip
483+
484+ rm " test-other-value.log"
485+ }
486+
487+ @test " Post-command replaces file variables with multiple files with relocation (sometimes)" {
488+ export RANDOM_VAR=" random-value"
489+ export OTHER_VAR=" other-value"
490+ export DEST_VAR=" dest-value"
491+ export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_0=" test-\$ {OTHER_VAR}.log"
492+ export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_1_FROM=" test2-\$ {OTHER_VAR}.log"
493+ export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_1_TO=" test-\$ {DEST_VAR}.log"
494+ export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED=" file-\$ {RANDOM_VAR}.zip"
495+ export BUILDKITE_PLUGIN_ARTIFACTS_EXPAND_UPLOAD_VARS=" true"
496+
497+ touch " test-other-value.log"
498+ touch " test2-other-value.log"
499+
500+ stub buildkite-agent \
501+ " artifact upload \* : echo uploaded \$ 3"
502+
503+ stub zip \
504+ " -r \* \* : echo zipped \$ 3 into \$ 2"
505+
506+ run " $PWD /hooks/post-command"
507+
508+ assert_success
509+
510+ assert_output --partial " Moving [test2-other-value.log] to [test-dest-value.log]"
511+ assert_output --partial " Compressing test-other-value.log test-dest-value.log to file-random-value.zip"
512+
513+ unstub buildkite-agent
514+ unstub zip
515+
516+ rm -f " test-other-value.log"
517+ rm -f " test2-other-value.log"
518+ rm -f " test-dest-value.log"
519+ }
0 commit comments