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 4a2a525d 2021-10-04 op tests_done() {
39 4a2a525d 2021-10-04 op if [ "$failed" != "" ]; then
41 4a2a525d 2021-10-04 op echo "failed tests:$failed"
47 176179b2 2021-10-04 op # usage: gen_config <global config> <server config>
48 176179b2 2021-10-04 op # generates a configuration file reg.conf
49 176179b2 2021-10-04 op gen_config() {
50 176179b2 2021-10-04 op cat <<EOF > reg.conf
51 176179b2 2021-10-04 op $config_common
53 176179b2 2021-10-04 op server "localhost" {
54 176179b2 2021-10-04 op cert "$PWD/cert.pem"
55 176179b2 2021-10-04 op key "$PWD/key.pem"
56 176179b2 2021-10-04 op root "$PWD/testdata"
60 176179b2 2021-10-04 op if ! checkconf; then
61 176179b2 2021-10-04 op echo "failed to parse the config" >&2
67 176179b2 2021-10-04 op $gmid -n -c reg.conf >/dev/null
70 176179b2 2021-10-04 op # usage: setup_simple_test <global config> <server config>
71 176179b2 2021-10-04 op # generates a configuration file with `gen_config', validates it and
72 176179b2 2021-10-04 op # launches the daemon
73 176179b2 2021-10-04 op setup_simple_test() {
74 176179b2 2021-10-04 op gen_config "$1" "$2"
78 176179b2 2021-10-04 op # usage: get <path>
79 176179b2 2021-10-04 op # return the body of the request on stdout
81 176179b2 2021-10-04 op $gg -T30 -b $ggflags "gemini://localhost:10965/$1"
84 176179b2 2021-10-04 op # usage: head <path>
85 176179b2 2021-10-04 op # return the meta response line on stdout
87 176179b2 2021-10-04 op $gg -T30 -h $ggflags "gemini://localhost:10965/$1"
90 176179b2 2021-10-04 op # usage: raw <path>
91 176179b2 2021-10-04 op # return both header and body
93 176179b2 2021-10-04 op $gg -T30 $ggflags "gemini://localhost:10965/$1"
96 176179b2 2021-10-04 op # usage: fetch <path>
97 176179b2 2021-10-04 op # fetches the header and the body. They're returned in $hdr and
100 176179b2 2021-10-04 op if ! hdr="$(head $1)" || ! body="$(get $1)"; then
105 176179b2 2021-10-04 op # usage: fetch_hdr <path>
106 176179b2 2021-10-04 op # fetches the header into $hdr
107 176179b2 2021-10-04 op fetch_hdr() {
108 176179b2 2021-10-04 op hdr="$(head $1)"
112 176179b2 2021-10-04 op # usage: check_reply header body
113 176179b2 2021-10-04 op # checks that $hdr and $body are equal to the given strings
114 176179b2 2021-10-04 op check_reply() {
115 176179b2 2021-10-04 op if [ "$hdr" != "$1" ]; then
116 176179b2 2021-10-04 op echo "Header mismatch" >&2
117 176179b2 2021-10-04 op echo "wants : $1" >&2
118 176179b2 2021-10-04 op echo "got : $hdr" >&2
122 176179b2 2021-10-04 op if [ "$body" != "$2" ]; then
123 176179b2 2021-10-04 op echo "Body mismatch" >&2
124 176179b2 2021-10-04 op echo "wants : $1" >&2
125 176179b2 2021-10-04 op echo "got : $body" >&2
131 176179b2 2021-10-04 op if check; then
132 176179b2 2021-10-04 op kill -HUP "$(cat gmid.pid)"
137 176179b2 2021-10-04 op $gmid -P gmid.pid -c reg.conf
139 176179b2 2021-10-04 op # give gmid time to bind the port, otherwise we end up
140 176179b2 2021-10-04 op # executing gg when gmid isn't ready yet.
145 176179b2 2021-10-04 op if [ ! -f gmid.pid ]; then
149 176179b2 2021-10-04 op pid="$(cat gmid.pid || true)"
150 176179b2 2021-10-04 op if [ "$pid" == "" ]; then
154 176179b2 2021-10-04 op # remember: we're running under ``set -e''
155 176179b2 2021-10-04 op if ps $pid >/dev/null; then
162 176179b2 2021-10-04 op # usage: sha in out
163 176179b2 2021-10-04 op # writes the sha256 of `in' to `out'
165 176179b2 2021-10-04 op if which sha256 >/dev/null 2>&1; then
166 176179b2 2021-10-04 op sha256 < "$1" > "$2"
170 176179b2 2021-10-04 op if which sha256sum >/dev/null 2>&1; then
171 176179b2 2021-10-04 op sha256sum "$1" | awk '{print $1}' > "$2"
175 176179b2 2021-10-04 op echo "No sha binary found" >&2
180 176179b2 2021-10-04 op wc -l | xargs
184 176179b2 2021-10-04 op pid="$(cat gmid.pid || true)"
185 176179b2 2021-10-04 op if [ "$pid" != "" ]; then
186 176179b2 2021-10-04 op kill $pid || true
192 176179b2 2021-10-04 op rm -f bigfile bigfile.sha