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,12 +41,14 @@ 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
# POSIX-compliant string inclusion test https://stackoverflow.com/a/8811800/2063546
38
48
if [ " ${OSTYPE#* darwin* } " != " $OSTYPE " ] ; then
39
- nc -z -w 1 -G 1 " $1 " " $2 "
49
+ conditionally_output nc -z -w 1 -G 1 " $1 " " $2 "
40
50
else
41
- nc -z -w 1 " $1 " " $2 " > /dev/null 2>&1
51
+ conditionally_output nc -z -w 1 " $1 " " $2 "
42
52
fi
43
53
}
44
54
@@ -51,7 +61,7 @@ wait_for() {
51
61
if [ $result -eq 0 ] ; then break ; fi
52
62
sleep 1
53
63
done
54
- [ $result -ne 0 ] && echo " Operation timed out" >&2
64
+ [ $result -ne 0 ] && echoerr " Operation timed out"
55
65
if [ $result -eq 0 -o $LOOSE -eq 1 -a $# -gt 0 ] ; then
56
66
TIMEOUT=$OLD_TIMEOUT QUIET=$OLD_QUIET PORT=$OLD_PORT HOST=$OLD_HOST LOOSE=$OLD_LOOSE exec " $@ "
57
67
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