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-install-svn-hook". |
---|
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 173 |
---|
28 | #------------------------------------------------------------------------------- |
---|
29 | FCM_REAL_HOME=$(readlink -f "$FCM_HOME") |
---|
30 | TODAY=$(date -u +%Y%m%d) |
---|
31 | mkdir -p conf/ |
---|
32 | export FCM_CONF_PATH="$PWD/conf" |
---|
33 | cat >conf/admin.cfg <<__CONF__ |
---|
34 | fcm_site_home=$PWD |
---|
35 | svn_group= |
---|
36 | svn_live_dir=$PWD/svn-repos |
---|
37 | svn_project_suffix= |
---|
38 | __CONF__ |
---|
39 | cat >hooks-env <<__CONF__ |
---|
40 | [default] |
---|
41 | FCM_HOME=$FCM_REAL_HOME |
---|
42 | FCM_SITE_HOME=$PWD |
---|
43 | FCM_SVN_HOOK_ADMIN_EMAIL=$USER |
---|
44 | FCM_SVN_HOOK_COMMIT_DUMP_DIR=/var/svn/dumps |
---|
45 | FCM_SVN_HOOK_TRAC_ROOT_DIR=/srv/trac |
---|
46 | TZ=UTC |
---|
47 | __CONF__ |
---|
48 | #------------------------------------------------------------------------------- |
---|
49 | # Live directory does not exist |
---|
50 | TEST_KEY="$TEST_KEY_BASE-no-live-dir" |
---|
51 | run_pass "$TEST_KEY" "$FCM_HOME/sbin/fcm-install-svn-hook" |
---|
52 | file_cmp "$TEST_KEY.out" "$TEST_KEY.out" /dev/null |
---|
53 | file_cmp "$TEST_KEY.err" "$TEST_KEY.err" /dev/null |
---|
54 | #------------------------------------------------------------------------------- |
---|
55 | # Project does not exist |
---|
56 | TEST_KEY="$TEST_KEY_BASE-no-project" |
---|
57 | run_fail "$TEST_KEY" "$FCM_HOME/sbin/fcm-install-svn-hook" foo |
---|
58 | file_cmp "$TEST_KEY.out" "$TEST_KEY.out" /dev/null |
---|
59 | file_cmp "$TEST_KEY.err" "$TEST_KEY.err" <<'__ERR__' |
---|
60 | foo: not found |
---|
61 | __ERR__ |
---|
62 | #------------------------------------------------------------------------------- |
---|
63 | # Live directory is empty |
---|
64 | TEST_KEY="$TEST_KEY_BASE-empty" |
---|
65 | mkdir svn-repos |
---|
66 | run_pass "$TEST_KEY" "$FCM_HOME/sbin/fcm-install-svn-hook" |
---|
67 | file_cmp "$TEST_KEY.out" "$TEST_KEY.out" /dev/null |
---|
68 | file_cmp "$TEST_KEY.err" "$TEST_KEY.err" /dev/null |
---|
69 | #------------------------------------------------------------------------------- |
---|
70 | run_tests() { |
---|
71 | # Create repository and add content if necessary |
---|
72 | rm -fr svn-repos/foo |
---|
73 | svnadmin create svn-repos/foo |
---|
74 | if [[ -d svn-import ]]; then |
---|
75 | svn import -q -m't' svn-import file://$PWD/svn-repos/foo |
---|
76 | fi |
---|
77 | # Hooks before |
---|
78 | local HOOK_TMPLS=$(ls svn-repos/foo/hooks/*) |
---|
79 | # Install |
---|
80 | run_pass "$TEST_KEY" "$FCM_HOME/sbin/fcm-install-svn-hook" "$@" |
---|
81 | # Hooks env |
---|
82 | file_cmp "$TEST_KEY-hooks-env" svn-repos/foo/conf/hooks-env hooks-env |
---|
83 | # Make sure all hooks are installed |
---|
84 | local FILE= |
---|
85 | for FILE in $(cd "$FCM_HOME/etc/svn-hooks" && ls); do |
---|
86 | file_cmp "$TEST_KEY-$FILE" \ |
---|
87 | "$FCM_HOME/etc/svn-hooks/$FILE" "svn-repos/foo/hooks/$FILE" |
---|
88 | file_test "$TEST_KEY-$FILE-chmod" "svn-repos/foo/hooks/$FILE" -x |
---|
89 | file_test "$TEST_KEY-$FILE.log.$TODAY" \ |
---|
90 | "svn-repos/foo/log/$FILE.log.$TODAY" |
---|
91 | readlink "svn-repos/foo/log/$FILE.log" >"$TEST_KEY-$FILE.log.link" |
---|
92 | file_cmp "$TEST_KEY-$FILE.log" \ |
---|
93 | "$TEST_KEY-$FILE.log.link" <<<"$FILE.log.$TODAY" |
---|
94 | done |
---|
95 | # Hooks after |
---|
96 | if [[ "$@" == *--clean* ]]; then |
---|
97 | run_fail "$TEST_KEY-ls-tmpl" ls $HOOK_TMPLS |
---|
98 | else |
---|
99 | run_pass "$TEST_KEY-ls-tmpl" ls $HOOK_TMPLS |
---|
100 | fi |
---|
101 | # STDOUT and STDERR |
---|
102 | date2datefmt "$TEST_KEY.out" >"$TEST_KEY.out.parsed" |
---|
103 | m4 -DFCM_REAL_HOME=$FCM_REAL_HOME -DPWD=$PWD -DTODAY=$TODAY \ |
---|
104 | "$TEST_SOURCE_DIR/$TEST_KEY_BASE/$NAME.out" >"$TEST_KEY.out.exp" |
---|
105 | file_cmp "$TEST_KEY.out" "$TEST_KEY.out.parsed" "$TEST_KEY.out.exp" |
---|
106 | file_cmp "$TEST_KEY.err" "$TEST_KEY.err" /dev/null |
---|
107 | # Run command a second time, should no longer install logs |
---|
108 | run_pass "$TEST_KEY-2" "$FCM_HOME/sbin/fcm-install-svn-hook" "$@" |
---|
109 | date2datefmt "$TEST_KEY-2.out" >"$TEST_KEY-2.out.parsed" |
---|
110 | m4 -DFCM_REAL_HOME=$FCM_REAL_HOME -DPWD=$PWD \ |
---|
111 | "$TEST_SOURCE_DIR/$TEST_KEY_BASE/$NAME-2.out" >"$TEST_KEY-2.out.exp" |
---|
112 | file_cmp "$TEST_KEY-2.out" "$TEST_KEY-2.out.parsed" "$TEST_KEY-2.out.exp" |
---|
113 | } |
---|
114 | |
---|
115 | # New install, single repository |
---|
116 | TEST_KEY="$TEST_KEY_BASE-new" |
---|
117 | NAME=new run_tests |
---|
118 | TEST_KEY="$TEST_KEY_BASE-new-foo" |
---|
119 | NAME=new run_tests foo |
---|
120 | |
---|
121 | # Clean install, single repository |
---|
122 | TEST_KEY="$TEST_KEY_BASE-clean" |
---|
123 | NAME=clean run_tests --clean |
---|
124 | TEST_KEY="$TEST_KEY_BASE-clean-foo" |
---|
125 | NAME=clean run_tests --clean foo |
---|
126 | |
---|
127 | # New install, single repository, with svnperms.conf |
---|
128 | TEST_KEY="$TEST_KEY_BASE-svnperms.conf" |
---|
129 | mkdir -p 'svn-import' |
---|
130 | echo '[foo]' >'svn-import/svnperms.conf' |
---|
131 | NAME='svnperms-conf' run_tests |
---|
132 | file_cmp "$TEST_KEY-cmp" \ |
---|
133 | 'svn-repos/foo/hooks/svnperms.conf' 'svn-import/svnperms.conf' |
---|
134 | |
---|
135 | # New install, single repository, with commit.conf |
---|
136 | TEST_KEY="$TEST_KEY_BASE-commit.conf" |
---|
137 | { |
---|
138 | echo 'notify-branch-owner' |
---|
139 | echo 'verify-branch-owner' |
---|
140 | } >'svn-import/commit.conf' |
---|
141 | NAME='commit-conf' run_tests |
---|
142 | file_cmp "$TEST_KEY-cmp" \ |
---|
143 | 'svn-repos/foo/hooks/commit.conf' 'svn-import/commit.conf' |
---|
144 | |
---|
145 | # New install, single repository, with commit.conf and site override |
---|
146 | TEST_KEY="$TEST_KEY_BASE-commit.conf-site-override" |
---|
147 | { |
---|
148 | echo 'notify-branch-owner' |
---|
149 | echo 'verify-branch-owner' |
---|
150 | } >'svn-import/commit.conf' |
---|
151 | mkdir -p 'svn-hooks/foo' |
---|
152 | { |
---|
153 | echo '# This is the override' |
---|
154 | echo '# It is actually empty' |
---|
155 | } >'svn-hooks/foo/commit.conf' |
---|
156 | NAME='commit-conf-site-override' run_tests |
---|
157 | file_cmp "$TEST_KEY-cmp" \ |
---|
158 | 'svn-repos/foo/hooks/commit.conf' 'svn-hooks/foo/commit.conf' |
---|
159 | rm -fr 'svn-hooks' |
---|
160 | #------------------------------------------------------------------------------- |
---|
161 | exit |
---|