From 1e1f9009f3b952ed82ad82df79e5d8b85ec4bb74 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Mon, 12 Dec 2016 17:22:52 +0200 Subject: [PATCH] - A more realistic receiver script, added tests to verify said script. --- tests/files/receiver.sh | 38 ++++++++++++++++++++++++++++++++++++-- tests/playbook.yml | 10 +++++++++- tests/test_gitreceive.py | 9 ++++++--- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/tests/files/receiver.sh b/tests/files/receiver.sh index efff13d..5f62f46 100644 --- a/tests/files/receiver.sh +++ b/tests/files/receiver.sh @@ -1,5 +1,39 @@ #!/bin/sh set -eu + +# This part was copied verbatim from +# https://github.com/progrium/gitreceive/wiki/TipsAndTricks +fetch_submodules () { + # We reinitialize .git to avoid conflicts + rm -fr .git + # GIT_DIR is previously set by gitreceive to ".", we want it back to default + # for this + unset GIT_DIR + git init . + + # We read the submodules from .gitmodules + git config -f .gitmodules --get-regexp '^submodule\..*\.path$' | + while read path_key path + do + rm -fr $path + url_key=`echo $path_key | sed 's/\.path/.url/'` + url=`git config -f .gitmodules --get "$url_key"` + git submodule add $url $path + done +} + mkdir -p /var/tmp/gitreceive -tar -xC /var/tmp/gitreceive -f - -echo "OK" +cd /var/tmp/gitreceive +echo '----> Unpacking ...' +tar -xf - +if [ -f .gitmodules ] +then + echo '----> Fetching submodules ...' + fetch_submodules +fi +if [ -f receiver ] && [ -x receiver ] +then + echo '----> Running receiver ...' + ./receiver +fi +echo '----> OK.' diff --git a/tests/playbook.yml b/tests/playbook.yml index 72e6f28..eac28b9 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -59,9 +59,17 @@ args: creates: /root/.ssh/known_hosts + - name: Clone gitreceive test repo + git: + dest: /root/gitreceive-test + force: yes + update: yes + repo: https://www.shore.co.il/git/gitreceive-test + version: master + - name: Add localhost as a git remote blockinfile: - dest: /root/gitreceive/.git/config + dest: /root/gitreceive-test/.git/config block: | [remote "test"] url = git@localhost:test diff --git a/tests/test_gitreceive.py b/tests/test_gitreceive.py index 85cc5ea..8786086 100644 --- a/tests/test_gitreceive.py +++ b/tests/test_gitreceive.py @@ -6,10 +6,13 @@ testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all') def test_gitreceive(Command, Sudo): with Sudo(): Command('rm -rf /home/git/test /var/tmp/gitreceive') - push = Command('git -C /root/gitreceive push test master') + push = Command('git -C /root/gitreceive-test push test master') assert push.rc == 0 - assert 'OK' in push.stderr + for message in ['----> Unpacking ...', '----> Fetching submodules ...', + '----> Running receiver ...', 'Dummy receiver script', + '----> OK.']: + assert message in push.stderr with Sudo(): - second_push = Command('git -C /root/gitreceive push test master') + second_push = Command('git -C /root/gitreceive-test push test master') assert second_push.rc == 0 assert 'Everything up-to-date' in second_push.stderr -- GitLab