Skip to content

Commit 7e35275

Browse files
authored
fix: error messages for missing dependencies, allow test suite to run on MacOS by supporting md5 (#162)
# What Fix error messages for missing dependencies, allow test suite to run on MacOS by supporting `md5` ## Dependency Checks There were some checks like this: ```bash curl_cmd="$(command -v curl)" if ! [ -x "${curl_cmd}" ]; then e "required dependency not found: curl not found in the path or not executable" exit ${no_dep_exit_code} fi ``` However, `command -v` exits with an error if the command does not exist. This results in the nice error message not being shown. The solution is to avoid the assignment of the variable erroring and instead relying on the executability check to make sure we have the right thing ## `md5` compatibility The test script depends on `md5sum` which is not available on MacOS. Thus, tests would fail at the start when run on MacOS. MacOS has a tool called `md5`, which when called with the `-r` flag which reverses the format of the output.
1 parent d6039f3 commit 7e35275

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

docs/development.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ additional modules.
5555

5656
## Testing
5757

58-
Automated tests require `docker`, `docker-compose`, `curl`, and `mc` (the minio [cli tool](https://github.com/penpyt/asdf-mc)) to be
58+
Automated tests require `docker`, `docker-compose`, `curl`, `md5sum` (or `md5` on MacOS), and `mc` (the minio [cli tool](https://github.com/penpyt/asdf-mc)) to be
5959
installed. To run all unit tests and integration tests, run the following command.
6060
If you invoke the test script with a plus parameter, you will need to add your
6161
NGINX repository keys to the `plus/etc/ssl/nginx` directory

test.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ e "${startup_message}"
131131

132132
set -o nounset # abort on unbound variable
133133

134-
docker_cmd="$(command -v docker)"
134+
docker_cmd="$(command -v docker || true)"
135135
if ! [ -x "${docker_cmd}" ]; then
136136
e "required dependency not found: docker not found in the path or not executable"
137137
exit ${no_dep_exit_code}
@@ -147,7 +147,7 @@ else
147147
fi
148148
e "Using Docker Compose command: ${docker_compose_cmd}"
149149

150-
curl_cmd="$(command -v curl)"
150+
curl_cmd="$(command -v curl || true)"
151151
if ! [ -x "${curl_cmd}" ]; then
152152
e "required dependency not found: curl not found in the path or not executable"
153153
exit ${no_dep_exit_code}

test/integration/test_api.sh

+14-3
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,29 @@ if [ -z "${test_dir}" ]; then
5858
e "missing second parameter: path to test data directory"
5959
fi
6060

61-
curl_cmd="$(command -v curl)"
61+
curl_cmd="$(command -v curl || true)"
6262
if ! [ -x "${curl_cmd}" ]; then
6363
e "required dependency not found: curl not found in the path or not executable"
6464
exit ${no_dep_exit_code}
6565
fi
6666

67-
checksum_cmd="$(command -v md5sum)"
68-
if ! [ -x "${curl_cmd}" ]; then
67+
# Allow for MacOS which does not support "md5sum"
68+
# but has "md5 -r" which can be substituted
69+
checksum_cmd="$(command -v md5sum || command -v md5 || true)"
70+
71+
if ! [ -x "${checksum_cmd}" ]; then
6972
e "required dependency not found: md5sum not found in the path or not executable"
7073
exit ${no_dep_exit_code}
7174
fi
7275

76+
# If we are using the `md5` executable
77+
# then use the -r flag which makes it behave the same as `md5sum`
78+
# this is done after the `-x` check for ability to execute
79+
# since it will not pass with the flag
80+
if [[ $checksum_cmd =~ \/md5$ ]]; then
81+
checksum_cmd="${checksum_cmd} -r"
82+
fi
83+
7384
assertHttpRequestEquals() {
7485
method="$1"
7586
path="$2"

0 commit comments

Comments
 (0)