blob: 7ce9f5363fa1faace42afa064a9e611831b84c03 (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
#!/bin/sh

# Checks link-trailers.lua, the shipped trailer-filter, whose configuration as
# shipped links Fixes and Reverts object names to ./?id=, Closes and Bug marks
# to bugs.example.com and a bare URL to itself. The unit checks cover the rules
# under every suitable standalone Lua, and a commit carrying one of each is
# then rendered through cgit itself.

test_description='Check the shipped link-trailers extension'
CGIT_TEST_NO_CREATE_REPOS=YesPlease
. ./setup.sh
. "$TEST_OUTPUT_DIRECTORY/extensions/lib.sh"

interpreters=$(ext_lua_interpreters 4)
test -z "$interpreters" &&
	say 'no standalone lua on the path, unit checks skipped'

for lua in $interpreters
do
	test_expect_success "unit checks under $lua" "
		'$lua' '$EXT_TEST_DIRECTORY/test-link-trailers.lua' '$EXTENSIONS_DIRECTORY/link-trailers.lua'
	"
done

test "$CGIT_HAS_LUA" -eq 1 && test_set_prereq CGIT_LUA
test "$CGIT_HAS_LUA" -eq 1 ||
	say 'cgit built without lua, filter checks through cgit skipped'

test_expect_success 'create a repository whose commit carries linkable trailers' '
	test_create_repo repos/linky &&
	(
		cd repos/linky &&
		echo content >file &&
		git add file &&
		git commit -F - <<-\EOF
		fix it

		Fixes: 1234567 ("earlier")
		Link: https://example.com/?a=1&b=2
		Closes: #45
		EOF
	)
'

test_expect_success 'point cgit at it through the trailer filter' '
	cat >cgitrc <<-EOF
	virtual-root=/
	cache-size=0
	enable-commit-trailers=1
	repo.url=linky
	repo.path=$PWD/repos/linky/.git
	repo.trailer-filter=lua:$EXTENSIONS_DIRECTORY/link-trailers.lua
	EOF
'

test_expect_success CGIT_LUA 'the Fixes object name links to its commit page' '
	cgit_url "linky/commit/" >tmp &&
	grep "<th scope=.row.>Fixes</th><td><a href=....id=1234567.>1234567</a> (.earlier.)</td>" tmp
'

test_expect_success CGIT_LUA 'the bare URL links to itself' '
	grep "<a href=.https://example.com/?a=1&amp;b=2.>https://example.com/?a=1&amp;b=2</a>" tmp
'

test_expect_success CGIT_LUA 'the Closes mark links out' '
	grep "bugs.example.com/?bug=45.>#45</a>" tmp
'

test_done