Skip to content

Commit

Permalink
fix: error messages for missing dependencies, allow test suite to run…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
4141done authored Aug 8, 2023
1 parent d6039f3 commit 7e35275
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ additional modules.

## Testing

Automated tests require `docker`, `docker-compose`, `curl`, and `mc` (the minio [cli tool](https://github.com/penpyt/asdf-mc)) to be
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
installed. To run all unit tests and integration tests, run the following command.
If you invoke the test script with a plus parameter, you will need to add your
NGINX repository keys to the `plus/etc/ssl/nginx` directory
Expand Down
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ e "${startup_message}"

set -o nounset # abort on unbound variable

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

curl_cmd="$(command -v curl)"
curl_cmd="$(command -v curl || true)"
if ! [ -x "${curl_cmd}" ]; then
e "required dependency not found: curl not found in the path or not executable"
exit ${no_dep_exit_code}
Expand Down
17 changes: 14 additions & 3 deletions test/integration/test_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,29 @@ if [ -z "${test_dir}" ]; then
e "missing second parameter: path to test data directory"
fi

curl_cmd="$(command -v curl)"
curl_cmd="$(command -v curl || true)"
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

checksum_cmd="$(command -v md5sum)"
if ! [ -x "${curl_cmd}" ]; then
# Allow for MacOS which does not support "md5sum"
# but has "md5 -r" which can be substituted
checksum_cmd="$(command -v md5sum || command -v md5 || true)"

if ! [ -x "${checksum_cmd}" ]; then
e "required dependency not found: md5sum not found in the path or not executable"
exit ${no_dep_exit_code}
fi

# If we are using the `md5` executable
# then use the -r flag which makes it behave the same as `md5sum`
# this is done after the `-x` check for ability to execute
# since it will not pass with the flag
if [[ $checksum_cmd =~ \/md5$ ]]; then
checksum_cmd="${checksum_cmd} -r"
fi

assertHttpRequestEquals() {
method="$1"
path="$2"
Expand Down

0 comments on commit 7e35275

Please sign in to comment.