Skip to content

Commit d017ee6

Browse files
authored
Allow running tests with podman (#197)
1 parent 305236a commit d017ee6

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

bin/run-tests-in-docker.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
# Synopsis:
6-
# Test the test runner Docker image by running it against a predefined set of
6+
# Test the test runner Docker image by running it against a predefined set of
77
# solutions with an expected output.
88
# The test runner Docker image is built automatically.
99

@@ -14,16 +14,34 @@ set -e
1414
# Example:
1515
# ./bin/run-tests-in-docker.sh
1616

17+
mnt_opt=""
18+
run_opt=""
19+
if ! command -v docker > /dev/null ; then
20+
if ! command -v podman > /dev/null ; then
21+
echo "Docker or Podman must be installed to run the tests in a container."
22+
exit 1
23+
fi
24+
# Docker is unavailable, use Podman
25+
docker() {
26+
podman "$@"
27+
}
28+
# for SELinux systems, permit container access to mounted directories
29+
mnt_opt=",Z"
30+
# use same user ID for container, avoids file ownership problems
31+
run_opt="--userns=keep-id"
32+
fi
33+
1734
# Build the Docker image
1835
docker build --rm -t exercism/rust-test-runner .
1936

2037
# Run the Docker image using the settings mimicking the production environment
2138
docker run \
2239
--rm \
2340
--network none \
24-
--mount type=bind,src="${PWD}/tests",dst=/opt/test-runner/tests \
41+
--mount type=bind,src="${PWD}/tests,dst=/opt/test-runner/tests$mnt_opt" \
2542
--mount type=tmpfs,dst=/tmp \
26-
--volume "${PWD}/bin/run-tests.sh:/opt/test-runner/bin/run-tests.sh" \
43+
--mount type=bind,src="${PWD}/bin/run-tests.sh,dst=/opt/test-runner/bin/run-tests.sh$mnt_opt" \
44+
$run_opt \
2745
--workdir /opt/test-runner \
2846
--entrypoint /opt/test-runner/bin/run-tests.sh \
2947
exercism/rust-test-runner

bin/run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ for test_dir in tests/*; do
3535
bin/run.sh "${slug}" "${test_dir_path}" "${test_dir_path}"
3636

3737
# Normalize the results file
38-
jq 'if (.tests != null) then .tests |= sort_by(.name) else . end' "${results_file_path}" > tmp && mv tmp "${results_file_path}"
38+
jq 'if (.tests != null) then .tests |= sort_by(.name) else . end' "${results_file_path}" > /tmp/res && mv /tmp/res "${results_file_path}"
3939
sed -i -e 's/warning: build failed, waiting for other jobs to finish.*//' "${results_file_path}"
4040

4141
echo "${test_dir_name}: comparing results.json to expected_results.json"

0 commit comments

Comments
 (0)