Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Test the scan settings no test reached
Nothing exercised noweb, scan-hidden-path, section-from-path, an
ordinary project-list, the gitweb settings or the command-line modes,
so a regression could list repositories meant to stay hidden, and the
command line could drop what a repository set or lose its sort.
Diffstat (limited to 'tests/t0207-scan.sh')
| -rwxr-xr-x | tests/t0207-scan.sh | 128 |
1 file changed, 128 insertions, 0 deletions
diff --git a/tests/t0207-scan.sh b/tests/t0207-scan.sh new file mode 100755 index 0000000..7a919ec --- /dev/null +++ b/tests/t0207-scan.sh @@ -0,0 +1,128 @@ +#!/bin/sh + +# Checks the repository scan. scan-path and the command line both walk a +# directory for repositories, and the settings read before scan-path decide +# which repositories a scan takes, what it names them, where it files them +# and in what order. + +test_description='Check the repository scan' +CGIT_TEST_NO_CREATE_REPOS=YesPlease +. ./setup.sh + +# The index sorts by name, so a scan's own order shows only in the list it +# caches, which keeps the repositories in the order the scan found them. +scan_index() { + cgitrc_file=$1 + shift + { + echo "virtual-root=/" && + echo "cache-size=0" && + printf '%s\n' "$@" + } >"$cgitrc_file" && + cgit_ok "$cgitrc_file" "url=" +} + +test_expect_success 'a scan from the command line prints its list sorted by url' ' + mkrepo cmdscan/x 1 && + mkrepo cmdscan/x.git 1 && + mv cmdscan/x/.git cmdscan/x/a.git && + echo "snapshots=zip" >cmdscan/x.git/.git/cgitrc && + cgit --scan-path="$PWD/cmdscan" >scan.out && + sed -n "s/^repo.url=//p" scan.out >urls && + test_write_lines x.git x/a.git >expect && + test_cmp expect urls && + test_grep "^repo.snapshots=\\.zip$" scan.out && + cgit --scan-tree="$PWD/cmdscan" >tree.out && + test_cmp scan.out tree.out +' + +test_expect_success 'the command line can stand in for the web server' ' + mkrepo repos/foo 1 && + cgitrc_repo cmdrc foo && + CGIT_CONFIG="$PWD/cmdrc" cgit --nohttp --query="url=foo/log/" >nohttp.out && + test_grep ! "^Status:" nohttp.out && + test_grep "data-page=.log. data-repo=.foo." nohttp.out && + sed "s/^cache-size=0$/cache-size=64/" cmdrc >cmdcacherc && + mkdir cmdcache && + CGIT_CONFIG="$PWD/cmdcacherc" cgit --cache="$PWD/cmdcache" --query="url=foo/log/" >cache.out && + test_grep "^Status: 200" cache.out && + ls cmdcache >slots && + test_line_count = 1 slots +' + +# A noweb file in a repository keeps the scan from listing it. +test_expect_success 'a repository holding noweb is left out' ' + mkrepo noweb/shown 1 && + mkrepo noweb/hidden 1 && + touch noweb/hidden/.git/noweb && + scan_index nowebrc "scan-path=$PWD/noweb" >tmp && + test_grep ">shown</a>" tmp && + test_grep ! ">hidden</a>" tmp +' + +test_expect_success 'a dot directory is scanned only with scan-hidden-path' ' + mkrepo dotted/shown 1 && + mkrepo dotted/.secret 1 && + scan_index dottedrc "scan-path=$PWD/dotted" >tmp && + test_grep ">shown</a>" tmp && + test_grep ! ">.secret</a>" tmp && + scan_index dottedrc "scan-hidden-path=1" "scan-path=$PWD/dotted" >tmp && + test_grep ">.secret</a>" tmp +' + +# The section is taken from the path a number of separators in from the left, +# or back from the right when the number is negative, and the name keeps what +# follows it. A path too short for the number keeps no section. +test_expect_success 'section-from-path files a repository under its path' ' + mkrepo sectioned/top/mid/repo 1 && + mkrepo sectioned/solo 1 && + scan_index sectionrc "section-from-path=1" "scan-path=$PWD/sectioned" >tmp && + test_grep "<td colspan=.[0-9]*. class=.reposection.>top</td>" tmp && + test_grep "href=./top/mid/repo/.>mid/repo</a>" tmp && + scan_index sectionrc "section-from-path=-1" "scan-path=$PWD/sectioned" >tmp && + test_grep "<td colspan=.[0-9]*. class=.reposection.>top/mid</td>" tmp && + test_grep "href=./top/mid/repo/.>repo</a>" tmp && + test_grep "href=./solo/.>solo</a>" tmp && + scan_index sectionrc "scan-path=$PWD/sectioned" >tmp && + test_grep ! "class=.reposection." tmp && + test_grep "href=./top/mid/repo/.>top/mid/repo</a>" tmp +' + +test_expect_success 'a project list scans only what it names, in its order' ' + mkrepo listed/one 1 && + mkrepo listed/two 1 && + mkrepo listed/unlisted 1 && + test_write_lines two one >projects && + mkdir listcache && + { + echo "virtual-root=/" && + echo "cache-root=$PWD/listcache" && + echo "cache-size=64" && + echo "cache-index-ttl=0" && + echo "project-list=$PWD/projects" && + echo "scan-path=$PWD/listed" + } >listrc && + cgit_ok listrc "url=" >tmp && + test_grep ">one</a>" tmp && + test_grep ">two</a>" tmp && + test_grep ! ">unlisted</a>" tmp && + sed -n "s/^repo.url=//p" listcache/rc-* >urls && + test_write_lines two one >expect && + test_cmp expect urls +' + +test_expect_success 'a scan reads the gitweb settings of a repository' ' + mkrepo gitweb/repo 1 && + git -C gitweb/repo config gitweb.owner "Some Owner" && + git -C gitweb/repo config gitweb.description "Described by gitweb" && + git -C gitweb/repo config gitweb.category "Category" && + scan_index gitwebrc "enable-git-config=1" "scan-path=$PWD/gitweb" >tmp && + test_grep "<td colspan=.[0-9]*. class=.reposection.>Category</td>" tmp && + test_grep ">Described by gitweb</a>" tmp && + test_grep "Some Owner" tmp && + scan_index gitwebrc "scan-path=$PWD/gitweb" >tmp && + test_grep ! "Described by gitweb" tmp && + test_grep ! "Some Owner" tmp +' + +test_done |
