#!/bin/sh test_description='Check ESI frame and fragment output' . ./setup.sh test_expect_success 'esi-diff is a 404 when ESI is disabled' ' cgit_url "foo/esi-diff&id=HEAD" >tmp && grep "Status: 404" tmp ' test_expect_success 'commit page has no ESI markup when ESI is disabled' ' cgit_url "foo/commit" >tmp && ! grep -e "esi:include" -e "Surrogate-Control" -e ">cgitrc ' test_expect_success 'generate foo/commit frame' ' head=$(cd repos/foo && git rev-parse HEAD) && parent=$(cd repos/foo && git rev-parse HEAD^) && cgit_url "foo/commit" >tmp ' test_expect_success 'frame announces ESI' ' grep "^Surrogate-Control: content=.ESI/1.0.$" tmp ' test_expect_success 'frame sets base to the repo root' ' grep "" tmp ' test_expect_success 'frame keeps header, tabs and commit info' ' grep "" tmp && grep "
commit 5<" tmp && grep "" tmp ' test_expect_success 'frame includes fragment with resolved ids' ' grep "" tmp ' test_expect_success 'frame contains no diff' ' ! grep "class=.diffstat." tmp && ! grep "class=.diff." tmp ' test_expect_success 'generate fragment' ' cgit_url "foo/esi-diff&id=$head&id2=$parent&dt=0" >tmp ' test_expect_success 'fragment has no layout' ' ! grep "" tmp && ! grep "diff options" tmp ' test_expect_success 'fragment has the diff' ' grep "
" tmp && grep "
+5
" tmp ' test_expect_success 'fragment links are relative and carry no repo' ' grep "
file-5" tmp && grep "+++ b/file-5" tmp && ! grep "/foo/" tmp ' test_expect_success 'fragment ignores branch parameter' ' cgit_url "foo/esi-diff&id=$head&id2=$parent&dt=0&h=master" >tmp2 && ! grep "h=master" tmp2 ' test_expect_success 'ssdiff fragment links are relative' ' cgit_url "foo/esi-diff&id=$head&id2=$parent&dt=1" >tmp && grep "
" tmp && grep "+++ b/file-5" tmp && grep "file-5" tmp && ! grep "/foo/" tmp ' test_expect_success 'root commit frame omits id2' ' root=$(cd repos/foo && git rev-list --reverse HEAD | head -1) && cgit_url "foo/commit&id=$root" >tmp && grep "" tmp ' test_expect_success 'root commit fragment renders' ' cgit_url "foo/esi-diff&id=$root&dt=0" >tmp && grep "file-1" tmp ' test_expect_success 'diff page is a frame too' ' cgit_url "foo/diff" >tmp && grep "^Surrogate-Control:" tmp && grep "diff options" tmp && grep "" tmp ' test_expect_success 'diff options are carried into the fragment URL' ' cgit_url "foo/diff&dt=1&context=5&ignorews=1" >tmp && grep "" tmp ' test_expect_success 'symbolic id resolves to the same fragment' ' cgit_url "foo/commit&id=master" >tmp && grep "" tmp ' test_expect_success 'fragment without id is a 400' ' cgit_url "foo/esi-diff" >tmp && grep "Status: 400" tmp ' test_expect_success 'rawdiff is untouched' ' cgit_url "foo/rawdiff" >tmp && ! grep "esi:include" tmp && grep "^+5$" tmp ' test_expect_success 'fragments are cached under a repo-neutral key' ' cgit_query "p=ls_cache" >tmp && grep " esi-diff/?id=$head&id2=$parent&dt=0&context=0&ignorews=0$" tmp && grep " esi-diff/?id=$head&id2=$parent&dt=1&context=0&ignorews=0$" tmp && ! grep "foo/esi-diff&id=$head" tmp ' test_done