Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Add the shared config writers and cgit_rc
The helpers are named by kind. cgitrc_repo and cgitrc_copy write the config file named first, and cgit_url, cgit_query and cgit_rc run cgit, each named after what it is handed first. A repository copies its defaults from the globals read before its repo.url, so cgitrc_repo places every setting itself, and a global can no longer land where it silently stops applying. The t00xx and t01xx files move to them here.
Diffstat (limited to 'tests/setup.sh')
-rwxr-xr-xtests/setup.sh61
1 file changed, 55 insertions, 6 deletions
diff --git a/tests/setup.sh b/tests/setup.sh
index 9f17778..92451b7 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -1,9 +1,10 @@
# Shared groundwork sourced by every test script. It builds a handful of small
# repositories under repos/ and writes a cgitrc pointing at them, then offers
-# the helpers that ask cgit for a page so a test only has to look at what comes
-# back. Sourcing it also brings in the test library from the bundled Git tree,
-# which is where test_expect_success and the trash directory come from. Set
-# CGIT_TEST_NO_CREATE_REPOS to get the helpers without paying for the fixtures.
+# the helpers that write a config of a test's own and ask cgit for a page, so
+# a test only has to look at what comes back. Sourcing it also brings in the
+# test library from the bundled Git tree, which is where test_expect_success
+# and the trash directory come from. Set CGIT_TEST_NO_CREATE_REPOS to get the
+# helpers without paying for the fixtures.
LF='
'
@@ -168,12 +169,60 @@ EOF
fi
}
+# Writes a config to the file named first that serves repos/<url> under the
+# url named second, with the cache off and links rooted at /, and takes the
+# rest as settings. A repository copies its defaults from the global settings
+# read before its repo.url, so whatever order they come in, the repo.* ones
+# go after the repository and all others ahead of it. A repo.path setting
+# names a repository kept somewhere else.
+cgitrc_repo() {
+ cgitrc_file=$1
+ cgitrc_url=$2
+ shift 2
+ cgitrc_path="repo.path=$PWD/repos/$cgitrc_url/.git"
+ cgitrc_before=
+ cgitrc_after=
+ for cgitrc_setting
+ do
+ case "$cgitrc_setting" in
+ repo.path=*)
+ cgitrc_path=$cgitrc_setting
+ ;;
+ repo.*)
+ cgitrc_after="$cgitrc_after$cgitrc_setting$LF"
+ ;;
+ *)
+ cgitrc_before="$cgitrc_before$cgitrc_setting$LF"
+ ;;
+ esac
+ done
+ printf '%s' "virtual-root=/$LF" "cache-size=0$LF" "$cgitrc_before" \
+ "repo.url=$cgitrc_url$LF" "$cgitrc_path$LF" "$cgitrc_after" >"$cgitrc_file"
+}
+
+# Writes the global settings named after the file ahead of a copy of the
+# shared cgitrc. The copy turns the cache off, because a page is cached under
+# its request alone and would otherwise come back as the shared config made
+# it.
+cgitrc_copy() {
+ cgitrc_file=$1
+ shift
+ {
+ test $# = 0 || printf '%s\n' "$@"
+ sed "s/^cache-size=.*/cache-size=0/" cgitrc
+ } >"$cgitrc_file"
+}
+
+cgit_rc() {
+ CGIT_CONFIG="$PWD/$1" QUERY_STRING="$2" cgit
+}
+
cgit_query() {
- CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="$1" cgit
+ cgit_rc cgitrc "$1"
}
cgit_url() {
- CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit
+ cgit_rc cgitrc "url=$1"
}
# The response headers run down to the first empty line, and a test comparing