summaryrefslogtreecommitdiff
path: root/tests/t0112-esi.sh
blob: f45509cfbb3d8d261fd5b00ba614004a0a9cc5ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/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 "<base " tmp
'

test_expect_success 'enable ESI' '
	rm -f cache/* &&
	echo "enable-esi=1" >>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 "<base href=./foo/./>" tmp
'

test_expect_success 'frame keeps header, tabs and commit info' '
	grep "<table class=.tabs.>" tmp &&
	grep "<div class=.commit-subject.>commit 5<" tmp &&
	grep "<a href=./foo/tree/.>" tmp
'

test_expect_success 'frame includes fragment with resolved ids' '
	grep "<esi:include src=./foo/esi-diff/?id=$head&id2=$parent&dt=0./>" 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 "<html" tmp &&
	! grep "<table class=.tabs.>" tmp &&
	! grep "diff options" tmp
'

test_expect_success 'fragment has the diff' '
	grep "<table summary=.diffstat. class=.diffstat.>" tmp &&
	grep "<div class=.add.>+5</div>" tmp
'

test_expect_success 'fragment links are relative and carry no repo' '
	grep "<a href=.diff/file-5?id=$head&amp;id2=$parent.>file-5</a>" tmp &&
	grep "+++ b/<a href=.tree/file-5?id=$head.>file-5</a>" 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 "<table summary=.ssdiff. class=.ssdiff.>" tmp &&
	grep "+++ b/<a href=.tree/file-5?id=$head.>file-5</a>" tmp &&
	grep "<a href=.diff/file-5?id=$head&amp;id2=$parent&amp;dt=1.>file-5</a>" 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 "<esi:include src=./foo/esi-diff/?id=$root&dt=0./>" tmp
'

test_expect_success 'root commit fragment renders' '
	cgit_url "foo/esi-diff&id=$root&dt=0" >tmp &&
	grep "<a href=.diff/file-1?id=$root.>file-1</a>" tmp
'

test_expect_success 'diff page is a frame too' '
	cgit_url "foo/diff" >tmp &&
	grep "^Surrogate-Control:" tmp &&
	grep "diff options" tmp &&
	grep "<esi:include src=./foo/esi-diff/?id=$head&id2=$parent&dt=0./>" tmp
'

test_expect_success 'diff options are carried into the fragment URL' '
	cgit_url "foo/diff&dt=1&context=5&ignorews=1" >tmp &&
	grep "<esi:include src=./foo/esi-diff/?id=$head&id2=$parent&dt=1&context=5&ignorews=1./>" tmp
'

test_expect_success 'symbolic id resolves to the same fragment' '
	cgit_url "foo/commit&id=master" >tmp &&
	grep "<esi:include src=./foo/esi-diff/?id=$head&id2=$parent&dt=0./>" 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