1#! /bin/sh 2# 3# Test suite for archive. 4 5# The count starts at 1 and is updated each time ok is printed. printcount 6# takes "ok" or "not ok". 7count=1 8printcount () { 9 echo "$1 $count $2" 10 count=`expr $count + 1` 11} 12 13# Run archive and make sure that it exits successfully. Purges the archive in 14# advance to make sure that we have fresh data. 15archive () { 16 rm -rf archive 17 mkdir -p archive 18 "$archive" -r "$@" < spool/tokens 19 if [ $? = 0 ] ; then 20 printcount "ok" 21 else 22 printcount "not ok" 23 fi 24} 25 26# Given two files, make sure that the first file exists and that its contents 27# match the contents of the second file. 28compare () { 29 if [ -r "$1" ] && diff "$1" "$2" ; then 30 printcount "ok" 31 else 32 printcount "not ok" 33 fi 34} 35 36# Find the right directory. 37sm="../../frontends/sm" 38archive="../../backends/archive" 39dirs='../data data data/storage' 40for dir in $dirs ; do 41 if [ -r "$dir/articles/1" ] ; then 42 cd $dir 43 break 44 fi 45done 46if [ ! -x "$archive" ] ; then 47 echo "Could not find archive" >&2 48 exit 1 49fi 50 51# Print out the count of tests. 52echo 17 53 54# Point programs at the appropriate inn.conf file and create our required 55# directory structure. 56INNCONF=etc/inn.conf; export INNCONF 57mkdir -p spool 58 59# Store the articles so that archive can read them using the strorage API. 60"$sm" -s < articles/1 > spool/tokens 61"$sm" -s < articles/2 >> spool/tokens 62echo '# This is a comment' >> spool/tokens 63"$sm" -s < articles/3 >> spool/tokens 64"$sm" -s < articles/bad-subj >> spool/tokens 65echo '' >> spool/tokens 66echo '# Another comment' >> spool/tokens 67"$sm" -s < articles/bad-msgid >> spool/tokens 68 69# Archive those messages with the default options. 70archive 71 72# Make sure they were written properly. 73compare archive/example/test/1 articles/1 74compare archive/example/config/1 articles/2 75compare archive/example/test/2 articles/3 76compare archive/example/config/2 articles/3 77compare archive/example/test/3 articles/bad-subj 78compare archive/example/test/4 articles/bad-msgid 79 80# Archive the same messages using a flat directory structure and writing an 81# index. 82archive -f -i archive/INDEX 83 84# Make sure they were written properly. 85compare archive/example.test/1 articles/1 86compare archive/example.config/1 articles/2 87compare archive/example.test/2 articles/3 88compare archive/example.config/2 articles/3 89compare archive/example.test/3 articles/bad-subj 90compare archive/example.test/4 articles/bad-msgid 91 92# Check the index. 93cat > archive/INDEX.right <<EOF 94example.test/1 Test article <example-1@example.com> 95example.config/1 Test article #2 <example-2@example.com> 96example.test/2 Test article #3 with a | | tab <example-3@example.com> 97example.config/2 Test article #3 with a | | tab <example-3@example.com> 98example.test/3 <none> <example-bad-subj@example.com> 99example.test/4 Test article with stray CR | | and no message ID <none> 100EOF 101compare archive/INDEX archive/INDEX.right 102 103# Archive the same messages using per-date collections of messages. Only 104# archive messages to example.config. 105archive -c -p '*.config' 106 107# Make sure they were written properly. 108( echo '-----------' ; cat articles/2 ; 109 echo '-----------' ; cat articles/3 ) > archive/check 110date=`date +%Y%m` 111compare "archive/example.config/$date" archive/check 112 113# All done. Clean up. 114rm -rf archive spool 115