Skip to content

Commit 6294732

Browse files
authored
Merge branch 'master' into toote_s3_backend_sync
2 parents d369054 + 5662a64 commit 6294732

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

backends/cache_s3

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ s3_cmd() {
4040
s3_listobjects() {
4141
local prefix="$1"
4242

43-
aws_cmd=(aws s3api list-objects-v2 --bucket "${BUILDKITE_PLUGIN_S3_CACHE_BUCKET}" --prefix "$(build_key "${prefix}")" --max-items 1)
43+
aws_cmd=(aws s3api list-objects-v2 --bucket "${BUILDKITE_PLUGIN_S3_CACHE_BUCKET}" --prefix "$(build_key "${prefix}")" --max-items 1 --query Contents)
4444

4545
if [ -n "${BUILDKITE_PLUGIN_S3_CACHE_ENDPOINT}" ]; then
4646
aws_cmd+=(--endpoint-url "${BUILDKITE_PLUGIN_S3_CACHE_ENDPOINT}")
4747
fi
4848

49-
"${aws_cmd[@]}"
49+
result=$("${aws_cmd[@]}")
50+
[ "${result}" != 'null' ]
5051
}
5152

5253
restore_cache() {
@@ -70,7 +71,7 @@ save_cache() {
7071

7172
exists_cache() {
7273
if [ -z "$1" ]; then exit 1; fi
73-
[ -n "$(s3_listobjects "$1")" ]
74+
s3_listobjects "$1"
7475
}
7576

7677
OPCODE="$1"

tests/cache_s3.bats

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ setup() {
3737
}
3838

3939
@test 'Exists on non-existing file fails' {
40-
stub aws 'exit 1'
40+
stub aws 'echo null'
4141

4242
run "${PWD}/backends/cache_s3" exists PATH/THAT/DOES/NOT/EXIST
4343

@@ -97,10 +97,10 @@ setup() {
9797
stub aws \
9898
's3 cp --recursive --endpoint-url https://s3.somewhere.com \* \* : echo ' \
9999
's3 cp --recursive --endpoint-url https://s3.somewhere.com \* \* : echo ' \
100-
's3api list-objects-v2 --bucket \* --prefix \* --max-items 1 --endpoint-url https://s3.somewhere.com : echo exists' \
100+
's3api list-objects-v2 --bucket \* --prefix \* --max-items 1 --query Contents --endpoint-url https://s3.somewhere.com : echo exists' \
101101
's3 cp --recursive \* \* : echo ' \
102102
's3 cp --recursive \* \* : echo ' \
103-
's3api list-objects-v2 --bucket \* --prefix \* --max-items 1 : echo exists'
103+
's3api list-objects-v2 --bucket \* --prefix \* --max-items 1 --query Contents : echo exists'
104104

105105
run "${PWD}/backends/cache_s3" save from to
106106

@@ -141,7 +141,7 @@ setup() {
141141
touch "${BATS_TEST_TMPDIR}/new-file"
142142
mkdir "${BATS_TEST_TMPDIR}/s3-cache"
143143
stub aws \
144-
"echo" \
144+
"echo null" \
145145
"ln -s \$4 $BATS_TEST_TMPDIR/s3-cache/\$(echo \$5 | md5sum | cut -c-32)" \
146146
"echo 'exists'" \
147147
"cp -r $BATS_TEST_TMPDIR/s3-cache/\$(echo \$4 | md5sum | cut -c-32) \$5"
@@ -179,7 +179,7 @@ setup() {
179179
echo 'random content' > "${BATS_TEST_TMPDIR}/new-folder/new-file"
180180

181181
stub aws \
182-
"echo" \
182+
"echo null" \
183183
"ln -s \$4 $BATS_TEST_TMPDIR/s3-cache/\$(echo \$5 | md5sum | cut -c-32)" \
184184
"echo 'exists'" \
185185
"cp -r $BATS_TEST_TMPDIR/s3-cache/\$(echo \$4 | md5sum | cut -c-32) \$5"

0 commit comments

Comments
 (0)