Skip to content

Commit d64682a

Browse files
committed
test/system: Don't use XDG_CACHE_HOME or HOME for temporary files
The XDG_CACHE_HOME environment variable is supposed to default to $HOME/.cache [1], just as it did in the test suite, and this location is meant to be used as a cache for 'normal' use by the user. Test suites generally don't qualify as 'normal' use. One expects that deleting the cache shouldn't affect 'normal' use other than degrading performance. However, deleting these temporary files used by the test suite will cause actual breakage. Even if the user doesn't manually delete the cache, two concurrent invocations of the test suite can do so or lead to other unexpected collisions, because the paths are constant across multiple invocations. Therefore, it's better to limit the scope of the test suite's temporary files within the sandbox offered by Bats [2]. The sandbox is clearly labelled as being used by Bats, is unique for each invocation, and Bats takes care of cleaning everything up once it has finished running. Note that there's no need for the system-test-storage sub-directory under BATS_SUITE_TMPDIR. So it was left out. [1] https://specifications.freedesktop.org/basedir-spec/latest/ [2] https://bats-core.readthedocs.io/en/stable/writing-tests.html #1645
1 parent e980323 commit d64682a

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

test/system/libs/helpers.bash

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ load 'libs/bats-support/load'
44
load 'libs/bats-assert/load'
55

66
# Helpful globals
7-
readonly TEMP_BASE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/toolbx"
8-
readonly TEMP_STORAGE_DIR="${TEMP_BASE_DIR}/system-test-storage"
9-
107
readonly IMAGE_CACHE_DIR="${BATS_SUITE_TMPDIR}/image-cache"
11-
readonly ROOTLESS_PODMAN_STORE_DIR="${TEMP_STORAGE_DIR}/storage"
12-
readonly ROOTLESS_PODMAN_RUNROOT_DIR="${TEMP_STORAGE_DIR}/runroot"
13-
readonly PODMAN_STORE_CONFIG_FILE="${TEMP_STORAGE_DIR}/storage.conf"
14-
readonly DOCKER_REG_ROOT="${TEMP_STORAGE_DIR}/docker-registry-root"
8+
readonly ROOTLESS_PODMAN_STORE_DIR="${BATS_SUITE_TMPDIR}/storage"
9+
readonly ROOTLESS_PODMAN_RUNROOT_DIR="${BATS_SUITE_TMPDIR}/runroot"
10+
readonly PODMAN_STORE_CONFIG_FILE="${BATS_SUITE_TMPDIR}/storage.conf"
11+
readonly DOCKER_REG_ROOT="${BATS_SUITE_TMPDIR}/docker-registry-root"
1512
readonly DOCKER_REG_CERTS_DIR="${BATS_SUITE_TMPDIR}/certs"
1613
readonly DOCKER_REG_AUTH_DIR="${BATS_SUITE_TMPDIR}/auth"
1714
readonly DOCKER_REG_URI="localhost:50000"
@@ -43,23 +40,12 @@ function _setup_environment() {
4340
}
4441

4542
function _setup_containers_storage() {
46-
mkdir -p "${TEMP_STORAGE_DIR}"
4743
# Set up a storage config file for PODMAN
4844
echo -e "[storage]\n driver = \"overlay\"\n rootless_storage_path = \"${ROOTLESS_PODMAN_STORE_DIR}\"\n runroot = \"${ROOTLESS_PODMAN_RUNROOT_DIR}\"\n" > "${PODMAN_STORE_CONFIG_FILE}"
4945
export CONTAINERS_STORAGE_CONF="${PODMAN_STORE_CONFIG_FILE}"
5046
}
5147

5248

53-
function _clean_temporary_storage() {
54-
podman system reset --force >/dev/null
55-
56-
rm --force --recursive "${ROOTLESS_PODMAN_STORE_DIR}"
57-
rm --force --recursive "${ROOTLESS_PODMAN_RUNROOT_DIR}"
58-
rm --force --recursive "${PODMAN_STORE_CONFIG_FILE}"
59-
rm --force --recursive "${TEMP_STORAGE_DIR}"
60-
}
61-
62-
6349
# Pulls an image using Podman and saves it to a image dir using Skopeo
6450
#
6551
# Parameters
@@ -202,19 +188,19 @@ function _setup_docker_registry() {
202188
assert_success
203189

204190
run podman login \
205-
--authfile "${TEMP_BASE_DIR}/authfile.json" \
191+
--authfile "${BATS_SUITE_TMPDIR}/authfile.json" \
206192
--username user \
207193
--password user \
208194
"${DOCKER_REG_URI}"
209195
assert_success
210196

211197
# Add fedora-toolbox:34 image to the registry
212-
run skopeo copy --dest-authfile "${TEMP_BASE_DIR}/authfile.json" \
198+
run skopeo copy --dest-authfile "${BATS_SUITE_TMPDIR}/authfile.json" \
213199
dir:"${IMAGE_CACHE_DIR}"/fedora-toolbox-34 \
214200
docker://"${DOCKER_REG_URI}"/fedora-toolbox:34
215201
assert_success
216202

217-
run rm "${TEMP_BASE_DIR}/authfile.json"
203+
run rm "${BATS_SUITE_TMPDIR}/authfile.json"
218204
assert_success
219205
}
220206

test/system/setup_suite.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@ teardown_suite() {
8686
fi
8787

8888
_clean_cached_images
89-
_clean_temporary_storage
89+
podman system reset --force >/dev/null
9090
}

0 commit comments

Comments
 (0)