Tests: Use netstat to list occupied ports on macOS

Use netstat instead of ss to list the occupied ports on macOS since
macOS doesn't have ss.

Closes #139
pull/143/head
Ryan Schmidt 2022-05-09 14:31:03 -05:00 committed by Adrian Perez
parent 5930c29d6a
commit 20ba8038ac
1 changed files with 10 additions and 2 deletions

View File

@ -37,8 +37,16 @@ function nginx_conf_generate () {
readonly NGINX_CONF="${PREFIX}/conf/nginx.conf"
readonly NGINX_PID="${PREFIX}/logs/nginx.pid"
NGINX_PORT=$(ss -4Htnl | awk '{ sub("[^:]+:", "", $4) ; seen[$4]=1 }
END { p=1025 ; while (seen[p]) p++; print p}')
case $(uname -s) in
Darwin)
NGINX_PORT=$(netstat -a -n -finet -ptcp | awk '/LISTEN/ { sub(".+\\.", "", $4) ; seen[$4]=1 }
END { p=1025 ; while (seen[p]) p++; print p}')
;;
*)
NGINX_PORT=$(ss -4Htnl | awk '{ sub("[^:]+:", "", $4) ; seen[$4]=1 }
END { p=1025 ; while (seen[p]) p++; print p}')
;;
esac
readonly NGINX_PORT
rm -f "${NGINX_CONF}" "${NGINX_PID}"