diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2012-03-28 14:45:23 +0100 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2012-03-28 16:31:43 +0100 |
commit | 2b2c2a896d5fa9f8cdaf5ef543da1a64cc9b8fa4 (patch) | |
tree | 7bea1a60a668e13e636c62dd655b2c297eb1bd3b /tests | |
parent | bf521cd10164c18717ebf8806f077b8a490f979a (diff) | |
download | lorry-2b2c2a896d5fa9f8cdaf5ef543da1a64cc9b8fa4.tar.gz |
tests: add test for keeping the repo on error
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/git-backup-on-error.script | 49 | ||||
-rwxr-xr-x | tests/git-backup-on-error.setup | 47 | ||||
-rw-r--r-- | tests/git-backup-on-error.stderr | 0 | ||||
-rw-r--r-- | tests/git-backup-on-error.stdout | 82 |
4 files changed, 178 insertions, 0 deletions
diff --git a/tests/git-backup-on-error.script b/tests/git-backup-on-error.script new file mode 100755 index 0000000..866db65 --- /dev/null +++ b/tests/git-backup-on-error.script @@ -0,0 +1,49 @@ +#!/bin/bash +# +# Tests when a git mirror fails that it keeps the backups around +# +# Copyright (C) 2012 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +set -e +set -o pipefail + + +logfile="$DATADIR/git-backup-test-repo.log" +workdir="$DATADIR/work-dir" +repo="$DATADIR/git-backup-test-repo" + +normalize() { + DATETIMESPEC='[0-9]*-[0-9]*-[0-9]*-[0-9]*:[0-9]*:[0-9]*' + sed -r -e "s|git-pre-update-$DATETIMESPEC|git-pre-update-DATETIME|g" \ + -e "s|git-post-fail-$DATETIMESPEC|git-post-fail-DATETIME|g" \ + -e "s|$DATADIR|DATADIR|g" "$@" +} + +# mirror some history +./lorry --pull-only --log="$logfile" --working-area="$workdir" \ + "$DATADIR/git-backup-test-repo.lorry" | normalize + +# make upstream disappear to cause errors +rm -rf "$repo" +if ./lorry --pull-only --log="$logfile" --working-area="$workdir" \ + "$DATADIR/git-backup-test-repo.lorry" | normalize +then + echo Previous lorry command should have failed >&2 + exit 1 +else + find "$workdir/git-backup-test-repo" | LC_ALL=C sort | normalize +fi diff --git a/tests/git-backup-on-error.setup b/tests/git-backup-on-error.setup new file mode 100755 index 0000000..03a8dad --- /dev/null +++ b/tests/git-backup-on-error.setup @@ -0,0 +1,47 @@ +#!/bin/sh +# +# Creates a git repository with a single file and a single commit. +# +# Copyright (C) 2012 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +set -e + +# create the repository +repo="$DATADIR/git-backup-test-repo" +mkdir "$repo" +cd "$repo" +git init --quiet + +# add the test file +echo "first line" > test.txt +git add test.txt + +# make a commit +git commit --quiet -m "first commit" + +# create the .lorry file for the repository +cat <<EOF > $DATADIR/git-backup-test-repo.lorry +{ + "git-backup-test-repo": { + "type": "git", + "url": "file://$repo" + } +} +EOF + +# create the working directory +test -d "$DATADIR/work-dir" || mkdir "$DATADIR/work-dir" diff --git a/tests/git-backup-on-error.stderr b/tests/git-backup-on-error.stderr new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/git-backup-on-error.stderr diff --git a/tests/git-backup-on-error.stdout b/tests/git-backup-on-error.stdout new file mode 100644 index 0000000..8f91061 --- /dev/null +++ b/tests/git-backup-on-error.stdout @@ -0,0 +1,82 @@ +Mirror of git-backup-test-repo failed, state before mirror is saved at DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME and state after mirror is saved at DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME +Exception: git fetch origin failed (exit code 128): + fatal: 'DATADIR/git-backup-test-repo' does not appear to be a git repository + fatal: The remote end hung up unexpectedly + +DATADIR/work-dir/git-backup-test-repo +DATADIR/work-dir/git-backup-test-repo/git +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/FETCH_HEAD +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/HEAD +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/branches +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/config +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/description +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/git___gitorious_org_baserock_morphs_git_backup_test_repo.bndl +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/hooks +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/hooks/applypatch-msg.sample +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/hooks/commit-msg.sample +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/hooks/post-commit.sample +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/hooks/post-receive.sample +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/hooks/post-update.sample +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/hooks/pre-applypatch.sample +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/hooks/pre-commit.sample +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/hooks/pre-rebase.sample +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/hooks/prepare-commit-msg.sample +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/hooks/update.sample +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/info +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/info/exclude +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/info/refs +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/objects +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/packed-refs +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/refs +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/refs/heads +DATADIR/work-dir/git-backup-test-repo/git-post-fail-DATETIME/refs/tags +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/HEAD +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/branches +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/config +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/description +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/git___gitorious_org_baserock_morphs_git_backup_test_repo.bndl +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/hooks +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/hooks/applypatch-msg.sample +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/hooks/commit-msg.sample +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/hooks/post-commit.sample +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/hooks/post-receive.sample +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/hooks/post-update.sample +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/hooks/pre-applypatch.sample +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/hooks/pre-commit.sample +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/hooks/pre-rebase.sample +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/hooks/prepare-commit-msg.sample +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/hooks/update.sample +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/info +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/info/exclude +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/info/refs +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/objects +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/packed-refs +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/refs +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/refs/heads +DATADIR/work-dir/git-backup-test-repo/git-pre-update-DATETIME/refs/tags +DATADIR/work-dir/git-backup-test-repo/git/HEAD +DATADIR/work-dir/git-backup-test-repo/git/branches +DATADIR/work-dir/git-backup-test-repo/git/config +DATADIR/work-dir/git-backup-test-repo/git/description +DATADIR/work-dir/git-backup-test-repo/git/git___gitorious_org_baserock_morphs_git_backup_test_repo.bndl +DATADIR/work-dir/git-backup-test-repo/git/hooks +DATADIR/work-dir/git-backup-test-repo/git/hooks/applypatch-msg.sample +DATADIR/work-dir/git-backup-test-repo/git/hooks/commit-msg.sample +DATADIR/work-dir/git-backup-test-repo/git/hooks/post-commit.sample +DATADIR/work-dir/git-backup-test-repo/git/hooks/post-receive.sample +DATADIR/work-dir/git-backup-test-repo/git/hooks/post-update.sample +DATADIR/work-dir/git-backup-test-repo/git/hooks/pre-applypatch.sample +DATADIR/work-dir/git-backup-test-repo/git/hooks/pre-commit.sample +DATADIR/work-dir/git-backup-test-repo/git/hooks/pre-rebase.sample +DATADIR/work-dir/git-backup-test-repo/git/hooks/prepare-commit-msg.sample +DATADIR/work-dir/git-backup-test-repo/git/hooks/update.sample +DATADIR/work-dir/git-backup-test-repo/git/info +DATADIR/work-dir/git-backup-test-repo/git/info/exclude +DATADIR/work-dir/git-backup-test-repo/git/info/refs +DATADIR/work-dir/git-backup-test-repo/git/objects +DATADIR/work-dir/git-backup-test-repo/git/packed-refs +DATADIR/work-dir/git-backup-test-repo/git/refs +DATADIR/work-dir/git-backup-test-repo/git/refs/heads +DATADIR/work-dir/git-backup-test-repo/git/refs/tags |