-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-helpers.bash
77 lines (64 loc) · 1.19 KB
/
test-helpers.bash
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
http() {
echo curl
for var in "$@"
do
echo ". $var"
done
curl "$@" -D out.head >out.body 2>/dev/null
}
call() {
BACKEND_BASE_URL="${BACKEND_BASE_URL:-http://localhost:8080}"
path=$1
shift
http "$@" -H "accept: application/json" "${BACKEND_BASE_URL}${path}"
}
get() {
call "$@" -X GET
}
post() {
call "$@" -H "Content-Type: application/json" -X POST
}
put() {
call "$@" -H "Content-Type: application/json" -X PUT
}
auth() {
TOKEN=$(<user.token)
echo "Authorization: Bearer $TOKEN"
}
status_is() {
expected=$1
output=$(head -n 1 out.head | cut -d' ' -f2)
assert_output "$expected" || \
(
diag_file out.head
# diag_file out.body
false
)
}
jq_get() {
jq -r "$@" out.body
}
jq_is() {
expected=$1
shift
run jq_get "$@"
assert_output "$expected"
}
jq_ok() {
jq_is true "$@" || \
(
diag "Expected jq: $@"
diag_file out.body
false
)
}
diag() {
printf ' # %s\n' "$@" >&3
#echo " # $@" >&3
}
diag_file() {
while IFS="" read -r p || [ -n "$p" ]
do
diag "$p"
done < $1
}