1 | #!/bin/bash |
---|
2 | #------------------------------------------------------------------------------- |
---|
3 | # Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
4 | # |
---|
5 | # This file is part of FCM, tools for managing and building source code. |
---|
6 | # |
---|
7 | # FCM is free software: you can redistribute it and/or modify |
---|
8 | # it under the terms of the GNU General Public License as published by |
---|
9 | # the Free Software Foundation, either version 3 of the License, or |
---|
10 | # (at your option) any later version. |
---|
11 | # |
---|
12 | # FCM is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | #------------------------------------------------------------------------------- |
---|
20 | # Basic tests for "fcm-recover-svn-repos". |
---|
21 | #------------------------------------------------------------------------------- |
---|
22 | . $(dirname $0)/test_header |
---|
23 | #------------------------------------------------------------------------------- |
---|
24 | if ! which svnadmin 1>/dev/null 2>/dev/null; then |
---|
25 | skip_all 'svnadmin not available' |
---|
26 | fi |
---|
27 | tests 26 |
---|
28 | #------------------------------------------------------------------------------- |
---|
29 | set -e |
---|
30 | mkdir -p etc srv/svn var/svn/{backups,cache,dumps} |
---|
31 | # Configuration |
---|
32 | export FCM_CONF_PATH="$PWD/etc" |
---|
33 | cat >etc/admin.cfg <<__CONF__ |
---|
34 | svn_backup_dir=$PWD/var/svn/backups |
---|
35 | svn_dump_dir=$PWD/var/svn/dumps |
---|
36 | svn_group= |
---|
37 | svn_live_dir=$PWD/srv/svn |
---|
38 | __CONF__ |
---|
39 | # Create some repositories and populate them |
---|
40 | # Repository 1 |
---|
41 | svnadmin create srv/svn/bar |
---|
42 | svn co -q file://$PWD/srv/svn/bar |
---|
43 | echo 'Barley drink.' >bar/barley |
---|
44 | svn add -q bar/* |
---|
45 | svn ci -q -m'test 1' bar |
---|
46 | svnadmin hotcopy srv/svn/bar var/svn/backups/bar |
---|
47 | tar -C var/svn/backups -czf $PWD/var/svn/backups/bar.tgz bar |
---|
48 | svnadmin dump srv/svn/bar -r 1 --incremental --deltas -q \ |
---|
49 | | gzip >var/svn/dumps/bar-1.gz |
---|
50 | # Repository 2 |
---|
51 | svnadmin create srv/svn/foo |
---|
52 | svn co -q file://$PWD/srv/svn/foo |
---|
53 | echo 'Number of football players = 0' >foo/football |
---|
54 | echo 'Food is yummy.' >foo/food |
---|
55 | svn add -q foo/* |
---|
56 | svn ci -q -m'test 1' foo |
---|
57 | svnadmin hotcopy srv/svn/foo var/svn/backups/foo |
---|
58 | tar -C var/svn/backups -czf $PWD/var/svn/backups/foo.tgz foo |
---|
59 | rm -fr var/svn/backups/foo |
---|
60 | echo 'Fool is a clown.' >foo/fool |
---|
61 | svn add -q foo/fool |
---|
62 | svn ci -q -m'test 2' foo |
---|
63 | for I in {1..11}; do |
---|
64 | echo "Number of football players = $I" >foo/football |
---|
65 | svn ci -q -m"incr football player" foo |
---|
66 | done |
---|
67 | for I in {1..13}; do |
---|
68 | svnadmin dump srv/svn/foo -r $I --incremental --deltas -q \ |
---|
69 | | gzip >var/svn/dumps/foo-$I.gz |
---|
70 | done |
---|
71 | rm -fr bar foo |
---|
72 | set +e |
---|
73 | #------------------------------------------------------------------------------- |
---|
74 | TEST_KEY="$TEST_KEY_BASE-live-exists" |
---|
75 | run_fail "$TEST_KEY" "$FCM_HOME/sbin/fcm-recover-svn-repos" |
---|
76 | file_cmp "$TEST_KEY.out" "$TEST_KEY.out" </dev/null |
---|
77 | file_cmp "$TEST_KEY.err" "$TEST_KEY.err" <<__ERR__ |
---|
78 | $PWD/srv/svn/bar: live repository exists. |
---|
79 | __ERR__ |
---|
80 | #------------------------------------------------------------------------------- |
---|
81 | TEST_KEY="$TEST_KEY_BASE" |
---|
82 | mv srv/svn/{bar,foo} var/svn/cache |
---|
83 | run_pass "$TEST_KEY" "$FCM_HOME/sbin/fcm-recover-svn-repos" |
---|
84 | # Check revisions |
---|
85 | for NAME in bar foo; do |
---|
86 | svnlook youngest var/svn/cache/$NAME >"$TEST_KEY-youngest-$NAME.exp" |
---|
87 | svnlook youngest srv/svn/$NAME >"$TEST_KEY-youngest-$NAME" |
---|
88 | file_cmp "$TEST_KEY-youngest-$NAME" \ |
---|
89 | "$TEST_KEY-youngest-$NAME" "$TEST_KEY-youngest-$NAME.exp" |
---|
90 | for I in $(seq 1 $(<"$TEST_KEY-youngest-$NAME.exp")); do |
---|
91 | svnlook changed -r $I var/svn/cache/$NAME \ |
---|
92 | >"$TEST_KEY-changed-$NAME-$I.exp" |
---|
93 | svnlook changed -r $I srv/svn/$NAME >"$TEST_KEY-changed-$NAME-$I" |
---|
94 | file_cmp "$TEST_KEY-changed-$NAME-$I" \ |
---|
95 | "$TEST_KEY-changed-$NAME-$I" "$TEST_KEY-changed-$NAME-$I.exp" |
---|
96 | done |
---|
97 | svn export -q file://$PWD/var/svn/cache/$NAME $NAME.orig |
---|
98 | svn export -q file://$PWD/srv/svn/$NAME $NAME |
---|
99 | FILES_ORIG=$(cd $NAME.orig; find -type f) |
---|
100 | FILES=$(cd $NAME; find -type f) |
---|
101 | run_pass "$TEST_KEY-$NAME-n-files" \ |
---|
102 | test $(wc -l <<<"$FILES_ORIG") -eq $(wc -l <<<"$FILES") |
---|
103 | for FILE in $FILES_ORIG; do |
---|
104 | file_cmp "$TEST_KEY-cmp-$NAME-$FILE" "$NAME.orig/$FILE" "$NAME/$FILE" |
---|
105 | done |
---|
106 | done |
---|
107 | #------------------------------------------------------------------------------- |
---|
108 | exit |
---|