4 176179b2 2021-10-04 op gmid="./../gmid"
10 176179b2 2021-10-04 op config_common="
18 176179b2 2021-10-04 op current_test=$1
19 176179b2 2021-10-04 op rm -f reg.conf
22 176179b2 2021-10-04 op echo "$1 failed"
23 176179b2 2021-10-04 op failed="$failed $1"
25 176179b2 2021-10-04 op echo "$1 passed"
28 176179b2 2021-10-04 op if [ "$dont_check" != 'no' ]; then
32 176179b2 2021-10-04 op if ! check; then
33 176179b2 2021-10-04 op echo "gmid crashed?"
34 176179b2 2021-10-04 op failed="$failed $1"
38 176179b2 2021-10-04 op # usage: gen_config <global config> <server config>
39 176179b2 2021-10-04 op # generates a configuration file reg.conf
40 176179b2 2021-10-04 op gen_config() {
41 176179b2 2021-10-04 op cat <<EOF > reg.conf
42 176179b2 2021-10-04 op $config_common
44 176179b2 2021-10-04 op server "localhost" {
45 176179b2 2021-10-04 op cert "$PWD/cert.pem"
46 176179b2 2021-10-04 op key "$PWD/key.pem"
47 176179b2 2021-10-04 op root "$PWD/testdata"
51 176179b2 2021-10-04 op if ! checkconf; then
52 176179b2 2021-10-04 op echo "failed to parse the config" >&2
58 176179b2 2021-10-04 op $gmid -n -c reg.conf >/dev/null
61 176179b2 2021-10-04 op # usage: setup_simple_test <global config> <server config>
62 176179b2 2021-10-04 op # generates a configuration file with `gen_config', validates it and
63 176179b2 2021-10-04 op # launches the daemon
64 176179b2 2021-10-04 op setup_simple_test() {
65 176179b2 2021-10-04 op gen_config "$1" "$2"
69 176179b2 2021-10-04 op # usage: get <path>
70 176179b2 2021-10-04 op # return the body of the request on stdout
72 176179b2 2021-10-04 op $gg -T30 -b $ggflags "gemini://localhost:10965/$1"
75 176179b2 2021-10-04 op # usage: head <path>
76 176179b2 2021-10-04 op # return the meta response line on stdout
78 176179b2 2021-10-04 op $gg -T30 -h $ggflags "gemini://localhost:10965/$1"
81 176179b2 2021-10-04 op # usage: raw <path>
82 176179b2 2021-10-04 op # return both header and body
84 176179b2 2021-10-04 op $gg -T30 $ggflags "gemini://localhost:10965/$1"
87 176179b2 2021-10-04 op # usage: fetch <path>
88 176179b2 2021-10-04 op # fetches the header and the body. They're returned in $hdr and
91 176179b2 2021-10-04 op if ! hdr="$(head $1)" || ! body="$(get $1)"; then
96 176179b2 2021-10-04 op # usage: fetch_hdr <path>
97 176179b2 2021-10-04 op # fetches the header into $hdr
99 176179b2 2021-10-04 op hdr="$(head $1)"
103 176179b2 2021-10-04 op # usage: check_reply header body
104 176179b2 2021-10-04 op # checks that $hdr and $body are equal to the given strings
105 176179b2 2021-10-04 op check_reply() {
106 176179b2 2021-10-04 op if [ "$hdr" != "$1" ]; then
107 176179b2 2021-10-04 op echo "Header mismatch" >&2
108 176179b2 2021-10-04 op echo "wants : $1" >&2
109 176179b2 2021-10-04 op echo "got : $hdr" >&2
113 176179b2 2021-10-04 op if [ "$body" != "$2" ]; then
114 176179b2 2021-10-04 op echo "Body mismatch" >&2
115 176179b2 2021-10-04 op echo "wants : $1" >&2
116 176179b2 2021-10-04 op echo "got : $body" >&2
122 176179b2 2021-10-04 op if check; then
123 176179b2 2021-10-04 op kill -HUP "$(cat gmid.pid)"
128 176179b2 2021-10-04 op $gmid -P gmid.pid -c reg.conf
130 176179b2 2021-10-04 op # give gmid time to bind the port, otherwise we end up
131 176179b2 2021-10-04 op # executing gg when gmid isn't ready yet.
136 176179b2 2021-10-04 op if [ ! -f gmid.pid ]; then
140 176179b2 2021-10-04 op pid="$(cat gmid.pid || true)"
141 176179b2 2021-10-04 op if [ "$pid" == "" ]; then
145 176179b2 2021-10-04 op # remember: we're running under ``set -e''
146 176179b2 2021-10-04 op if ps $pid >/dev/null; then
153 176179b2 2021-10-04 op # usage: sha in out
154 176179b2 2021-10-04 op # writes the sha256 of `in' to `out'
156 176179b2 2021-10-04 op if which sha256 >/dev/null 2>&1; then
157 176179b2 2021-10-04 op sha256 < "$1" > "$2"
161 176179b2 2021-10-04 op if which sha256sum >/dev/null 2>&1; then
162 176179b2 2021-10-04 op sha256sum "$1" | awk '{print $1}' > "$2"
166 176179b2 2021-10-04 op echo "No sha binary found" >&2
171 176179b2 2021-10-04 op wc -l | xargs
175 176179b2 2021-10-04 op pid="$(cat gmid.pid || true)"
176 176179b2 2021-10-04 op if [ "$pid" != "" ]; then
177 176179b2 2021-10-04 op kill $pid || true
183 176179b2 2021-10-04 op rm -f bigfile bigfile.sha