Commits

Alexis Lê-Quôc  committed 7e0fc0f

First test in place

  • Participants
  • Parent commits 1c3c3ff

Comments (0)

Files changed (3)

File src/ApacheLogtailer.py

                 }
         regex = r"^"
         for directive in log_format.split():
-            logger.debug("directive: %s" % (directive,))
             rg = xlate.get(directive, None)
-            logger.debug("regex: %s" % (rg,))
+            logger.debug("directive: %s -> %s" % (directive, rg))
             if rg is not None:
                 if len(regex) > 1:
                     regex += " "

File src/ganglia-logtailer

                 # this is our first run or our state file got nuked.
                 # write out a new state file and exit
                 logger.info('First run or state file got nuked.  Wrote new state file. Exiting.')
-                input = os.popen(shell_tail)
+                _input = os.popen(shell_tail)
                 retval = input.close()
                 if( retval != 256 ):
-                    logger.warning('%s returned bad exit code %s' %
-                                   (shell_tail, retval))
+                    logger.warning('%s returned bad exit code %s' % (shell_tail, retval))
                 end_locking(lockfile, logtail_lock_file)
                 sys.exit(0)
             _input = os.popen(shell_tail)
         except Exception, e:
             # note - there is no exception when shell-tailer doesn't exist.
             # I don't know when this exception will ever actually be triggered.
-            print ("Failed to run %s to get log data (line %s): %s" %
-                   (shell_tail, lineno(), e))
+            logging.exception("Failed to run %s to get log data: %s" % (shell_tail, e))
             end_locking(lockfile, logtail_lock_file)
             sys.exit(1)
     else:

File tests/test_apache.py

+import unittest
+from ApacheLogtailer import *
+
+class TestApacheLogtailer(unittest.TestCase):
+    def setUp(self):
+        self.loglines = open("tests/access.log").readlines()
+        self.tailer = ApacheLogtailer()
+        
+    def testParseLine(self):
+        for line in self.loglines:
+            hits = self.tailer.num_hits
+            self.tailer.parse_line(line)
+            self.assertEquals(self.tailer.num_hits, hits + 1)
+            
+if __name__ == "__main__":
+    unittest.main()