Rsync replacement scripts, uses Perl to pull changed files to mirrors. The changes...
[mir.git] / scripts / mirror-scripts / testupdate.sh
1 #!/bin/sh
2
3 # This script will run tests with the update script to ensure
4 # that all is good :)
5
6 SCRIPT=/home/mish/active/indymedia/mirror-scripts/update.pl
7
8 TESTDIR=/tmp/test_updatemirror
9 CHANGEDIR=$TESTDIR/changes
10 STATEDIR=$TESTDIR/state
11
12 LASTUPDATEFILE=$STATEDIR/lastupdate.txt
13 OUTPUTFILE=$TESTDIR/out.txt
14 CORRECTFILE=$TESTDIR/correct.txt
15
16 # set up - set up the directories and files required
17 setup ()
18 {
19         # first remove anything left
20         rm -rf $TESTDIR
21
22         # create the directory and copy the files we need to it
23         mkdir -p $CHANGEDIR
24         mkdir -p $STATEDIR
25         cp change*.txt $TESTDIR/
26         return
27 }
28
29 # teardown - remove all stuff so that next time is clean
30 teardown ()
31 {
32         # do we want to wait before tear down
33         if [ "$INTERACTIVE" == "i" ]; then
34                 echo "Press any key to continue to next test"
35                 read -n1
36         fi
37
38         rm -rf $TESTDIR
39         return
40 }
41
42 # setlastupdate - set the last update date/time
43 # pass the date/time as YYYY MM DD hh mm ss
44 setlastupdate ()
45 {
46         # set the format as for `date -s %Y/%m/%d %H:%M:%S`
47         # or use that if no argument is set
48         if [ "$#" -eq "0" ]; then
49                 date +"%Y:%m:%dT%H:%M:%S" > $LASTUPDATEFILE
50         else
51                 echo "$1:$2:$3T$4:$5:$6" > $LASTUPDATEFILE
52         fi
53         return
54 }
55
56 # get the list of change files - one day only
57 testChangeFileListOneDay ()
58 {
59         setup 
60         setlastupdate 2006 06 22 16 13 11
61         $SCRIPT --test \
62                 --workingdir=$TESTDIR \
63                 --list-change-files \
64                 --now="2006:06:22T16:31:11.01" \
65                 --output=$OUTPUTFILE
66         # check output file
67         echo "/changes/changes20060622.txt" > $CORRECTFILE
68         diff $OUTPUTFILE $CORRECTFILE
69         if [ "$?" -ne "0" ]; then
70                 echo "*** FAILED testChangeFileListOneDay ***"
71         else
72                 echo "Passed testChangeFileListOneDay"
73         fi
74  
75         teardown 
76 }
77
78
79 # generic test 
80 testGeneric ()
81 {
82         setup 
83         teardown 
84 }
85
86 # do we want to do tests interactively
87 if [ $# -eq 0 ]; then
88         INTERACTIVE=0
89 else
90         INTERACTIVE=$1
91 fi
92
93
94 # do the tests
95 testGeneric
96 testChangeFileListOneDay