Fix PR10: Gcm_input may loose its input message
[gnucomo.git] / test / read_no_database
1 #!/bin/bash
2
3 #
4 #  Try to read a syslog file and store in a database that does not exist.
5 #  gcm_input should return an error and save the input in an XML file.
6
7
8 rm -f gcm_input.log
9
10 createdb gnucomo_test
11 result=1
12
13
14 if psql gnucomo_test -q <../src/database/create.sql >/dev/null
15 then
16    psql gnucomo_test -q -c "insert into object (objectname) values ('example1.gnucomo.test')"
17    ../src/gcm_input/gcm_input -c gnucomo_nodb -h example1.gnucomo.test -d 'sep 5 2002 20:30:45' <messages
18    result=$?
19    echo "gcm_input returned $result"
20
21    if [[ $result -eq 1 ]]
22    then
23       # check if nothing was stored in the (existing) database
24       NR_LOGS=`psql gnucomo_test -q -t -c "select count(*) from log"`
25       if [[ $NR_LOGS -eq 0 ]]
26       then
27          echo "No log entries in database"
28          result=0
29       fi
30       # check if the saved XML file exists
31       SAVEDFILE=`grep 'XML content stored' gcm_input.log |cut -d ' ' -f 12`
32       echo "Saved file is $SAVEDFILE"
33       if [[ ! -e $SAVEDFILE ]]
34       then
35          echo $SAVEDFILE does not exist.
36          result=2
37       fi
38       rm $SAVEDFILE   # cleanup
39    else
40       echo "gcm_input did not return an error"
41       result=1
42    fi
43    psql gnucomo_test -f ../src/database/destroy.sql -q
44 else
45    echo Can not create test database
46 fi
47
48 dropdb gnucomo_test
49 exit $result