File tree 2 files changed +17
-8
lines changed
2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,14 @@ echoerr() {
19
19
if [ " $QUIET " -ne 1 ]; then printf " %s\n" " $* " 1>&2 ; fi
20
20
}
21
21
22
+ conditionally_output () {
23
+ if [ " $QUIET " -ne 1 ]; then
24
+ " $@ "
25
+ else
26
+ " $@ " > /dev/null 2>&1
27
+ fi
28
+ }
29
+
22
30
usage () {
23
31
exitcode=" $1 "
24
32
cat << USAGE >&2
@@ -33,11 +41,13 @@ USAGE
33
41
}
34
42
35
43
test_connection () {
44
+ conditionally_output echo " Testing connection to $1 :$2 ..."
45
+
36
46
# force a 1-second timeout on darwin (https://stackoverflow.com/a/20460402/2063546)
37
47
if [ -z " ${OSTYPE##* darwin* } " ] ; then
38
- nc -z -w 1 -G 1 " $1 " " $2 " > /dev/null 2>&1
48
+ conditionally_output nc -z -w 1 -G 1 " $1 " " $2 "
39
49
else
40
- nc -z -w 1 " $1 " " $2 " > /dev/null 2>&1
50
+ conditionally_output nc -z -w 1 " $1 " " $2 "
41
51
fi
42
52
}
43
53
@@ -50,7 +60,7 @@ wait_for() {
50
60
if [ $result -eq 0 ] ; then break ; fi
51
61
sleep 1
52
62
done
53
- [ $result -ne 0 ] && echo " Operation timed out" >&2
63
+ [ $result -ne 0 ] && echoerr " Operation timed out"
54
64
if [ $result -eq 0 -o $LOOSE -eq 1 -a $# -gt 0 ] ; then
55
65
TIMEOUT=$OLD_TIMEOUT QUIET=$OLD_QUIET PORT=$OLD_PORT HOST=$OLD_HOST LOOSE=$OLD_LOOSE exec " $@ "
56
66
fi
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bats
2
2
3
- @test " google should be immediately found" {
4
- run ./wait-for google.com:80 -- echo ' success'
3
+ @test " google should be immediately found, no output other than our own " {
4
+ run ./wait-for -q google.com:80 -- echo ' success'
5
5
6
6
[ " $output " = " success" ]
7
7
}
14
14
}
15
15
16
16
@test " nonexistent server should start command if loose option is specified" {
17
- run ./wait-for -t 1 -l noserver:9999 -- echo ' passable' 2>&1
17
+ run ./wait-for -q - t 1 -l noserver:9999 -- echo ' passable' 2>&1
18
18
19
19
[ " $status " -eq 0 ]
20
20
21
- [ " ${lines[0]} " = " Operation timed out" ]
22
- [ " ${lines[1]} " = " passable" ]
21
+ [ " $output " = " passable" ]
23
22
}
24
23
25
24
@test " preserve existing environment variables" {
You can’t perform that action at this time.
0 commit comments