-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.sh
executable file
·110 lines (99 loc) · 2.99 KB
/
demo.sh
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
#!/bin/bash -Eeu
readonly SH_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/sh" && pwd)"
source "${SH_DIR}/versioner_env_vars.sh"
export $(versioner_env_vars)
source "${SH_DIR}/build_images.sh"
source "${SH_DIR}/containers_down.sh"
source "${SH_DIR}/containers_up.sh"
source "${SH_DIR}/ip_address.sh"
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
api_demo()
{
build_images
containers_up api-demo
echo
demo
echo
if [ "${1:-}" == '--no-browser' ]; then
containers_down
else
open "http://${IP_ADDRESS}:80/custom-chooser/group_choose"
fi
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
demo()
{
echo API
curl_json_body_200 alive
curl_json_body_200 ready
curl_json_body_200 sha
echo
curl_200 assets/app.css 'Content-Type: text/css'
echo
curl_200 group_choose exercise
curl_params_302 group_create "$(params_display_names)"
echo
curl_200 kata_choose exercise
curl_params_302 kata_create "$(params_display_name)"
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
curl_json_body_200()
{
local -r route="${1}" # eg ready
curl \
--data '' \
--fail \
--header 'Content-type: application/json' \
--header 'Accept: application/json' \
--request GET \
--silent \
--verbose \
"http://${IP_ADDRESS}:$(port)/${route}" \
> "$(log_filename)" 2>&1
grep --quiet 200 "$(log_filename)" # eg HTTP/1.1 200 OK
local -r result=$(tail -n 1 "$(log_filename)")
echo "$(tab)GET ${route} => 200 ${result}"
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
curl_200()
{
local -r route="${1}" # eg kata_choose
local -r pattern="${2}" # eg exercise
curl \
--fail \
--request GET \
--silent \
--verbose \
"http://${IP_ADDRESS}:$(port)/${route}" \
> "$(log_filename)" 2>&1
grep --quiet 200 "$(log_filename)" # eg HTTP/1.1 200 OK
local -r result=$(grep "${pattern}" "$(log_filename)" | head -n 1)
echo "$(tab)GET ${route} => 200 ${result}"
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
curl_params_302()
{
local -r route="${1}" # eg kata_create
local -r params="${2}" # eg "display_name=Java Countdown, Round 1"
curl \
--data-urlencode "${params}" \
--fail \
--request GET \
--silent \
--verbose \
"http://${IP_ADDRESS}:$(port)/${route}" \
> "$(log_filename)" 2>&1
grep --quiet 302 "$(log_filename)" # eg HTTP/1.1 302 Moved Temporarily
local -r result=$(grep Location "$(log_filename)" | head -n 1)
echo "$(tab)GET ${route} => 302 ${result}"
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
port() { echo -n "${CYBER_DOJO_CUSTOM_CHOOSER_PORT}"; }
params_display_names() { params display_names[] "$(display_name)"; }
params_display_name() { params display_name "$(display_name)"; }
params() { echo -n "${1}=${2}"; }
display_name() { echo -n 'Java Countdown, Round 1'; }
tab() { printf '\t'; }
log_filename() { echo -n /tmp/custom-chooser.log; }
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
api_demo "$@"