Skip to content

Commit

Permalink
actual tests
Browse files Browse the repository at this point in the history
  • Loading branch information
progrium committed Jul 12, 2013
1 parent 3364ecd commit 9331e29
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
7 changes: 6 additions & 1 deletion Makefile
@@ -1,5 +1,7 @@
VERSION = 0.1.0

REMOTE_DIR ?= /tmp/gitreceive

install:
cp gitreceive /usr/local/bin/gitreceive
chmod +x /usr/local/bin/gitreceive
Expand All @@ -11,4 +13,7 @@ test: check-docker
cp gitreceive tests
docker build -t progrium/gitreceive-tests tests
rm tests/gitreceive
docker run progrium/gitreceive-tests
docker run progrium/gitreceive-tests

remote:
tar -c . | ssh ${REMOTE} "rm -rf ${REMOTE_DIR} && mkdir -p ${REMOTE_DIR} && cd ${REMOTE_DIR} && tar -xf - && make ${TARGET}"
3 changes: 2 additions & 1 deletion tests/Dockerfile
@@ -1,6 +1,7 @@
from ubuntu:12.04
run apt-get -y update
run apt-get -y install git
run apt-get -y install git ssh
run ssh-keygen -t rsa -N "" -f /root/.ssh/id_rsa
run git clone https://github.com/sstephenson/bats.git && cd bats && ./install.sh /usr/local
add ./gitreceive /usr/local/bin/gitreceive
add ./gitreceive.bats /
Expand Down
34 changes: 31 additions & 3 deletions tests/gitreceive.bats
@@ -1,6 +1,34 @@

@test "hello world" {
result=$(echo Hello world)
[[ $result == "Hello world" ]]
teardown() {
rm -rf /home/git
userdel git
}

@test "gitreceive init creates git user ready for pushes" {
gitreceive init
[[ -d /home/git ]]
[[ -f /home/git/.ssh/authorized_keys ]]
[[ -f /home/git/receiver ]]
[[ "git" == "$(ls -l /home/git/receiver | awk '{print $3}')" ]]
}

@test "gitreceive receiver script gets tar of pushed repo" {
gitreceive init
cat /root/.ssh/id_rsa.pub | ssh root@localhost "gitreceive upload-key test"
mkdir $BATS_TMPDIR/$BATS_TEST_NAME-push
chown git $BATS_TMPDIR/$BATS_TEST_NAME-push
cat <<EOF > /home/git/receiver
#!/bin/bash
tar -C $BATS_TMPDIR/$BATS_TEST_NAME-push -xf -
EOF
mkdir $BATS_TMPDIR/$BATS_TEST_NAME-repo
cd $BATS_TMPDIR/$BATS_TEST_NAME-repo
git init
echo "foobar" > contents
git add .
git commit -m 'only commit'
git remote add test git@localhost:test-$BATS_TEST_NUMBER
git push test master
[[ -f $BATS_TMPDIR/$BATS_TEST_NAME-push/contents ]]
[[ "foobar" == $(cat $BATS_TMPDIR/$BATS_TEST_NAME-push/contents) ]]
}
11 changes: 11 additions & 0 deletions tests/init
@@ -1,2 +1,13 @@
#!/bin/bash
set -e

mkdir -p /var/run/sshd && /usr/sbin/sshd

cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
cat <<EOF > /root/.ssh/config
Host localhost
UserKnownHostsFile=/dev/null
StrictHostKeyChecking=no
EOF

/usr/local/bin/bats /gitreceive.bats

0 comments on commit 9331e29

Please sign in to comment.