Testcases for reading system log
[gnucomo.git] / test / read_without_hostname
1 #!/bin/bash
2
3 #
4 #  Create an object 'kithira.andromeda.nl' in the database and
5 #  try to parse a piece of a syslog file without specifying the hostname.
6 #  The message should be rejected on account of an unknown host.
7
8 rm -f gcm_input.log
9
10 createdb gnucomo_test
11 result=1
12
13 if psql gnucomo_test -q <../src/database/create.sql >/dev/null
14 then
15    psql gnucomo_test -q -c "insert into object (objectname) values ('kithira.andromeda.nl')"
16    ../src/gcm_input/gcm_input -c gnucomo_test  <messages
17    NR_LOGS=`psql gnucomo_test -q -t -c "select count(*) from log"`
18    if [[ $NR_LOGS -eq 0 ]]
19    then
20       echo "No log entries in database"
21       result=0
22    fi
23    if [[ $result -eq 0 ]]
24    then
25       GCM_LOG=`cat gcm_input.log`
26       echo $GCM_LOG
27       if [[ $GCM_LOG != "Can not determine the hostname where the message came from." ]]
28       then
29          result=2
30       fi
31    fi
32    psql gnucomo_test -f ../src/database/destroy.sql -q
33    dropdb gnucomo_test
34    exit $result
35 else
36    echo Can not create test database
37    dropdb gnucomo_test
38    exit 1
39 fi