Testcases for reading system log
[gnucomo.git] / test / read_without_hostname
diff --git a/test/read_without_hostname b/test/read_without_hostname
new file mode 100755 (executable)
index 0000000..de8cb28
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+#
+#  Create an object 'kithira.andromeda.nl' in the database and
+#  try to parse a piece of a syslog file without specifying the hostname.
+#  The message should be rejected on account of an unknown host.
+
+rm -f gcm_input.log
+
+createdb gnucomo_test
+result=1
+
+if psql gnucomo_test -q <../src/database/create.sql >/dev/null
+then
+   psql gnucomo_test -q -c "insert into object (objectname) values ('kithira.andromeda.nl')"
+   ../src/gcm_input/gcm_input -c gnucomo_test  <messages
+   NR_LOGS=`psql gnucomo_test -q -t -c "select count(*) from log"`
+   if [[ $NR_LOGS -eq 0 ]]
+   then
+      echo "No log entries in database"
+      result=0
+   fi
+   if [[ $result -eq 0 ]]
+   then
+      GCM_LOG=`cat gcm_input.log`
+      echo $GCM_LOG
+      if [[ $GCM_LOG != "Can not determine the hostname where the message came from." ]]
+      then
+         result=2
+      fi
+   fi
+   psql gnucomo_test -f ../src/database/destroy.sql -q
+   dropdb gnucomo_test
+   exit $result
+else
+   echo Can not create test database
+   dropdb gnucomo_test
+   exit 1
+fi