diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/t0105-plain.sh51
-rwxr-xr-xtests/t0111-atom.sh65
2 files changed, 116 insertions, 0 deletions
diff --git a/tests/t0105-plain.sh b/tests/t0105-plain.sh
new file mode 100755
index 0000000..b950098
--- /dev/null
+++ b/tests/t0105-plain.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+# The plain page hands over a repository's own bytes rather than a rendered
+# view of them, so these checks read the response headers and then compare
+# the body against what git says the blob holds. A file with no better guess
+# is served as text unless its bytes look binary, a directory answers with a
+# bare listing of links rather than one of the themed pages, and a path that
+# names nothing has to come back as a 404 rather than an empty document.
+
+test_description='Check content on plain page'
+. ./setup.sh
+
+test_expect_success 'generate foo/plain/file-1' '
+ cgit_url "foo/plain/file-1" >tmp
+'
+
+test_expect_success 'a text file is served as text/plain' '
+ head -n 1 tmp | grep "Status: 200 OK" &&
+ sed "/^$/q" tmp | grep "Content-Type: text/plain"
+'
+
+test_expect_success 'the body carries the blob byte for byte' '
+ strip_headers <tmp >body &&
+ git -C repos/foo show master:file-1 >expect &&
+ test_cmp expect body
+'
+
+test_expect_success 'a missing path is a 404' '
+ cgit_url "foo/plain/no-such-file" >tmp &&
+ head -n 1 tmp | grep "Status: 404"
+'
+
+test_expect_success 'a directory answers with a listing of links' '
+ cgit_url "foo/plain" >tmp &&
+ grep "<li><a href=" tmp &&
+ grep "file-1" tmp &&
+ grep "file-5" tmp
+'
+
+test_expect_success 'a blob whose bytes look binary is served as octet-stream' '
+ (
+ cd repos/foo &&
+ printf "\000\001\002" >blob.bin &&
+ git add blob.bin &&
+ git commit -m binary
+ ) &&
+ cgit_url "foo/plain/blob.bin" >tmp &&
+ sed "/^$/q" tmp | grep "Content-Type: application/octet-stream"
+'
+
+test_done
diff --git a/tests/t0111-atom.sh b/tests/t0111-atom.sh
new file mode 100755
index 0000000..d2a678b
--- /dev/null
+++ b/tests/t0111-atom.sh
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+# The atom page serves a repository's recent history as a feed, XML rather
+# than a page, so a reader can follow the project without polling the
+# browsable log. These checks read the content type, count the entries
+# against the max-atom-items cap, which defaults to ten, and hand the feed to
+# xmllint where one is installed, since a reader is far stricter about
+# well-formedness than any of the greps here.
+
+test_description='Check the atom feed'
+. ./setup.sh
+
+test_expect_success 'generate foo/atom' '
+ cgit_url "foo/atom" >tmp
+'
+
+test_expect_success 'the response is an atom feed' '
+ head -n 1 tmp | grep "Status: 200 OK" &&
+ sed "/^$/q" tmp | grep "Content-Type: application/atom+xml" &&
+ strip_headers <tmp >feed &&
+ grep "<feed xmlns=.http://www.w3.org/2005/Atom.>" feed &&
+ grep "<title>foo, branch master</title>" feed
+'
+
+test_expect_success 'every commit of a small repository is an entry' '
+ test $(grep -c "<entry>" feed) -eq 5 &&
+ grep "<title>commit 1</title>" feed &&
+ grep "<title>commit 5</title>" feed
+'
+
+test_expect_success 'ten entries is the default ceiling' '
+ cgit_url "bar/atom" >tmp &&
+ strip_headers <tmp >feed &&
+ test $(grep -c "<entry>" feed) -eq 10 &&
+ grep "<title>commit 50</title>" feed &&
+ ! grep "<title>commit 40</title>" feed
+'
+
+test_expect_success 'max-atom-items overrides the ceiling' '
+ {
+ echo "virtual-root=/" &&
+ echo "cache-size=0" &&
+ echo "max-atom-items=3" &&
+ echo "repo.url=bar" &&
+ echo "repo.path=$PWD/repos/bar/.git"
+ } >atomrc &&
+ CGIT_CONFIG="$PWD/atomrc" QUERY_STRING="url=bar/atom" cgit >tmp &&
+ strip_headers <tmp >feed &&
+ test $(grep -c "<entry>" feed) -eq 3
+'
+
+if command -v xmllint >/dev/null 2>&1
+then
+ test_set_prereq XMLLINT
+else
+ say 'Skipping well-formedness check: xmllint not found'
+fi
+
+test_expect_success XMLLINT 'the feed is well-formed xml' '
+ cgit_url "foo/atom" >tmp &&
+ strip_headers <tmp >feed &&
+ xmllint --noout feed
+'
+
+test_done