-
Notifications
You must be signed in to change notification settings - Fork 436
/
wait-for.bats
86 lines (60 loc) · 2.15 KB
/
wait-for.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bats
@test "google should be immediately found" {
run ./wait-for google.com:80 -- echo 'success'
[ "$output" = "success" ]
}
@test "nonexistent server should not start command" {
run ./wait-for -t 1 noserver:9999 -- echo 'success'
[ "$status" -ne 0 ]
[ "$output" != "success" ]
}
@test "support condensed option style" {
run ./wait-for -qt1 google.com:80 -- echo 'success'
[ "$output" = "success" ]
}
@test "timeout cannot be negative" {
run ./wait-for -t -1 google.com:80 -- echo 'success'
[ "$status" -ne 0 ]
[ "$output" != "success" ]
}
@test "timeout cannot be empty" {
run ./wait-for -t -- google.com:80 -- echo 'success'
[ "$status" -ne 0 ]
[ "$output" != "success" ]
}
@test "environment variable HOST 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 variable HOST 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" ]
}
@test "environment variable PROTOCOL should be restored for command invocation" {
PROTOCOL=success run ./wait-for -t 1 google.com:80 -- sh -c 'echo "$PROTOCOL"'
[ "$output" = "success" ]
}
@test "unset environment variables PROTOCOL should be restored as unset for command invocation" {
run ./wait-for -t 1 google.com:80 -- sh -uc 'echo "$PROTOCOL"'
[ "$status" -ne 0 ]
[ "$output" != "google.com" ]
}
@test "http://duckduckgo.com should be immediately found" {
run ./wait-for http://duckduckgo.com -- echo 'success'
[ "$output" = "success" ]
}
@test "https://duckduckgo.com should be immediately found" {
run ./wait-for https://duckduckgo.com -- echo 'success'
[ "$output" = "success" ]
}
@test "connection error in HTTP test should not start command" {
run ./wait-for -t 1 http://google.com:8080 -- echo 'success'
[ "$status" -ne 0 ]
[ "$output" != "success" ]
}
@test "not found HTTP status should not start command" {
run ./wait-for -t 1 http://google.com/ping -- echo 'success'
[ "$status" -ne 0 ]
[ "$output" != "success" ]
}