Tests: Smoke-test that the module is returning data

pull/55/head
Adrian Perez de Castro 2016-08-18 00:31:15 +03:00
parent 8d47b33509
commit 3789187861
No known key found for this signature in database
GPG Key ID: 91C559DBE4C9123B
5 changed files with 110 additions and 3 deletions

3
t/01-smoke-hasindex.test Normal file
View File

@ -0,0 +1,3 @@
#! /bin/bash
nginx_start
grep 'Index of' <( fetch )

View File

@ -0,0 +1,6 @@
#! /bin/bash
nginx_start
content=$(fetch --with-headers)
grep 'Index of /' <<< "${content}" # It is an index
grep '\<table\>' <<< "${content}" # It contains a table
grep '^ Content-Type:[[:space:]]*text/html' <<< "${content}"

25
t/nginx.conf Normal file
View File

@ -0,0 +1,25 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

View File

@ -6,6 +6,72 @@
# Distributed under terms of the MIT license.
#
function nginx_conf_generate () {
if ${DYNAMIC} ; then
echo 'load_module modules/ngx_http_fancyindex_module.so;'
fi
cat <<-EOF
worker_processes 1;
events { worker_connections 1024; }
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
server_name localhost;
listen 127.0.0.1:8888;
root ${TESTDIR};
error_page 500 502 503 504 /50x.html;
location = /50x.html { root html; }
location / {
index index.html;
fancyindex on;
$*
}
}
}
EOF
}
readonly NGINX_CONF="${PREFIX}/conf/nginx.conf"
readonly NGINX_PID="${PREFIX}/logs/nginx.pid"
rm -f "${NGINX_CONF}" "${NGINX_PID}"
mkdir -p "${PREFIX}/logs"
function nginx () {
"${PREFIX}/sbin/nginx" "$@"
}
function nginx_conf () {
nginx_conf_generate "$@" > "${NGINX_CONF}"
}
function nginx_is_running () {
[[ -r ${NGINX_PID} ]] && kill -0 $(< "${NGINX_PID}")
}
function nginx_stop () {
if nginx_is_running ; then nginx -s stop ; fi
rm -f "${NGINX_PID}"
}
trap nginx_stop EXIT
function nginx_start () {
if [[ $# -gt 0 || ! -r ${NGINX_CONF} ]] ; then nginx_conf "$@" ; fi
nginx_stop # Ensure that it is not running.
nginx
}
function fetch () {
local -a opts=( -q )
if [[ $1 = --with-headers ]] ; then
opts+=( -S )
shift
fi
wget "${opts[@]}" -O- "http://localhost:8888${1:-/}" 2>&1
}
function fail () {
printf "(FF) "
printf "$@"

13
t/run
View File

@ -6,10 +6,16 @@ if [[ $# -lt 1 || $# -gt 2 ]] ; then
exit 1
fi
readonly T=$(dirname "$0")
# Obtain the absolute path to the tests directory
pushd "$(dirname "$0")" &> /dev/null
readonly T=$(pwd)
popd &> /dev/null
export T
readonly prefix=$1
# Same for the nginx prefix directory
pushd "$1" &> /dev/null
readonly prefix=$(pwd)
popd &> /dev/null
dynamic=false
if [[ $# -gt 1 && $2 -eq 1 ]] ; then
@ -28,8 +34,9 @@ for t in "$T"/*.test ; do
outfile="${name}.out"
shfile="${name}.sh"
cat > "${shfile}" <<-EOF
readonly PREFIX='${prefix}'
readonly DYNAMIC=${dynamic}
readonly TESTDIR='$T'
readonly PREFIX='${prefix}'
$(< "$T/preamble")
$(< "$t")
EOF