Skip to content

Commit 0a07004

Browse files
committed
Better debugging and messages for fs backend
1 parent 94424f6 commit 0a07004

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

backends/cache_fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ set -euo pipefail
44
CACHE_FOLDER="${BUILDKITE_PLUGIN_FS_CACHE_FOLDER:-/var/cache/buildkite}"
55

66
if ! [ -d "${CACHE_FOLDER}" ]; then
7-
echo "Cache folder '${CACHE_FOLDER}' does not exist"
7+
echo "Cache folder ${CACHE_FOLDER} does not exist"
8+
echo 'Is the BUILDKITE_PLUGIN_FS_CACHE_FOLDER variable setup correctly?'
89
exit 1
910
fi
1011

tests/cache_fs.bats

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
setup() {
77
load "${BATS_PLUGIN_PATH}/load.bash"
88

9-
export BUILDKITE_PLUGIN_FS_CACHE_FOLDER=/tmp/fs-test
9+
export BUILDKITE_PLUGIN_FS_CACHE_FOLDER="/${BATS_TEST_TMPDIR}/fs-test"
1010
mkdir -p "${BUILDKITE_PLUGIN_FS_CACHE_FOLDER}"
1111
touch "${BUILDKITE_PLUGIN_FS_CACHE_FOLDER}/existing_file"
1212
mkdir "${BUILDKITE_PLUGIN_FS_CACHE_FOLDER}/existing_folder"
@@ -23,6 +23,16 @@ teardown() {
2323
assert_output ''
2424
}
2525

26+
@test "Backend fails if cache folder does not exist" {
27+
export BUILDKITE_PLUGIN_FS_CACHE_FOLDER=/does/not/exist
28+
29+
run "${PWD}/backends/cache_fs" exists whatever
30+
31+
assert_failure 1
32+
assert_output --partial 'Cache folder /does/not/exist does not exist'
33+
assert_output --partial 'BUILDKITE_PLUGIN_FS_CACHE_FOLDER variable'
34+
}
35+
2636
@test 'Exists on non-existing file fails' {
2737
run "${PWD}/backends/cache_fs" exists PATH/THAT/DOES/NOT/EXIST
2838

@@ -38,7 +48,7 @@ teardown() {
3848
}
3949

4050
@test 'Exists on existing folder works' {
41-
run "${PWD}/backends/cache_fs" exists existing_folder
51+
run "${PWD}/backends/cache_fs" exists existing_folder
4252

4353
assert_success
4454
assert_output ''
@@ -48,7 +58,7 @@ teardown() {
4858
touch "${BATS_TEST_TMPDIR}/new-file"
4959

5060
run "${PWD}/backends/cache_fs" exists new-file
51-
61+
5262
assert_failure
5363
assert_output ''
5464

@@ -74,7 +84,7 @@ teardown() {
7484
echo 'random content' > "${BATS_TEST_TMPDIR}/new-folder/new-file"
7585

7686
run "${PWD}/backends/cache_fs" exists new-folder
77-
87+
7888
assert_failure
7989
assert_output ''
8090

0 commit comments

Comments
 (0)