Skip to content

preserve existing environment variable #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion wait-for
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ USAGE
}

wait_for() {
_HOST=$HOST
_PORT=$PORT
for i in `seq $TIMEOUT` ; do
nc -z "$HOST" "$PORT" > /dev/null 2>&1

result=$?
if [ $result -eq 0 ] ; then
if [ $# -gt 0 ] ; then
unset HOST
unset PORT
HOST=$_HOST
PORT=$_PORT
unset _HOST
unset _PORT
exec "$@"
fi
exit 0
Expand Down
11 changes: 10 additions & 1 deletion wait-for.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@test "google should be immediately found" {
run ./wait-for google.com:80 -- echo 'success'

[ "$output" = "success" ]
}

Expand All @@ -12,3 +12,12 @@
[ "$status" -ne 0 ]
[ "$output" != "success" ]
}

@test "preserve existing environment variable" {
HOST=myweb.com
PORT=8080
run ./wait-for google.com:80 -- echo 'success'

[ "$(echo $HOST)" = 'myweb.com' ]
[ "$(echo $PORT)" = '8080' ]
}