source: LMDZ6/branches/Amaury_dev/tools/fcm/t/fcm-install-svn-hook/00-basic.t @ 5095

Last change on this file since 5095 was 5095, checked in by abarral, 4 months ago

Revert cosp*/ from the trunk, as it's external code
Add missing bits from FCM2 source

  • Property svn:executable set to *
File size: 6.1 KB
Line 
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#-------------------------------------------------------------------------------
24if ! which svnadmin 1>/dev/null 2>/dev/null; then
25    skip_all 'svnadmin not available'
26fi
27tests 173
28#-------------------------------------------------------------------------------
29FCM_REAL_HOME=$(readlink -f "$FCM_HOME")
30TODAY=$(date -u +%Y%m%d)
31mkdir -p conf/
32export FCM_CONF_PATH="$PWD/conf"
33cat >conf/admin.cfg <<__CONF__
34fcm_site_home=$PWD
35svn_group=
36svn_live_dir=$PWD/svn-repos
37svn_project_suffix=
38__CONF__
39cat >hooks-env <<__CONF__
40[default]
41FCM_HOME=$FCM_REAL_HOME
42FCM_SITE_HOME=$PWD
43FCM_SVN_HOOK_ADMIN_EMAIL=$USER
44FCM_SVN_HOOK_COMMIT_DUMP_DIR=/var/svn/dumps
45FCM_SVN_HOOK_TRAC_ROOT_DIR=/srv/trac
46TZ=UTC
47__CONF__
48#-------------------------------------------------------------------------------
49# Live directory does not exist
50TEST_KEY="$TEST_KEY_BASE-no-live-dir"
51run_pass "$TEST_KEY" "$FCM_HOME/sbin/fcm-install-svn-hook"
52file_cmp "$TEST_KEY.out" "$TEST_KEY.out" /dev/null
53file_cmp "$TEST_KEY.err" "$TEST_KEY.err" /dev/null
54#-------------------------------------------------------------------------------
55# Project does not exist
56TEST_KEY="$TEST_KEY_BASE-no-project"
57run_fail "$TEST_KEY" "$FCM_HOME/sbin/fcm-install-svn-hook" foo
58file_cmp "$TEST_KEY.out" "$TEST_KEY.out" /dev/null
59file_cmp "$TEST_KEY.err" "$TEST_KEY.err" <<'__ERR__'
60foo: not found
61__ERR__
62#-------------------------------------------------------------------------------
63# Live directory is empty
64TEST_KEY="$TEST_KEY_BASE-empty"
65mkdir svn-repos
66run_pass "$TEST_KEY" "$FCM_HOME/sbin/fcm-install-svn-hook"
67file_cmp "$TEST_KEY.out" "$TEST_KEY.out" /dev/null
68file_cmp "$TEST_KEY.err" "$TEST_KEY.err" /dev/null
69#-------------------------------------------------------------------------------
70run_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
116TEST_KEY="$TEST_KEY_BASE-new"
117NAME=new run_tests
118TEST_KEY="$TEST_KEY_BASE-new-foo"
119NAME=new run_tests foo
120
121# Clean install, single repository
122TEST_KEY="$TEST_KEY_BASE-clean"
123NAME=clean run_tests --clean
124TEST_KEY="$TEST_KEY_BASE-clean-foo"
125NAME=clean run_tests --clean foo
126
127# New install, single repository, with svnperms.conf
128TEST_KEY="$TEST_KEY_BASE-svnperms.conf"
129mkdir -p 'svn-import'
130echo '[foo]' >'svn-import/svnperms.conf'
131NAME='svnperms-conf' run_tests
132file_cmp "$TEST_KEY-cmp" \
133    'svn-repos/foo/hooks/svnperms.conf' 'svn-import/svnperms.conf'
134
135# New install, single repository, with commit.conf
136TEST_KEY="$TEST_KEY_BASE-commit.conf"
137{
138    echo 'notify-branch-owner'
139    echo 'verify-branch-owner'
140} >'svn-import/commit.conf'
141NAME='commit-conf' run_tests
142file_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
146TEST_KEY="$TEST_KEY_BASE-commit.conf-site-override"
147{
148    echo 'notify-branch-owner'
149    echo 'verify-branch-owner'
150} >'svn-import/commit.conf'
151mkdir -p 'svn-hooks/foo'
152{
153    echo '# This is the override'
154    echo '# It is actually empty'
155} >'svn-hooks/foo/commit.conf'
156NAME='commit-conf-site-override' run_tests
157file_cmp "$TEST_KEY-cmp" \
158    'svn-repos/foo/hooks/commit.conf' 'svn-hooks/foo/commit.conf'
159rm -fr 'svn-hooks'
160#-------------------------------------------------------------------------------
161exit
Note: See TracBrowser for help on using the repository browser.