Add test for --mimetypes

This commit is contained in:
Emil Mikulic 2013-06-10 20:41:46 +10:00
parent e6680c4f2f
commit 7dc06f3096
2 changed files with 64 additions and 6 deletions

View File

@ -11,25 +11,27 @@ if [ ! -e test.py ]; then
exit 1
fi
if [ \( ! -x a.out \) -o \( ../darkhttpd.c -nt a.out \) ]; then
echo "===> building a.out, darkhttpd.gcno"
gcc -g -fprofile-arcs -ftest-coverage ../darkhttpd.c || exit 1
# generates a.out, darkhttpd.gcno
fi
if [ -e $DIR ]; then
rm -rf $DIR || exit 1
fi
mkdir $DIR || exit 1
rm -f darkhttpd.gcda darkhttpd.log
# display usage statement
echo "===> run usage statement"
./a.out >/dev/null
# run tests against a basic instance (generates darkhttpd.gcda)
echo "===> run tests against a basic instance (generates darkhttpd.gcda)"
./a.out $DIR --port $PORT --log darkhttpd.log >/dev/null &
PID=$!
kill -0 $PID || exit 1
python test.py
kill $PID
wait $PID
# run forward tests
echo "===> run forwarding tests"
./a.out $DIR --port $PORT \
--forward example.com http://www.example.com \
--forward secure.example.com https://www.example.com/secure >/dev/null &
@ -37,15 +39,30 @@ PID=$!
kill -0 $PID || exit 1
python test_forward.py
kill $PID
wait $PID
# run no-server-id tests
echo "===> run no-server-id tests"
./a.out $DIR --port $PORT --no-server-id >/dev/null &
PID=$!
kill -0 $PID || exit 1
python test_server_id.py
kill $PID
wait $PID
echo generating darkhttpd.c.gcov report
echo "===> run mimemap tests"
echo "test/type1 a1" > $DIR/mimemap
echo "test/this-gets-replaced ap2" >> $DIR/mimemap
echo "# this is a comment" >> $DIR/mimemap
printf "test/type3\\tapp3\n" >> $DIR/mimemap
echo "test/type2 ap2" >> $DIR/mimemap
./a.out $DIR --port $PORT --mimetypes $DIR/mimemap >/dev/null &
PID=$!
kill -0 $PID || exit 1
python test_mimemap.py
kill $PID
wait $PID
echo "===> generating darkhttpd.c.gcov report"
gcov darkhttpd
rm -rf $DIR
rm -f darkhttpd.gcda darkhttpd.gcno darkhttpd.log a.out

41
devel/test_mimemap.py Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
# This is run by the "cover" script.
import unittest
import os
from test import WWWROOT, TestHelper, Conn, parse
class TestMimemap(TestHelper):
def setUp(self):
self.data = "hello\n"
self.datalen = len(self.data)
self.files = [ ("test-file.a1", "test/type1"),
("test-file.ap2", "test/type2"),
("test-file.app3", "test/type3"),
("test-file.appp4", "application/octet-stream") ]
for fn, _ in self.files:
open(WWWROOT + "/" + fn, "w").write(self.data)
def tearDown(self):
for fn, _ in self.files:
os.unlink(WWWROOT + "/" + fn)
def get_helper(self, idx):
fn, content_type = self.files[idx]
resp = Conn().get("/" + fn)
status, hdrs, body = parse(resp)
self.assertContains(status, "200 OK")
self.assertEquals(hdrs["Accept-Ranges"], "bytes")
self.assertEquals(hdrs["Content-Length"], str(self.datalen))
self.assertEquals(hdrs["Content-Type"], content_type)
self.assertContains(hdrs["Server"], "darkhttpd/")
self.assertEquals(body, self.data)
def test_get_1(self): self.get_helper(0)
def test_get_2(self): self.get_helper(1)
def test_get_3(self): self.get_helper(2)
def test_get_4(self): self.get_helper(3)
if __name__ == '__main__':
unittest.main()
# vim:set ts=4 sw=4 et: