From aa13f5347d3c4bdb7797e2a2f5b53f8101200375 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Tue, 10 Dec 2013 21:30:31 +0000 Subject: Add multi-backup tear down and single backup test --- .../git-backup-on-error-multiple-backups.teardown | 21 ++++++++ tests/git-backup-on-error-single-backup.script | 51 ++++++++++++++++++ tests/git-backup-on-error-single-backup.setup | 47 ++++++++++++++++ tests/git-backup-on-error-single-backup.stderr | 0 tests/git-backup-on-error-single-backup.stdout | 62 ++++++++++++++++++++++ tests/git-backup-on-error-single-backup.teardown | 21 ++++++++ 6 files changed, 202 insertions(+) create mode 100755 tests/git-backup-on-error-multiple-backups.teardown create mode 100755 tests/git-backup-on-error-single-backup.script create mode 100755 tests/git-backup-on-error-single-backup.setup create mode 100644 tests/git-backup-on-error-single-backup.stderr create mode 100644 tests/git-backup-on-error-single-backup.stdout create mode 100755 tests/git-backup-on-error-single-backup.teardown diff --git a/tests/git-backup-on-error-multiple-backups.teardown b/tests/git-backup-on-error-multiple-backups.teardown new file mode 100755 index 0000000..7c73c04 --- /dev/null +++ b/tests/git-backup-on-error-multiple-backups.teardown @@ -0,0 +1,21 @@ +#!/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. + + +rm -r "$DATADIR/git-backup-test-repo.log" "$DATADIR/work-dir" diff --git a/tests/git-backup-on-error-single-backup.script b/tests/git-backup-on-error-single-backup.script new file mode 100755 index 0000000..f721461 --- /dev/null +++ b/tests/git-backup-on-error-single-backup.script @@ -0,0 +1,51 @@ +#!/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 + +repo_name="git-backup-test-repo" +logfile="$DATADIR/$repo_name.log" +workdir="$DATADIR/work-dir" +repo="$DATADIR/$repo_name" +prebackup="$workdir/$repo_name/git-pre-update" +postbackup="$workdir/$repo_name/git-post-fail" + +normalize() { + sed -r -e '/hooks\/.*\.sample/d' \ + -e "s/pack-[0-9a-z]+\.(idx|pack)$/pack-file/" \ + -e "s|$DATADIR|DATADIR|g" "$@" +} + +# mirror some history +"${SRCDIR}/test-lorry" --pull-only --log="$logfile" --working-area="$workdir" --bundle=never \ + "$DATADIR/git-backup-test-repo.lorry" | normalize + +# make upstream disappear to cause errors +rm -rf "$repo" +if "${SRCDIR}/test-lorry" --pull-only --log="$logfile" --working-area="$workdir" \ + "$DATADIR/git-backup-test-repo.lorry" --bundle=never 2>/dev/null \ + | 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-single-backup.setup b/tests/git-backup-on-error-single-backup.setup new file mode 100755 index 0000000..81c0a49 --- /dev/null +++ b/tests/git-backup-on-error-single-backup.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 < $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-single-backup.stderr b/tests/git-backup-on-error-single-backup.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/git-backup-on-error-single-backup.stdout b/tests/git-backup-on-error-single-backup.stdout new file mode 100644 index 0000000..db622ef --- /dev/null +++ b/tests/git-backup-on-error-single-backup.stdout @@ -0,0 +1,62 @@ +Mirror of git-backup-test-repo failed, state before mirror is saved at DATADIR/work-dir/git-backup-test-repo/git-pre-update and state after mirror is saved at DATADIR/work-dir/git-backup-test-repo/git-post-fail +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 +DATADIR/work-dir/git-backup-test-repo/git-post-fail/FETCH_HEAD +DATADIR/work-dir/git-backup-test-repo/git-post-fail/HEAD +DATADIR/work-dir/git-backup-test-repo/git-post-fail/branches +DATADIR/work-dir/git-backup-test-repo/git-post-fail/config +DATADIR/work-dir/git-backup-test-repo/git-post-fail/description +DATADIR/work-dir/git-backup-test-repo/git-post-fail/hooks +DATADIR/work-dir/git-backup-test-repo/git-post-fail/info +DATADIR/work-dir/git-backup-test-repo/git-post-fail/info/exclude +DATADIR/work-dir/git-backup-test-repo/git-post-fail/info/refs +DATADIR/work-dir/git-backup-test-repo/git-post-fail/objects +DATADIR/work-dir/git-backup-test-repo/git-post-fail/objects/info +DATADIR/work-dir/git-backup-test-repo/git-post-fail/objects/info/packs +DATADIR/work-dir/git-backup-test-repo/git-post-fail/objects/pack +DATADIR/work-dir/git-backup-test-repo/git-post-fail/objects/pack/pack-file +DATADIR/work-dir/git-backup-test-repo/git-post-fail/objects/pack/pack-file +DATADIR/work-dir/git-backup-test-repo/git-post-fail/packed-refs +DATADIR/work-dir/git-backup-test-repo/git-post-fail/refs +DATADIR/work-dir/git-backup-test-repo/git-post-fail/refs/heads +DATADIR/work-dir/git-backup-test-repo/git-post-fail/refs/tags +DATADIR/work-dir/git-backup-test-repo/git-pre-update +DATADIR/work-dir/git-backup-test-repo/git-pre-update/FETCH_HEAD +DATADIR/work-dir/git-backup-test-repo/git-pre-update/HEAD +DATADIR/work-dir/git-backup-test-repo/git-pre-update/branches +DATADIR/work-dir/git-backup-test-repo/git-pre-update/config +DATADIR/work-dir/git-backup-test-repo/git-pre-update/description +DATADIR/work-dir/git-backup-test-repo/git-pre-update/hooks +DATADIR/work-dir/git-backup-test-repo/git-pre-update/info +DATADIR/work-dir/git-backup-test-repo/git-pre-update/info/exclude +DATADIR/work-dir/git-backup-test-repo/git-pre-update/info/refs +DATADIR/work-dir/git-backup-test-repo/git-pre-update/objects +DATADIR/work-dir/git-backup-test-repo/git-pre-update/objects/info +DATADIR/work-dir/git-backup-test-repo/git-pre-update/objects/info/packs +DATADIR/work-dir/git-backup-test-repo/git-pre-update/objects/pack +DATADIR/work-dir/git-backup-test-repo/git-pre-update/objects/pack/pack-file +DATADIR/work-dir/git-backup-test-repo/git-pre-update/objects/pack/pack-file +DATADIR/work-dir/git-backup-test-repo/git-pre-update/packed-refs +DATADIR/work-dir/git-backup-test-repo/git-pre-update/refs +DATADIR/work-dir/git-backup-test-repo/git-pre-update/refs/heads +DATADIR/work-dir/git-backup-test-repo/git-pre-update/refs/tags +DATADIR/work-dir/git-backup-test-repo/git/FETCH_HEAD +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/hooks +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/objects/info +DATADIR/work-dir/git-backup-test-repo/git/objects/info/packs +DATADIR/work-dir/git-backup-test-repo/git/objects/pack +DATADIR/work-dir/git-backup-test-repo/git/objects/pack/pack-file +DATADIR/work-dir/git-backup-test-repo/git/objects/pack/pack-file +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 diff --git a/tests/git-backup-on-error-single-backup.teardown b/tests/git-backup-on-error-single-backup.teardown new file mode 100755 index 0000000..7c73c04 --- /dev/null +++ b/tests/git-backup-on-error-single-backup.teardown @@ -0,0 +1,21 @@ +#!/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. + + +rm -r "$DATADIR/git-backup-test-repo.log" "$DATADIR/work-dir" -- cgit v1.2.1