Skip to content
Merged
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
14 changes: 11 additions & 3 deletions wait-for
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

set -- "$@" -- "$TIMEOUT" "$QUIET" "$HOST" "$PORT" "$result"
TIMEOUT=15
QUIET=0

Expand Down Expand Up @@ -52,7 +53,15 @@ wait_for() {

result=$?
if [ $result -eq 0 ] ; then
if [ $# -gt 0 ] ; then
if [ $# -gt 6 ] ; then
for result in $(seq $(($# - 6))); do
result=$1
shift
set -- "$@" "$result"
done

TIMEOUT=$2 QUIET=$3 HOST=$4 PORT=$5 result=$6
shift 6
exec "$@"
fi
exit 0
Expand All @@ -69,8 +78,7 @@ wait_for() {
exit 1
}

while [ $# -gt 0 ]
do
while :; do
case "$1" in
*:* )
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
Expand Down
13 changes: 13 additions & 0 deletions wait-for.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@
[ "$status" -ne 0 ]
[ "$output" != "success" ]
}

@test "environment variables should be restored for command invocation" {
HOST=success run ./wait-for -t 1 google.com:80 -- sh -c 'echo "$HOST"'

[ "$output" = "success" ]
}

@test "unset environment variables should be restored as unset for command invocation" {
run ./wait-for -t 1 google.com:80 -- sh -uc 'echo "$HOST"'

[ "$status" -ne 0 ]
[ "$output" != "google.com" ]
}