Skip to content

Commit 2adc6af

Browse files
tootedansamsara
authored andcommitted
Added tests with compression and multiple levels
1 parent e8acf29 commit 2adc6af

1 file changed

Lines changed: 77 additions & 5 deletions

File tree

tests/soft-fail.bats

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Tests for the soft-fail option feature
44
# This feature allows cache operations to fail gracefully without blocking the build
55

6+
# To debug stubs, uncomment these lines:
7+
# export CACHE_DUMMY_STUB_DEBUG=/dev/tty
8+
69
setup() {
710
load "${BATS_PLUGIN_PATH}/load.bash"
811

@@ -62,21 +65,56 @@ teardown() {
6265
assert_output --partial 'Missing manifest option'
6366
}
6467

65-
@test "Soft-fail restore: successful restore works normally" {
68+
@test "Soft-fail restore: backend restore failure exits 0 with warning" {
6669
export BUILDKITE_PLUGIN_CACHE_RESTORE=step
67-
unset BUILDKITE_PLUGIN_CACHE_MANIFEST
6870

6971
stub cache_dummy \
7072
'exists \* : exit 0' \
71-
'get \* \* : echo "restoring cache"; exit 0'
73+
'get \* \* : exit 1'
74+
75+
run "$PWD/hooks/pre-command"
76+
77+
assert_success
78+
assert_output --partial 'Cache restore operation failed, continuing build (soft-fail enabled)'
79+
80+
unstub cache_dummy
81+
}
82+
83+
@test "Soft-fail restore: backend restore intermediate failure exits 0 with warning" {
84+
export BUILDKITE_PLUGIN_CACHE_RESTORE=pipeline
85+
86+
stub cache_dummy \
87+
'exists \* : exit 1' \
88+
'exists \* : exit 0' \
89+
'get \* \* : exit 1'
90+
91+
run "$PWD/hooks/pre-command"
92+
93+
assert_success
94+
assert_output --partial 'Cache restore operation failed, continuing build (soft-fail enabled)'
95+
96+
unstub cache_dummy
97+
}
98+
99+
@test "Soft fail restore: compression failure exits 0 with warning" {
100+
export BUILDKITE_PLUGIN_CACHE_RESTORE=step
101+
export BUILDKITE_PLUGIN_CACHE_COMPRESSION=dummy_compress
102+
103+
stub cache_dummy \
104+
'exists \* : exit 0' \
105+
"get \* \* : echo restoring \$2 to \$3"
106+
107+
stub dummy_compress_wrapper \
108+
"decompress \* \* : exit 1"
72109

73110
run "$PWD/hooks/pre-command"
74111

75112
assert_success
76-
assert_output --partial 'Cache hit at step level'
77-
refute_output --partial 'soft-fail'
113+
assert_output --partial 'Cache is compressed, decompressing with dummy_compress'
114+
assert_output --partial 'Cache restore operation failed, continuing build (soft-fail enabled)'
78115

79116
unstub cache_dummy
117+
unstub dummy_compress_wrapper
80118
}
81119

82120
# ============================================================================
@@ -154,3 +192,37 @@ teardown() {
154192

155193
unstub cache_dummy
156194
}
195+
196+
@test "Soft-fail save: multiple levels with intermediate failure exits 0 with warning" {
197+
export BUILDKITE_PLUGIN_CACHE_SAVE_0=branch
198+
export BUILDKITE_PLUGIN_CACHE_SAVE_1=step
199+
export BUILDKITE_PLUGIN_CACHE_FORCE=true
200+
201+
stub cache_dummy \
202+
'save \* \* : exit 0' \
203+
'save \* \* : exit 1'
204+
205+
run "$PWD/hooks/post-command"
206+
207+
assert_success
208+
assert_output --partial 'Cache save operation failed, continuing build (soft-fail enabled)'
209+
210+
unstub cache_dummy
211+
}
212+
213+
@test "Soft fail save: compression failure exits 0 with warning" {
214+
export BUILDKITE_PLUGIN_CACHE_SAVE=step
215+
export BUILDKITE_PLUGIN_CACHE_COMPRESSION=dummy_compress
216+
export BUILDKITE_PLUGIN_CACHE_FORCE=true
217+
218+
stub dummy_compress_wrapper \
219+
"compress \* \* : exit 1"
220+
221+
run "$PWD/hooks/post-command"
222+
223+
assert_success
224+
assert_output --partial "Compressing ${BUILDKITE_PLUGIN_CACHE_PATH} with dummy_compress"
225+
assert_output --partial 'Cache save operation failed, continuing build (soft-fail enabled)'
226+
227+
unstub dummy_compress_wrapper
228+
}

0 commit comments

Comments
 (0)