New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
00-basic.t in vendors/FCM-2017.10.0/t/fcm-install-svn-hook – NEMO

source: vendors/FCM-2017.10.0/t/fcm-install-svn-hook/00-basic.t @ 11668

Last change on this file since 11668 was 10672, checked in by nicolasmartin, 5 years ago

Reimport latest FCM release

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