mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
Add test for --mimetypes
This commit is contained in:
29
devel/cover
29
devel/cover
@@ -11,25 +11,27 @@ if [ ! -e test.py ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ \( ! -x a.out \) -o \( ../darkhttpd.c -nt a.out \) ]; then
|
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
|
gcc -g -fprofile-arcs -ftest-coverage ../darkhttpd.c || exit 1
|
||||||
# generates a.out, darkhttpd.gcno
|
|
||||||
fi
|
fi
|
||||||
if [ -e $DIR ]; then
|
if [ -e $DIR ]; then
|
||||||
rm -rf $DIR || exit 1
|
rm -rf $DIR || exit 1
|
||||||
fi
|
fi
|
||||||
mkdir $DIR || exit 1
|
mkdir $DIR || exit 1
|
||||||
rm -f darkhttpd.gcda darkhttpd.log
|
rm -f darkhttpd.gcda darkhttpd.log
|
||||||
# display usage statement
|
|
||||||
|
echo "===> run usage statement"
|
||||||
./a.out >/dev/null
|
./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 &
|
./a.out $DIR --port $PORT --log darkhttpd.log >/dev/null &
|
||||||
PID=$!
|
PID=$!
|
||||||
kill -0 $PID || exit 1
|
kill -0 $PID || exit 1
|
||||||
python test.py
|
python test.py
|
||||||
kill $PID
|
kill $PID
|
||||||
|
wait $PID
|
||||||
|
|
||||||
# run forward tests
|
echo "===> run forwarding tests"
|
||||||
./a.out $DIR --port $PORT \
|
./a.out $DIR --port $PORT \
|
||||||
--forward example.com http://www.example.com \
|
--forward example.com http://www.example.com \
|
||||||
--forward secure.example.com https://www.example.com/secure >/dev/null &
|
--forward secure.example.com https://www.example.com/secure >/dev/null &
|
||||||
@@ -37,15 +39,30 @@ PID=$!
|
|||||||
kill -0 $PID || exit 1
|
kill -0 $PID || exit 1
|
||||||
python test_forward.py
|
python test_forward.py
|
||||||
kill $PID
|
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 &
|
./a.out $DIR --port $PORT --no-server-id >/dev/null &
|
||||||
PID=$!
|
PID=$!
|
||||||
kill -0 $PID || exit 1
|
kill -0 $PID || exit 1
|
||||||
python test_server_id.py
|
python test_server_id.py
|
||||||
kill $PID
|
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
|
gcov darkhttpd
|
||||||
rm -rf $DIR
|
rm -rf $DIR
|
||||||
rm -f darkhttpd.gcda darkhttpd.gcno darkhttpd.log a.out
|
rm -f darkhttpd.gcda darkhttpd.gcno darkhttpd.log a.out
|
||||||
|
|||||||
41
devel/test_mimemap.py
Executable file
41
devel/test_mimemap.py
Executable 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:
|
||||||
Reference in New Issue
Block a user