-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.bats
249 lines (217 loc) · 5.56 KB
/
test.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/env bats
export SYSTEM_NAME="$(uname -s | tr '[:upper:]' '[:lower:]')"
export PROCFILE_BIN="build/$SYSTEM_NAME/procfile-util-amd64"
setup_file() {
make prebuild $PROCFILE_BIN
}
teardown_file() {
make clean
}
@test "[lax] comments" {
run $PROCFILE_BIN check -P fixtures/comments.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "valid procfile detected 2custom, cron, custom, release, web, wor-ker"
run $PROCFILE_BIN list -P fixtures/comments.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "2custom
cron
custom
release
web
wor-ker"
run $PROCFILE_BIN show -P fixtures/comments.Procfile -p web
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "node web.js"
}
@test "[lax] forwardslash-comments" {
run $PROCFILE_BIN check -P fixtures/forwardslash-comments.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "valid procfile detected web, worker, worker-2"
run $PROCFILE_BIN show -P fixtures/forwardslash-comments.Procfile -p worker
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "node worker.js"
run $PROCFILE_BIN list -P fixtures/forwardslash-comments.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "web
worker
worker-2"
}
@test "[lax] multiple" {
run $PROCFILE_BIN check -P fixtures/multiple.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "valid procfile detected release, web, webpacker, worker"
run $PROCFILE_BIN list -P fixtures/multiple.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "release
web
webpacker
worker"
}
@test "[lax] port" {
run $PROCFILE_BIN check -P fixtures/port.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "valid procfile detected web, worker"
run $PROCFILE_BIN show -P fixtures/port.Procfile -p web
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "node web.js --port 5000"
run $PROCFILE_BIN list -P fixtures/port.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "web
worker"
}
@test "[strict] comments" {
run $PROCFILE_BIN check -S -P fixtures/comments.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "valid procfile detected 2custom, cron, custom, release, web, wor-ker"
run $PROCFILE_BIN list -S -P fixtures/comments.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "2custom
cron
custom
release
web
wor-ker"
}
@test "[strict] forwardslash-comments" {
run $PROCFILE_BIN check -S -P fixtures/forwardslash-comments.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "valid procfile detected web, worker, worker-2"
run $PROCFILE_BIN show -S -P fixtures/forwardslash-comments.Procfile -p worker
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "node worker.js"
run $PROCFILE_BIN list -S -P fixtures/forwardslash-comments.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "web
worker
worker-2"
}
@test "[strict] multiple" {
run $PROCFILE_BIN check -S -P fixtures/multiple.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "valid procfile detected release, web, webpacker, worker"
run $PROCFILE_BIN list -S -P fixtures/multiple.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "release
web
webpacker
worker"
}
@test "[strict] port" {
run $PROCFILE_BIN check -S -P fixtures/port.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "valid procfile detected web, worker"
run $PROCFILE_BIN show -S -P fixtures/port.Procfile -p web
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "node web.js --port 5000"
run $PROCFILE_BIN list -S -P fixtures/port.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output "web
worker"
}
flunk() {
{
if [[ "$#" -eq 0 ]]; then
cat -
else
echo "$*"
fi
}
return 1
}
assert_equal() {
if [[ "$1" != "$2" ]]; then
{
echo "expected: $1"
echo "actual: $2"
} | flunk
fi
}
assert_exit_status() {
exit_status="$1"
if [[ "$status" -ne "$exit_status" ]]; then
{
echo "expected exit status: $exit_status"
echo "actual exit status: $status"
} | flunk
flunk
fi
}
assert_failure() {
if [[ "$status" -eq 0 ]]; then
flunk "expected failed exit status"
elif [[ "$#" -gt 0 ]]; then
assert_output "$1"
fi
}
assert_success() {
if [[ "$status" -ne 0 ]]; then
flunk "command failed with exit status $status"
elif [[ "$#" -gt 0 ]]; then
assert_output "$1"
fi
}
assert_output() {
local expected
if [[ $# -eq 0 ]]; then
expected="$(cat -)"
else
expected="$1"
fi
assert_equal "$expected" "$output"
}
assert_output_contains() {
local input="$output"
local expected="$1"
local count="${2:-1}"
local found=0
until [ "${input/$expected/}" = "$input" ]; do
input="${input/$expected/}"
found=$((found + 1))
done
assert_equal "$count" "$found"
}
assert_output_not_exists() {
[[ -z "$output" ]] || flunk "expected no output, found some"
}