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