apache_log_metrics.py: Fix "ip_addr" group match
A bug was introduced by switching to named regex match groups - the
ip_addr group was referenced as "ipaddr".
BUG=chromium:630776
TEST=added a unit test.
Change-Id: I6a51c2c18aeffc2fbda53446c5e5690ae53060cc
Reviewed-on: https://chromium-review.googlesource.com/362588
Reviewed-by: Richard Barnette <jrbarnette@google.com>
Tested-by: Paul Hobbs <phobbs@google.com>
diff --git a/apache_log_metrics_unittest.py b/apache_log_metrics_unittest.py
index 8e3f3df..ae73186 100755
--- a/apache_log_metrics_unittest.py
+++ b/apache_log_metrics_unittest.py
@@ -8,6 +8,7 @@
from __future__ import print_function
+import mock
import unittest
import apache_log_metrics
@@ -36,5 +37,17 @@
self.assertEqual(match.group('size'), '13805917')
+class TestEmitters(unittest.TestCase):
+ """Tests the emitter functions in apache_log_metrics."""
+
+ def testEmitStaticResponse(self):
+ match = apache_log_metrics.STATIC_GET_MATCHER.match(
+ STATIC_REQUEST_LINE)
+ # Calling the emitter should not raise any exceptions (for example, by
+ # referencing regex match groups that don't exist.
+ with mock.patch.object(apache_log_metrics, 'metrics'):
+ apache_log_metrics.EmitStaticRequestMetric(match)
+
+
if __name__ == '__main__':
unittest.main()