Diff options
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/t0507-hooks.sh | 68 |
1 file changed, 51 insertions, 17 deletions
diff --git a/tests/t0507-hooks.sh b/tests/t0507-hooks.sh index f30bd94..9e5dfce 100755 --- a/tests/t0507-hooks.sh +++ b/tests/t0507-hooks.sh @@ -11,8 +11,32 @@ CGIT_TEST_NO_CREATE_REPOS=YesPlease HOOK_DIRECTORY="$TEST_OUTPUT_DIRECTORY/../custom/hooks" +# The request each page slot in a directory answers, read off its head the +# way the hook reads it, leaving out the locks and the cached repository +# scan. +cached_requests() { + test -d "$1" || return 1 + for slot in "$1"/* + do + case $slot in + *.lock | */rc-*) + continue + ;; + esac + dd if="$slot" bs=4096 count=1 2>/dev/null >slot-head && + tr "\0" "\n" <slot-head | sed -n 1p || return 1 + done +} + +# Every cache hook run starts from the cache as cgit left it. +fresh_slots() { + rm -rf slots && cp -R pristine slots +} + # A cache that cgit itself filled, for two scanned repositories and the -# index, so the hook reads the keys cgit really writes. +# index, so the hook reads the keys cgit really writes. Each page has to +# have a slot of its own, or a check that a page went would pass for one +# that was never there. test_expect_success 'set up a cache of two repositories and the index' ' test_create_repo pusher && test_commit -C pusher cached && @@ -36,19 +60,27 @@ test_expect_success 'set up a cache of two repositories and the index' ' cgit_rc cachedrc "url=b.git/refs/" >/dev/null && echo writer >slots/0123abcd.lock && cp -R slots pristine && + sort >expect-keys <<-\EOF && + 7|http://0|1|/0| + 7|http://0|7|/a.git/0| + 7|http://0|11|/a.git/log/0| + 7|http://0|7|/b.git/0| + 7|http://0|11|/b.git/log/0| + 7|http://0|0|15|url=a.git/refs/ + 7|http://0|0|15|url=b.git/refs/ + EOF + cached_requests pristine >keys && + sort keys >sorted-keys && + test_cmp expect-keys sorted-keys && + ls pristine >pristine-slots && + grep "^rc-" pristine-slots && sed -e "s|^cache_root=.*|cache_root='\''$PWD/slots'\''|" \ -e "s|^scan_path=.*|scan_path='\''$PWD/scan'\''|" \ - "$HOOK_DIRECTORY/post-receive.cgit-cache" >cache-hook + "$HOOK_DIRECTORY/post-receive.cgit-cache" >cache-hook && + grep -Fx "cache_root='\''$PWD/slots'\''" cache-hook && + grep -Fx "scan_path='\''$PWD/scan'\''" cache-hook ' -# The request each slot answers, read off its head the way the hook reads it. -cached_requests() { - for slot in slots/* - do - dd if="$slot" bs=4096 count=1 2>/dev/null | tr "\0" "\n" | sed -n 1p - done -} - # The hooks are POSIX sh, so each runs under every such shell that is here. shells= for shell in sh dash ksh bash @@ -59,9 +91,9 @@ done for shell in $shells do test_expect_success "a push drops its own pages and the index under $shell" " - rm -rf slots && cp -R pristine slots && + fresh_slots && (cd scan/a.git && $shell ../../cache-hook) && - cached_requests >left && + cached_requests slots >left && grep '|/b.git/log/' left && grep 'url=b.git/refs/' left && ! grep 'a.git' left && @@ -72,27 +104,29 @@ do done test_expect_success 'a repository named in cgitrc gives the hook its url' ' - rm -rf slots && cp -R pristine slots && + fresh_slots && git -C scan/b.git config hooks.cgiturl b.git && sed "s|^scan_path=.*|scan_path=/nonexistent|" cache-hook >named-hook && + grep -Fx "scan_path=/nonexistent" named-hook && (cd scan/b.git && sh ../../named-hook) && - cached_requests >left && + cached_requests slots >left && grep "|/a.git/log/" left && ! grep "b.git" left ' test_expect_success 'with no url to go on the whole cache goes' ' - rm -rf slots && cp -R pristine slots && + fresh_slots && (cd scan/a.git && sh ../../named-hook) && test "$(ls slots)" = 0123abcd.lock ' test_expect_success SANITY 'the cache hook shows a pusher no error' ' - rm -rf slots && cp -R pristine slots && + fresh_slots && test_when_finished "chmod 755 slots" && chmod 555 slots && (cd scan/a.git && sh ../../cache-hook 2>../../err) && - cached_requests | grep "a.git" && + ls slots >left && + test_cmp pristine-slots left && test_must_be_empty err ' |
