Add unit tests for local headers and footers

pull/118/head
Adrian Perez de Castro 2020-10-24 18:35:35 +03:00 committed by Adrian Perez
parent 527511fbf8
commit f52bacea8f
4 changed files with 91 additions and 0 deletions

17
t/08-local-footer.test Normal file
View File

@ -0,0 +1,17 @@
#! /bin/bash
cat <<---
This test checks that a local footer can be included with
"fancyindex_header ... local"
--
use pup
cat > "${TESTDIR}/footer" <<EOF
<div id="customfooter">yes</div>
EOF
nginx_start 'fancyindex_footer "/footer" local;'
T=$(fetch / | pup -p body 'div#customfooter' text{})
[[ $T == yes ]] || fail 'Custom header missing'
nginx_is_running || fail 'Nginx died'

17
t/09-local-header.test Normal file
View File

@ -0,0 +1,17 @@
#! /bin/bash
cat <<---
This test checks that a local header can be included with
"fancyindex_header ... local"
--
use pup
cat > "${TESTDIR}/header" <<EOF
<div id="customheader">yes</div>
EOF
nginx_start 'fancyindex_header "/header" local;'
T=$(fetch / | pup -p body 'div#customheader' text{})
[[ $T == yes ]] || fail 'Custom header missing'
nginx_is_running || fail 'Nginx died'

View File

@ -0,0 +1,26 @@
#! /bin/bash
cat <<---
This test checks that both a local header and footer can be included with
"fancyindex_{header,footer} ... local"
--
use pup
cat > "${TESTDIR}/header" <<EOF
<div id="customheader">yes</div>
EOF
cat > "${TESTDIR}/footer" <<EOF
<div id="customfooter">yes</div>
EOF
nginx_start 'fancyindex_header "/header" local;
fancyindex_footer "/footer" local;'
P=$(fetch /)
H=$(pup -p body 'div#customheader' text{} <<< "$P")
[[ $H == yes ]] || fail 'Custom header missing'
F=$(pup -p body 'div#customfooter' text{} <<< "$P")
[[ $F == yes ]] || fail 'Custom footer missing'
nginx_is_running || fail 'Nginx died'

View File

@ -0,0 +1,31 @@
#! /bin/bash
cat <<---
This test checks that local footers are correctly included in presence of
directives in nested locations:
fancyindex_footer <one> local;
location /sub {
fancyindex_footer <another> local;
}
--
use pup
echo '<div id="topfooter">yes</div>' > "${TESTDIR}/top-footer"
echo '<div id="subfooter">yes</div>' > "${TESTDIR}/sub-footer"
nginx_start 'fancyindex_footer "/top-footer" local;
location /child-directory {
fancyindex_footer "/sub-footer" local;
}'
T=$(fetch /)
echo "$T" > "$TESTDIR/top.html"
[[ $(pup -p body 'div#topfooter' text{} <<< "$T") = yes ]] || fail 'Custom header missing at /'
[[ -z $(pup -p body 'div#subfooter' text{} <<< "$T") ]] || fail 'Wrong header at /'
T=$(fetch /child-directory/)
[[ $(pup -p body 'div#subfooter' text{} <<< "$T") = yes ]] || fail 'Custom header missing at /sub/'
[[ -z $(pup -p body 'div#topfooter' text{} <<< "$T") ]] || fail 'Wrong header at /sub/'
nginx_is_running || fail 'Nginx died'