Skip to content

Commit 4f6cff8

Browse files
committed
preserve existing environment variable
1 parent a93091b commit 4f6cff8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

wait-for

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ USAGE
2020
}
2121

2222
wait_for() {
23+
_HOST=$HOST
24+
_PORT=$PORT
2325
for i in `seq $TIMEOUT` ; do
2426
nc -z "$HOST" "$PORT" > /dev/null 2>&1
25-
27+
2628
result=$?
2729
if [ $result -eq 0 ] ; then
2830
if [ $# -gt 0 ] ; then
31+
unset HOST
32+
unset PORT
33+
HOST=$_HOST
34+
PORT=$_PORT
35+
unset _HOST
36+
unset _PORT
2937
exec "$@"
3038
fi
3139
exit 0

wait-for.bats

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
@test "google should be immediately found" {
44
run ./wait-for google.com:80 -- echo 'success'
5-
5+
66
[ "$output" = "success" ]
77
}
88

@@ -12,3 +12,12 @@
1212
[ "$status" -ne 0 ]
1313
[ "$output" != "success" ]
1414
}
15+
16+
@test "preserve existing environment variable" {
17+
HOST=myweb.com
18+
PORT=8080
19+
run ./wait-for google.com:80 -- echo 'success'
20+
21+
[ "$(echo $HOST)" = 'myweb.com' ]
22+
[ "$(echo $PORT)" = '8080' ]
23+
}

0 commit comments

Comments
 (0)