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.
01-housekeep-log.t in vendors/FCM-2017.10.0/t/fcm-install-svn-hook – NEMO

source: vendors/FCM-2017.10.0/t/fcm-install-svn-hook/01-housekeep-log.t @ 13688

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

Reimport latest FCM release

File size: 8.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# Tests housekeep hook logs functionalities provided by "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 14
29#-------------------------------------------------------------------------------
30FCM_REAL_HOME=$(readlink -f "$FCM_HOME")
31TODAY=$(date -u +%Y%m%d)
32mkdir -p conf/ svn-repos/
33export FCM_CONF_PATH="$PWD/conf"
34cat >conf/admin.cfg <<__CONF__
35svn_group=
36svn_live_dir=$PWD/svn-repos
37svn_project_suffix=
38__CONF__
39#-------------------------------------------------------------------------------
40# Newly created logs
41svnadmin create svn-repos/bar
42svnadmin create svn-repos/foo
43
44# 1st run, create logs
45KEY="0-cmd0"
46TEST_KEY="$TEST_KEY_BASE-$KEY"
47run_pass "$TEST_KEY" "$FCM_HOME/sbin/fcm-install-svn-hook"
48date2datefmt "$TEST_KEY.out" >"$TEST_KEY.out.parsed"
49m4 -DFCM_HOME="$FCM_REAL_HOME" -DPWD="$PWD" -DTODAY="$TODAY" \
50    "$TEST_SOURCE_DIR/$TEST_KEY_BASE/$KEY.out" >"$TEST_KEY.out.exp"
51diff -u "$TEST_KEY.out.parsed" "$TEST_KEY.out.exp" >&2
52file_cmp "$TEST_KEY.out" "$TEST_KEY.out.parsed" "$TEST_KEY.out.exp"
53
54# Add something to logs between runs
55for FILE in svn-repos/{foo,bar}/log/*.log; do
56    echo "$FILE: time passes, and contents were written to me." >"$FILE"
57done
58sha1sum svn-repos/{foo,bar}/log/*.log >logs.shalsum
59#-------------------------------------------------------------------------------
60# 2nd run on same day, should leave logs alone
61KEY="0-cmd1"
62TEST_KEY="$TEST_KEY_BASE-$KEY"
63run_pass "$TEST_KEY" "$FCM_HOME/sbin/fcm-install-svn-hook"
64date2datefmt "$TEST_KEY.out" >"$TEST_KEY.out.parsed"
65m4 -DFCM_HOME="$FCM_REAL_HOME" -DPWD="$PWD" -DTODAY="$TODAY" \
66    "$TEST_SOURCE_DIR/$TEST_KEY_BASE/$KEY.out" >"$TEST_KEY.out.exp"
67file_cmp "$TEST_KEY.out" "$TEST_KEY.out.parsed" "$TEST_KEY.out.exp"
68# Logs should not be modified
69run_pass "$TEST_KEY.sha1sum" sha1sum -c logs.shalsum
70#-------------------------------------------------------------------------------
71# Pretend that logs were created 3 days ago
72TEST_KEY="$TEST_KEY_BASE-3"
73DATE_P3D=$(date --date='3 days ago' +%Y%m%d)
74
75# Add something to logs
76# Pretend that they were created 3 days ago
77for FILE in svn-repos/{foo,bar}/log/*.log; do
78    echo "$FILE: time flies in the world of testing." >>"$FILE"
79    NAME=$(readlink "$FILE")
80    mv "$(dirname $FILE)/$NAME" "$FILE.$DATE_P3D"
81    ln -f -s "$(basename $FILE).$DATE_P3D" "$FILE"
82done
83sha1sum svn-repos/{foo,bar}/log/*.log >logs.shalsum
84
85# Run with logs created 3 days ago
86# STDOUT should be identical to "0-cmd1".
87run_pass "$TEST_KEY" "$FCM_HOME/sbin/fcm-install-svn-hook"
88date2datefmt "$TEST_KEY.out" >"$TEST_KEY.out.parsed"
89m4 -DFCM_HOME="$FCM_REAL_HOME" -DPWD="$PWD" -DTODAY="$TODAY" \
90    "$TEST_SOURCE_DIR/$TEST_KEY_BASE/0-cmd1.out" >"$TEST_KEY.out.exp"
91file_cmp "$TEST_KEY.out" "$TEST_KEY.out.parsed" "$TEST_KEY.out.exp"
92
93# Logs should not be modified
94run_pass "$TEST_KEY.sha1sum" sha1sum -c logs.shalsum
95#-------------------------------------------------------------------------------
96# Pretend that logs were created 7 days ago
97TEST_KEY="$TEST_KEY_BASE-7"
98DATE_P7D=$(date --date='7 days ago' +%Y%m%d)
99
100# Add something to logs
101# Pretend that they were created 7 days ago
102for FILE in svn-repos/{foo,bar}/log/*.log; do
103    echo "$FILE: time continues to fly in the world of testing." >>"$FILE"
104    NAME=$(readlink "$FILE")
105    mv "$(dirname $FILE)/$NAME" "$FILE.$DATE_P7D"
106    ln -f -s "$(basename $FILE).$DATE_P7D" "$FILE"
107done
108sha1sum svn-repos/{foo,bar}/log/*.log >logs.shalsum
109
110# Run with logs created 7 days ago, should gzip old logs and create new ones
111run_pass "$TEST_KEY" "$FCM_HOME/sbin/fcm-install-svn-hook"
112date2datefmt "$TEST_KEY.out" >"$TEST_KEY.out.parsed"
113m4 -DFCM_HOME="$FCM_REAL_HOME" -DPWD="$PWD" -DTODAY="$TODAY" \
114    -DDATE_P7D="$DATE_P7D" \
115    "$TEST_SOURCE_DIR/$TEST_KEY_BASE/7-cmd.out" >"$TEST_KEY.out.exp"
116file_cmp "$TEST_KEY.out" "$TEST_KEY.out.parsed" "$TEST_KEY.out.exp"
117
118# Unzip old logs and check that their contents are unchanged
119mkdir -p old-logs/svn-repos/{foo,bar}/log
120for FILE in svn-repos/{foo,bar}/log/*.log.*.gz; do
121    gunzip -c "$FILE" >old-logs/${FILE%.$DATE_P7D.gz}
122done
123cd old-logs
124run_pass "$TEST_KEY.sha1sum" sha1sum -c ../logs.shalsum
125cd "$OLDPWD"
126#-------------------------------------------------------------------------------
127# Pretend that logs were created between 7 to 28 days ago
128TEST_KEY="$TEST_KEY_BASE-28"
129DATE_P14D=$(date --date='14 days ago' +%Y%m%d)
130DATE_P21D=$(date --date='21 days ago' +%Y%m%d)
131DATE_P28D=$(date --date='28 days ago' +%Y%m%d)
132
133# Create fake logs
134rm -f svn-repos/{foo,bar}/log/*.log*
135for FILE in svn-repos/{foo,bar}/log/{pre,post}-commit.log; do
136    for DATE in $DATE_P14D $DATE_P21D $DATE_P28D; do
137        echo "$FILE $DATE whatever" >"$FILE.$DATE"
138        gzip "$FILE.$DATE"
139    done
140    echo "$FILE $DATE_P7D whatever" >"$FILE.$DATE_P7D"
141    ln -s $(basename "$FILE.$DATE_P7D") "$FILE"
142done
143for FILE in svn-repos/{foo,bar}/log/{pre,post}-revprop-change.log; do
144    echo "$FILE $DATE_P7D whatever" >"$FILE.$DATE_P7D"
145    ln -s $(basename "$FILE.$DATE_P7D") "$FILE"
146done
147
148# Run with logs created 7 to 28 days ago.
149# Should remove oldest and empty ones, gzip old ones and create new ones
150run_pass "$TEST_KEY" "$FCM_HOME/sbin/fcm-install-svn-hook"
151date2datefmt "$TEST_KEY.out" >"$TEST_KEY.out.parsed"
152m4 -DFCM_HOME="$FCM_REAL_HOME" -DPWD="$PWD" -DTODAY="$TODAY" \
153    -DDATE_P7D="$DATE_P7D" -DDATE_P28D="$DATE_P28D" \
154    "$TEST_SOURCE_DIR/$TEST_KEY_BASE/28-cmd.out" >"$TEST_KEY.out.exp"
155file_cmp "$TEST_KEY.out" "$TEST_KEY.out.parsed" "$TEST_KEY.out.exp"
156ls svn-repos/{foo,bar}/log/*.log* | sort >"$TEST_KEY.ls.out"
157file_cmp "$TEST_KEY.ls" "$TEST_KEY.ls.out" <<__LIST__
158svn-repos/bar/log/post-commit.log
159svn-repos/bar/log/post-commit.log.$DATE_P21D.gz
160svn-repos/bar/log/post-commit.log.$DATE_P14D.gz
161svn-repos/bar/log/post-commit.log.$DATE_P7D.gz
162svn-repos/bar/log/post-commit.log.$TODAY
163svn-repos/bar/log/post-revprop-change.log
164svn-repos/bar/log/post-revprop-change.log.$DATE_P7D.gz
165svn-repos/bar/log/post-revprop-change.log.$TODAY
166svn-repos/bar/log/pre-commit.log
167svn-repos/bar/log/pre-commit.log.$DATE_P21D.gz
168svn-repos/bar/log/pre-commit.log.$DATE_P14D.gz
169svn-repos/bar/log/pre-commit.log.$DATE_P7D.gz
170svn-repos/bar/log/pre-commit.log.$TODAY
171svn-repos/bar/log/pre-revprop-change.log
172svn-repos/bar/log/pre-revprop-change.log.$DATE_P7D.gz
173svn-repos/bar/log/pre-revprop-change.log.$TODAY
174svn-repos/foo/log/post-commit.log
175svn-repos/foo/log/post-commit.log.$DATE_P21D.gz
176svn-repos/foo/log/post-commit.log.$DATE_P14D.gz
177svn-repos/foo/log/post-commit.log.$DATE_P7D.gz
178svn-repos/foo/log/post-commit.log.$TODAY
179svn-repos/foo/log/post-revprop-change.log
180svn-repos/foo/log/post-revprop-change.log.$DATE_P7D.gz
181svn-repos/foo/log/post-revprop-change.log.$TODAY
182svn-repos/foo/log/pre-commit.log
183svn-repos/foo/log/pre-commit.log.$DATE_P21D.gz
184svn-repos/foo/log/pre-commit.log.$DATE_P14D.gz
185svn-repos/foo/log/pre-commit.log.$DATE_P7D.gz
186svn-repos/foo/log/pre-commit.log.$TODAY
187svn-repos/foo/log/pre-revprop-change.log
188svn-repos/foo/log/pre-revprop-change.log.$DATE_P7D.gz
189svn-repos/foo/log/pre-revprop-change.log.$TODAY
190__LIST__
191#-------------------------------------------------------------------------------
192exit
Note: See TracBrowser for help on using the repository browser.