enhanced cmdline arguments in hio-webs.c

This commit is contained in:
2022-12-22 16:25:20 +00:00
parent 9e135dbbd7
commit b4cadfeed3
2 changed files with 107 additions and 37 deletions

View File

@ -1,8 +1,6 @@
#!/bin/sh
##srcdir=$(dirname "$0")
##srcdir="${0%/*}"
[ -z "$srcdir" ]
[ -z "$srcdir" ] && srcdir=$(dirname "$0")
. "${srcdir}/tap.inc"
test_default_index()
@ -10,10 +8,13 @@ test_default_index()
local msg="hi-webs default index.html"
local srvaddr=127.0.0.1:54321
local tmpdir="/tmp/s-001.$$"
mkdir -p "${tmpdir}"
## check if index.html is retrieved
../bin/hio-webs "${srvaddr}" "${tmpdir}" 2>/dev/null &
local jid=$!
mkdir -p "${tmpdir}"
cat >"${tmpdir}/index.html" <<EOF
<html>
<body>
@ -21,10 +22,12 @@ hello
</body>
</html>
EOF
sleep 0.5
local hc=$(curl -s -w '%{http_code}\n' -o /dev/null "http://${srvaddr}")
tap_ensure "$hc" "200" "$msg - got $hc"
## check if 404 is returned if the document root is not found
rm -rf "${tmpdir}"
local hc=$(curl -s -w '%{http_code}\n' -o /dev/null "http://${srvaddr}")
tap_ensure "$hc" "404" "$msg - got $hc"
@ -33,5 +36,29 @@ EOF
wait ${jid}
}
test_file_list_dir()
{
local msg="hi-webs file-list-dir"
local srvaddr=127.0.0.1:54321
local tmpdir="/tmp/s-001.$$"
mkdir -p "${tmpdir}"
## check directory listing against an empty directory
../bin/hio-webs --file-list-dir "${srvaddr}" "${tmpdir}" 2>/dev/null &
local jid=$!
sleep 0.5
local hc=$(curl -s -w '%{http_code}\n' -o /dev/null "http://${srvaddr}")
tap_ensure "$hc" "200" "$msg - got $hc"
rm -rf "${tmpdir}"
kill -TERM ${jid}
wait ${jid}
}
test_default_index
tap_end
test_file_list_dir
tap_end