7 176179b2 2021-10-04 op gmid="./../gmid"
13 7b7def0a 2022-01-03 op config_common="prefork 1
19 ae0d3cdb 2021-12-09 op dont_check_server_alive=no
21 5df699d1 2022-08-29 op ran_no=$((ran_no + 1))
23 176179b2 2021-10-04 op current_test=$1
24 176179b2 2021-10-04 op rm -f reg.conf
27 176179b2 2021-10-04 op echo "$1 failed"
28 176179b2 2021-10-04 op failed="$failed $1"
29 5df699d1 2022-08-29 op failed_no=$((failed_no + 1))
32 176179b2 2021-10-04 op echo "$1 passed"
35 ae0d3cdb 2021-12-09 op if [ "$dont_check_server_alive" != 'no' ]; then
39 176179b2 2021-10-04 op if ! check; then
40 176179b2 2021-10-04 op echo "gmid crashed?"
41 176179b2 2021-10-04 op failed="$failed $1"
42 5df699d1 2022-08-29 op failed_no=$((failed_no + 1))
46 4a2a525d 2021-10-04 op tests_done() {
47 5df699d1 2022-08-29 op ok=$((ran_no - failed_no))
49 5df699d1 2022-08-29 op echo "tests: $ran_no / passed: $ok / failed: $failed_no"
50 4a2a525d 2021-10-04 op if [ "$failed" != "" ]; then
52 4a2a525d 2021-10-04 op echo "failed tests:$failed"
58 176179b2 2021-10-04 op # usage: gen_config <global config> <server config>
59 176179b2 2021-10-04 op # generates a configuration file reg.conf
60 176179b2 2021-10-04 op gen_config() {
61 176179b2 2021-10-04 op cat <<EOF > reg.conf
62 176179b2 2021-10-04 op $config_common
64 176179b2 2021-10-04 op server "localhost" {
65 176179b2 2021-10-04 op cert "$PWD/cert.pem"
66 176179b2 2021-10-04 op key "$PWD/key.pem"
67 176179b2 2021-10-04 op root "$PWD/testdata"
71 176179b2 2021-10-04 op if ! checkconf; then
72 176179b2 2021-10-04 op echo "failed to parse the config" >&2
78 92a9f41d 2022-01-03 op cat <<EOF >>reg.conf
79 92a9f41d 2022-01-03 op server "localhost.local" {
80 92a9f41d 2022-01-03 op cert "$PWD/cert.pem"
81 92a9f41d 2022-01-03 op key "$PWD/key.pem"
83 534afd0d 2022-10-05 op relay-to localhost port $port
89 92a9f41d 2022-01-03 op if ! checkconf; then
90 92a9f41d 2022-01-03 op echo "failed to parse the config" >&2
96 aae8f6bf 2022-09-08 op if ! $gmid -n -f reg.conf >/dev/null 2>&1; then
97 aae8f6bf 2022-09-08 op $gmid -n -f reg.conf
101 176179b2 2021-10-04 op # usage: setup_simple_test <global config> <server config>
102 176179b2 2021-10-04 op # generates a configuration file with `gen_config', validates it and
103 176179b2 2021-10-04 op # launches the daemon
104 176179b2 2021-10-04 op setup_simple_test() {
105 176179b2 2021-10-04 op gen_config "$1" "$2"
109 176179b2 2021-10-04 op # usage: get <path>
110 176179b2 2021-10-04 op # return the body of the request on stdout
112 7a4ae106 2021-12-29 op $gg -T10 $ggflags "gemini://localhost:10965/$1" || true
115 176179b2 2021-10-04 op # usage: head <path>
116 176179b2 2021-10-04 op # return the meta response line on stdout
118 7a4ae106 2021-12-29 op $gg -T10 -d header $ggflags "gemini://localhost:10965/$1" || true
121 176179b2 2021-10-04 op # usage: fetch <path>
122 176179b2 2021-10-04 op # fetches the header and the body. They're returned in $hdr and
125 176179b2 2021-10-04 op if ! hdr="$(head $1)" || ! body="$(get $1)"; then
130 176179b2 2021-10-04 op # usage: fetch_hdr <path>
131 176179b2 2021-10-04 op # fetches the header into $hdr
132 176179b2 2021-10-04 op fetch_hdr() {
133 176179b2 2021-10-04 op hdr="$(head $1)"
137 176179b2 2021-10-04 op # usage: check_reply header body
138 176179b2 2021-10-04 op # checks that $hdr and $body are equal to the given strings
139 176179b2 2021-10-04 op check_reply() {
140 176179b2 2021-10-04 op if [ "$hdr" != "$1" ]; then
141 176179b2 2021-10-04 op echo "Header mismatch" >&2
142 176179b2 2021-10-04 op echo "wants : $1" >&2
143 176179b2 2021-10-04 op echo "got : $hdr" >&2
147 176179b2 2021-10-04 op if [ "$body" != "$2" ]; then
148 176179b2 2021-10-04 op echo "Body mismatch" >&2
149 ce09569f 2021-12-29 op echo "wants : $2" >&2
150 176179b2 2021-10-04 op echo "got : $body" >&2
156 176179b2 2021-10-04 op if check; then
157 176179b2 2021-10-04 op kill -HUP "$(cat gmid.pid)"
162 aae8f6bf 2022-09-08 op $gmid -P gmid.pid -f reg.conf
164 176179b2 2021-10-04 op # give gmid time to bind the port, otherwise we end up
165 176179b2 2021-10-04 op # executing gg when gmid isn't ready yet.
170 176179b2 2021-10-04 op if [ ! -f gmid.pid ]; then
174 176179b2 2021-10-04 op pid="$(cat gmid.pid || true)"
175 5266f500 2022-01-30 op if [ "$pid" = "" ]; then
179 176179b2 2021-10-04 op # remember: we're running under ``set -e''
180 176179b2 2021-10-04 op if ps $pid >/dev/null; then
188 176179b2 2021-10-04 op wc -l | xargs
192 176179b2 2021-10-04 op pid="$(cat gmid.pid || true)"
193 176179b2 2021-10-04 op if [ "$pid" != "" ]; then
194 176179b2 2021-10-04 op kill $pid || true
200 176179b2 2021-10-04 op rm -f bigfile bigfile.sha