From 7dc06f3096a5c2416f2f216ec57a549d189ebc76 Mon Sep 17 00:00:00 2001 From: Emil Mikulic Date: Mon, 10 Jun 2013 20:41:46 +1000 Subject: [PATCH] Add test for --mimetypes --- devel/cover | 29 +++++++++++++++++++++++------ devel/test_mimemap.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 6 deletions(-) create mode 100755 devel/test_mimemap.py diff --git a/devel/cover b/devel/cover index 972ee67..5c82b09 100755 --- a/devel/cover +++ b/devel/cover @@ -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 diff --git a/devel/test_mimemap.py b/devel/test_mimemap.py new file mode 100755 index 0000000..20d3e34 --- /dev/null +++ b/devel/test_mimemap.py @@ -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: