From 7f13a91e9c39dc70af12511443dceb6bf4dc80f4 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 11 Oct 2016 02:14:20 +0200 Subject: git-receiver: added test for post-receive. fixed leak --- tests/blogc-git-receiver/check_pre_receive.sh | 148 ++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100755 tests/blogc-git-receiver/check_pre_receive.sh (limited to 'tests/blogc-git-receiver') diff --git a/tests/blogc-git-receiver/check_pre_receive.sh b/tests/blogc-git-receiver/check_pre_receive.sh new file mode 100755 index 0000000..dc2066f --- /dev/null +++ b/tests/blogc-git-receiver/check_pre_receive.sh @@ -0,0 +1,148 @@ +#!/bin/bash + +set -xe -o pipefail + +export LC_ALL=C + +TEMP="$(mktemp -d)" +[[ -n "${TEMP}" ]] + +trap_func() { + [[ -e "${TEMP}/output.txt" ]] && cat "${TEMP}/output.txt" + rm -rf "${TEMP}" +} + +trap trap_func EXIT + +mkdir -p "${TEMP}/repos" +git init --bare "${TEMP}/repos/foo.git" &> /dev/null + +SELF="${PWD}/blogc-git-receiver" + +ln -s "${SELF}" "${TEMP}/repos/foo.git/hooks/pre-receive" + +cat > "${TEMP}/payload.txt" <&1 | tee "${TEMP}/output.txt" +grep "warning: no reference to master branch found. nothing to deploy." "${TEMP}/output.txt" &> /dev/null + +cat > "${TEMP}/tmp.txt" < \$(OUTPUT_DIR)/foo.txt + +reset refs/heads/master +commit refs/heads/master +mark :2 +author Rafael G. Martins 1476139736 +0200 +committer Rafael G. Martins 1476139736 +0200 +data 11 +testing... +M 100644 :1 Makefil + +EOF + +git fast-import < "${TEMP}/tmp.txt" &> /dev/null + +cat > "${TEMP}/payload.txt" <&1 | tee "${TEMP}/output.txt" +grep "warning: no makefile found. skipping ..." "${TEMP}/output.txt" &> /dev/null + +cd "${TEMP}" +rm -rf "${TEMP}/repos/foo.git" +git init --bare "${TEMP}/repos/foo.git" &> /dev/null +ln -s "${SELF}" "${TEMP}/repos/foo.git/hooks/pre-receive" + +cat > "${TEMP}/tmp.txt" < \$(OUTPUT_DIR)/foo.txt + +reset refs/heads/master +commit refs/heads/master +mark :2 +author Rafael G. Martins 1476139736 +0200 +committer Rafael G. Martins 1476139736 +0200 +data 11 +testing... +M 100644 :1 Makefile + +EOF + +cd "${TEMP}/repos/foo.git" +git fast-import < "${TEMP}/tmp.txt" &> /dev/null + +cat > "${TEMP}/payload.txt" <&1 | tee "${TEMP}/output.txt" +grep "echo lol" "${TEMP}/output.txt" &> /dev/null + +[[ -h htdocs ]] +[[ "$(cat htdocs/foo.txt)" == "lol" ]] + +DEST="$(readlink htdocs)" +[[ -e "${DEST}" ]] + +cd "${TEMP}" +rm -rf "${TEMP}/repos/foo.git" +git init --bare "${TEMP}/repos/foo.git" &> /dev/null +ln -s "${SELF}" "${TEMP}/repos/foo.git/hooks/pre-receive" + +cat > "${TEMP}/tmp.txt" < \$(OUTPUT_DIR)/foo.txt + + +commit refs/heads/master +mark :2 +author Rafael G. Martins 1476142917 +0200 +committer Rafael G. Martins 1476142917 +0200 +data 12 +testing2... +M 100644 :1 Makefile + +EOF + +cd "${TEMP}/repos/foo.git" +ln -s "${DEST}" htdocs +git fast-import < "${TEMP}/tmp.txt" &> /dev/null + +cat > "${TEMP}/payload.txt" <&1 | tee "${TEMP}/output.txt" +grep "echo lol" "${TEMP}/output.txt" &> /dev/null + +[[ -h htdocs ]] +[[ "$(cat htdocs/foo.txt)" == "lol" ]] +[[ "${DEST}" != "$(readlink htdocs)" ]] +[[ ! -e "${DEST}" ]] + +rm "${TEMP}/output.txt" -- cgit v1.2.3-18-g5258