7 176179b2 2021-10-04 op gmid="./../gmid"
13 94893746 2023-06-12 op config_common="ipv6 off
18 ae0d3cdb 2021-12-09 op dont_check_server_alive=no
20 5df699d1 2022-08-29 op ran_no=$((ran_no + 1))
22 176179b2 2021-10-04 op current_test=$1
23 176179b2 2021-10-04 op rm -f reg.conf
26 176179b2 2021-10-04 op echo "$1 failed"
27 176179b2 2021-10-04 op failed="$failed $1"
28 5df699d1 2022-08-29 op failed_no=$((failed_no + 1))
31 176179b2 2021-10-04 op echo "$1 passed"
34 ae0d3cdb 2021-12-09 op if [ "$dont_check_server_alive" != 'no' ]; then
38 176179b2 2021-10-04 op if ! check; then
39 176179b2 2021-10-04 op echo "gmid crashed?"
40 176179b2 2021-10-04 op failed="$failed $1"
41 5df699d1 2022-08-29 op failed_no=$((failed_no + 1))
45 4a2a525d 2021-10-04 op tests_done() {
46 5df699d1 2022-08-29 op ok=$((ran_no - failed_no))
48 5df699d1 2022-08-29 op echo "tests: $ran_no / passed: $ok / failed: $failed_no"
49 4a2a525d 2021-10-04 op if [ "$failed" != "" ]; then
51 4a2a525d 2021-10-04 op echo "failed tests:$failed"
57 176179b2 2021-10-04 op # usage: gen_config <global config> <server config>
58 176179b2 2021-10-04 op # generates a configuration file reg.conf
59 176179b2 2021-10-04 op gen_config() {
60 176179b2 2021-10-04 op cat <<EOF > reg.conf
61 176179b2 2021-10-04 op $config_common
63 176179b2 2021-10-04 op server "localhost" {
64 176179b2 2021-10-04 op cert "$PWD/cert.pem"
65 176179b2 2021-10-04 op key "$PWD/key.pem"
66 176179b2 2021-10-04 op root "$PWD/testdata"
70 176179b2 2021-10-04 op if ! checkconf; then
71 176179b2 2021-10-04 op echo "failed to parse the config" >&2
77 92a9f41d 2022-01-03 op cat <<EOF >>reg.conf
78 92a9f41d 2022-01-03 op server "localhost.local" {
79 92a9f41d 2022-01-03 op cert "$PWD/cert.pem"
80 92a9f41d 2022-01-03 op key "$PWD/key.pem"
82 534afd0d 2022-10-05 op relay-to localhost port $port
88 92a9f41d 2022-01-03 op if ! checkconf; then
89 92a9f41d 2022-01-03 op echo "failed to parse the config" >&2
95 0ac785a6 2023-06-05 op if ! $gmid -n -c reg.conf >/dev/null 2>&1; then
96 0ac785a6 2023-06-05 op $gmid -n -c reg.conf
100 176179b2 2021-10-04 op # usage: setup_simple_test <global config> <server config>
101 176179b2 2021-10-04 op # generates a configuration file with `gen_config', validates it and
102 176179b2 2021-10-04 op # launches the daemon
103 176179b2 2021-10-04 op setup_simple_test() {
104 176179b2 2021-10-04 op gen_config "$1" "$2"
108 176179b2 2021-10-04 op # usage: get <path>
109 176179b2 2021-10-04 op # return the body of the request on stdout
111 7a4ae106 2021-12-29 op $gg -T10 $ggflags "gemini://localhost:10965/$1" || true
114 176179b2 2021-10-04 op # usage: head <path>
115 176179b2 2021-10-04 op # return the meta response line on stdout
117 7a4ae106 2021-12-29 op $gg -T10 -d header $ggflags "gemini://localhost:10965/$1" || true
120 176179b2 2021-10-04 op # usage: fetch <path>
121 176179b2 2021-10-04 op # fetches the header and the body. They're returned in $hdr and
124 176179b2 2021-10-04 op if ! hdr="$(head $1)" || ! body="$(get $1)"; then
129 176179b2 2021-10-04 op # usage: fetch_hdr <path>
130 176179b2 2021-10-04 op # fetches the header into $hdr
131 176179b2 2021-10-04 op fetch_hdr() {
132 176179b2 2021-10-04 op hdr="$(head $1)"
136 176179b2 2021-10-04 op # usage: check_reply header body
137 176179b2 2021-10-04 op # checks that $hdr and $body are equal to the given strings
138 176179b2 2021-10-04 op check_reply() {
139 176179b2 2021-10-04 op if [ "$hdr" != "$1" ]; then
140 176179b2 2021-10-04 op echo "Header mismatch" >&2
141 176179b2 2021-10-04 op echo "wants : $1" >&2
142 176179b2 2021-10-04 op echo "got : $hdr" >&2
146 176179b2 2021-10-04 op if [ "$body" != "$2" ]; then
147 176179b2 2021-10-04 op echo "Body mismatch" >&2
148 ce09569f 2021-12-29 op echo "wants : $2" >&2
149 176179b2 2021-10-04 op echo "got : $body" >&2
155 176179b2 2021-10-04 op if check; then
156 176179b2 2021-10-04 op kill -HUP "$(cat gmid.pid)"
161 99f1fbb0 2023-06-08 op $gmid -P $PWD/gmid.pid -c reg.conf
163 176179b2 2021-10-04 op # give gmid time to bind the port, otherwise we end up
164 176179b2 2021-10-04 op # executing gg when gmid isn't ready yet.
169 176179b2 2021-10-04 op if [ ! -f gmid.pid ]; then
173 176179b2 2021-10-04 op pid="$(cat gmid.pid || true)"
174 5266f500 2022-01-30 op if [ "$pid" = "" ]; then
178 176179b2 2021-10-04 op # remember: we're running under ``set -e''
179 176179b2 2021-10-04 op if ps $pid >/dev/null; then
187 176179b2 2021-10-04 op wc -l | xargs
191 176179b2 2021-10-04 op pid="$(cat gmid.pid || true)"
192 176179b2 2021-10-04 op if [ "$pid" != "" ]; then
193 176179b2 2021-10-04 op kill $pid || true
199 176179b2 2021-10-04 op rm -f bigfile bigfile.sha