-
Notifications
You must be signed in to change notification settings - Fork 40
/
tests.bats
131 lines (116 loc) · 3.47 KB
/
tests.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bats
#
# To skip a test, just uncomment the # skip line
@test "-? switch" {
# skip
run ./ttfb -?
[[ "$output" =~ "Usage: " ]]
}
@test "Invalid switch" {
# skip
run ./ttfb -Z
[ $status -ne 0 ]
[[ "$output" =~ "Usage: " ]]
}
@test "-d logs requests to ./curl.log" {
# skip
rundir="$(mktemp -d)"
pwd="$PWD"
cd "$rundir" && run "$pwd/ttfb" -d example.com
[ $status -eq 0 ]
[ -f "$rundir/curl.log" ]
}
@test "-l logs to specific file" {
# skip
rundir="$(mktemp -d)"
logdir="$(mktemp -d)"
pwd="$PWD"
cd "$rundir" && run "$pwd/ttfb" -l "$logdir/log.log" example.com
[ $status -eq 0 ]
[ -f "$logdir/log.log" ]
}
@test "-l exits if the path the custom log file doesn't exist" {
# skip
rundir="$(mktemp -d)"
logdir="$(mktemp -d)"
rmdir "$logdir"
pwd="$PWD"
cd "$rundir" && run "$pwd/ttfb" -l "$logdir/log.log" example.com
[ $status -eq 1 ]
}
@test "-n expects an argument" {
# skip
run ./ttfb -n example.com
[ $status -ne 0 ]
[[ "$output" =~ "Usage: " ]]
}
@test "-n runs test multiple times" {
# skip
run ./ttfb -n 3 example.com
[ $status -eq 0 ]
[[ "$output" =~ "..." ]]
[[ "$output" =~ "fastest" ]]
}
@test "can test multiple urls" {
# skip
run ./ttfb example.com example.com/hello-world
[ $status -eq 0 ]
[[ "$output" =~ "example.com" ]]
[[ "$output" =~ "example.com/hello-world" ]]
}
@test "can test multiple urls multiple times" {
# skip
run ./ttfb -n 3 example.com example.com/hello-world
[ $status -eq 0 ]
[[ "$output" =~ "..." ]]
[[ "$output" =~ "example.com" ]]
[[ "$output" =~ "example.com/hello-world" ]]
}
@test "-d logs requests to multiple urls to multiple log files" {
# skip
rundir="$(mktemp -d)"
pwd="$PWD"
cd "$rundir" && run "$pwd/ttfb" -d example.com example.com/hello-world
[ $status -eq 0 ]
[ -f "$rundir/example_com-curl.log" ]
[ -f "$rundir/example_com_hello_world-curl.log" ]
}
@test "-l logs requests to multiple urls to multiple custom log files" {
# skip
rundir="$(mktemp -d)"
pwd="$PWD"
cd "$rundir" && run "$pwd/ttfb" -l "$rundir/custom.log" example.com example.com/hello-world
[ $status -eq 0 ]
[ -f "$rundir/example_com-custom.log" ]
[ -f "$rundir/example_com_hello_world-custom.log" ]
}
@test "-d logs multiple requests to multiple urls to multiple log files" {
# skip
rundir="$(mktemp -d)"
pwd="$PWD"
cd "$rundir" && run "$pwd/ttfb" -n2 -d example.com example.com/hello-world
[ $status -eq 0 ]
[ -f "$rundir/example_com-curl.log" ]
[ -f "$rundir/example_com_hello_world-curl.log" ]
[ $(grep " 200 OK" "$rundir/example_com-curl.log" | wc -l) -eq 2 ]
[ $(grep " 404 Not Found" "$rundir/example_com_hello_world-curl.log" | wc -l) -eq 2 ]
}
@test "-d logs multiple requests to multiple urls to multiple custom log files" {
# skip
rundir="$(mktemp -d)"
pwd="$PWD"
cd "$rundir" && run "$pwd/ttfb" -n2 -l "$rundir/custom.log" example.com example.com/hello-world
[ $status -eq 0 ]
[ -f "$rundir/example_com-custom.log" ]
[ -f "$rundir/example_com_hello_world-custom.log" ]
[ $(grep " 200 OK" "$rundir/example_com-custom.log" | wc -l) -eq 2 ]
[ $(grep " 404 Not Found" "$rundir/example_com_hello_world-custom.log" | wc -l) -eq 2 ]
}
@test "pass custom curl options via our -o option" {
# This test passes -k to curl, so it can successfully
# call https://self-signed.badssl.com which has a self-signed certificate
# which would normally result in a fail
# skip
run "$pwd/ttfb" -o "-k" https://self-signed.badssl.com
[[ "$output" != "0" ]]
}