@@ -11,17 +11,47 @@ set -o pipefail
11
11
run () {
12
12
_cmd=" ${1} "
13
13
14
- _red=" \033[0;31m"
15
- _green=" \033[0;32m"
16
- _yellow=" \033[0;33m"
14
+ # _red="\033[0;31m"
15
+ _gray=" \033[38;5;244m"
16
+ # _green="\033[0;32m"
17
+ # _yellow="\033[0;33m"
17
18
_reset=" \033[0m"
18
- _user=" $( whoami) "
19
+ # _user="$(whoami)"
19
20
20
- printf " ${_yellow} [%s] ${_red} %s \$ ${_green}${ _cmd}${_reset} \n" " $( hostname ) " " ${_user} "
21
+ printf " ${_gray} %s ${ _cmd}${_reset} \n" " \$ "
21
22
sh -c " LANG=C LC_ALL=C ${_cmd} "
22
23
}
23
24
24
25
26
+ log () {
27
+ local type=" ${1} "
28
+ local message=" ${2} "
29
+
30
+ local clr_gray=" \033[38;5;244m"
31
+ local clr_green=" \033[0;32m"
32
+ local clr_red=" \033[0;31m"
33
+ local clr_rst=" \033[0m"
34
+
35
+ if [ " ${type} " = " fail" ]; then
36
+ printf " ${clr_red} %s${clr_rst} \n" " --------------------------------------------------------------------------------" 1>&2
37
+ printf " ${clr_red} [FAIL] %s${clr_rst} \n" " ${message} " 1>&2
38
+ printf " ${clr_red} %s${clr_rst} \n" " --------------------------------------------------------------------------------" 1>&2
39
+ elif [ " ${type} " = " ok" ]; then
40
+ # printf "${clr_green}%s${clr_rst}\n" "--------------------------------------------------------------------------------" 1>&2
41
+ printf " ${clr_green} [SUCC] %s${clr_rst} \n" " ${message} "
42
+ # printf "${clr_green}%s${clr_rst}\n" "--------------------------------------------------------------------------------" 1>&2
43
+ elif [ " ${type} " = " loop" ]; then
44
+ printf " ${clr_gray} %s${clr_rst} \n" " --------------------------------------------------------------------------------" 1>&2
45
+ printf " ${clr_gray} [LOOP] %s${clr_rst} \n" " ${message} "
46
+ printf " ${clr_gray} %s${clr_rst} \n" " --------------------------------------------------------------------------------" 1>&2
47
+ else
48
+ printf " ${clr_red} %s${clr_rst} \n" " --------------------------------------------------------------------------------" 1>&2
49
+ printf " ${clr_red} [SYS] %s${clr_rst} \n" " Unknown log type: ${type} " 1>&1
50
+ printf " ${clr_red} %s${clr_rst} \n" " --------------------------------------------------------------------------------" 1>&2
51
+ return 1
52
+ fi
53
+ }
54
+
25
55
26
56
# ##
27
57
# ## Get 15 character random word
@@ -39,3 +69,117 @@ function get_random_name() {
39
69
done
40
70
echo " ${name} "
41
71
}
72
+
73
+ tmp_dir () {
74
+ local tmp_dir=
75
+ tmp_dir=" $( mktemp -d ) "
76
+ chmod 755 " ${tmp_dir} "
77
+ echo " ${tmp_dir} "
78
+ }
79
+
80
+
81
+ docker_logs () {
82
+ local container_name=" ${1} "
83
+ docker logs " ${container_name} " || true
84
+ }
85
+
86
+ docker_stop () {
87
+ local container_name=" ${1} "
88
+ docker stop " ${container_name} " > /dev/null 2>&1 || true
89
+ docker rm -f " ${container_name} " > /dev/null 2>&1 || true
90
+ }
91
+
92
+
93
+ # --------------------------------------------------------------------------------------------------
94
+ # TESTS
95
+ # --------------------------------------------------------------------------------------------------
96
+
97
+ # ##
98
+ # ## Application 1
99
+ # ##
100
+ create_app () {
101
+ local path=" ${1} "
102
+ local docr=" ${2} "
103
+ local name=" ${3} "
104
+ local file=" ${4} "
105
+ local cont=" ${5} "
106
+
107
+ run " mkdir -p ${path} /${name} /${docr} "
108
+ run " echo \" ${cont} \" > ${path} /${name} /${docr} /${file} "
109
+ }
110
+
111
+
112
+
113
+ # ##
114
+ # ## Find expected string in URL
115
+ # ##
116
+ test_vhost_response () {
117
+ local expect=" ${1} "
118
+ local url=" ${2} "
119
+ local header=" ${3:- } "
120
+
121
+ # local clr_gray="\033[38;5;244m"
122
+ local clr_rst=" \033[0m"
123
+ local clr_test=" \033[0;34m" # blue
124
+
125
+
126
+ printf " ${clr_test} %s${clr_rst} \n" " --------------------------------------------------------------------------------" 1>&2
127
+ printf " ${clr_test} [TEST] %s${clr_rst} \n" " Exec: curl -sS -k -L '${url} ' -H '${header} '"
128
+ printf " ${clr_test} [TEST] %s${clr_rst} " " Find: '${expect} ' "
129
+
130
+ count=0
131
+ retry=30
132
+ output=" "
133
+ while ! output=" $( sh -c " LANG=C LC_ALL=C curl --fail -sS -k -L '${url} ' -H '${header} ' 2>/dev/null | grep '^${expect} $'" ) " ; do
134
+ printf " ."
135
+ if [ " ${count} " = " ${retry} " ]; then
136
+ printf " \\ n"
137
+ sh -c " LANG=C LC_ALL=C curl -v --fail -sS -k -L '${url} ' -H '${header} '" || true
138
+ return 1
139
+ fi
140
+ count=$(( count + 1 ))
141
+ sleep 1
142
+ done
143
+
144
+ # Print success
145
+ printf " \\ n"
146
+ log " ok" " Resp: '${output} '"
147
+ echo
148
+ }
149
+
150
+
151
+ # ##
152
+ # ## Check docker logs for Errors
153
+ # ##
154
+ test_docker_logs_err () {
155
+ local container_name=" ${1} "
156
+
157
+ local re_internal=' (\[FAILURE|FAILED|FAIL|FATAL|ERROR|ERR|WARNING|WARN\])'
158
+ local re_upper=' (FAULT|FAIL|FATAL|ERR|WARN)'
159
+ local re_lower=' (segfault|fail|fatal|warn)'
160
+ local re_mixed=' ([Ss]egfault|[Ff]ail|[Ff]atal|[Ww]arn)'
161
+ local regex=" ${re_internal} |${re_upper} |${re_lower} |${re_mixed} "
162
+
163
+ # Ignore this pattern
164
+ local ignore1=' creating Certificate Authority'
165
+ local ignore2=' error_log' # nginx error log directive
166
+ local ignore3=' stackoverflow' # contains a link comment with 'error' in url
167
+ local ignore=" ${ignore1} |${ignore2} |${ignore3} "
168
+
169
+ # local clr_gray="\033[38;5;244m"
170
+ local clr_test=" \033[0;34m" # blue
171
+ local clr_rst=" \033[0m"
172
+
173
+ printf " ${clr_test} %s${clr_rst} \n" " --------------------------------------------------------------------------------" 1>&2
174
+ printf " ${clr_test} [TEST] %s${clr_rst} \n" " Exec: docker logs ${container_name} "
175
+ printf " ${clr_test} [TEST] %s${clr_rst} \n" " Find: '${regex} '"
176
+
177
+ if docker logs " ${container_name} " 2>&1 | grep -Ev " ${ignore} " | grep -E " ${regex} " > /dev/null; then
178
+ log " fail" " Found: $( docker logs " ${container_name} " 2>&1 | grep -Ev " ${ignore} " | grep -E " ${regex} " ) "
179
+ return 1
180
+ fi
181
+
182
+ # Print success
183
+ log " ok" " Resp: Nothing found in docker logs"
184
+ echo
185
+ }
0 commit comments