If you use a ./test/local directory, you need to create it again: $ make clean bats-build bats-fixture
43 lines
692 B
Bash
Executable file
43 lines
692 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -eu
|
|
|
|
script_name=$0
|
|
|
|
die() {
|
|
echo >&2 "$@"
|
|
exit 1
|
|
}
|
|
|
|
about() {
|
|
die "usage: ${script_name} [-q] <port_number>"
|
|
}
|
|
|
|
[[ $# -lt 1 ]] && about
|
|
|
|
QUIET=
|
|
if [[ "$1" == "-q" ]]; then
|
|
QUIET=quiet
|
|
shift
|
|
fi
|
|
|
|
[[ $# -lt 1 ]] && about
|
|
|
|
port_number=$1
|
|
|
|
# 4 seconds may seem long, but the tests must work on embedded, slow arm boxes too
|
|
for _ in $(seq 40); do
|
|
nc -z localhost "${port_number}" >/dev/null 2>&1 && exit 0
|
|
sleep .1
|
|
done
|
|
|
|
# send to &3 if open
|
|
if { true >&3; } 2>/dev/null; then
|
|
[[ -z "${QUIET}" ]] && echo "Can't connect to port ${port_number}" >&3
|
|
else
|
|
[[ -z "${QUIET}" ]] && echo "Can't connect to port ${port_number}" >&2
|
|
fi
|
|
|
|
exit 1
|
|
|