blob: 8e3f3df5a16361366f56eea9ed81dcbd58521976 [file] [log] [blame]
Paul Hobbsef4e0702016-06-27 17:01:42 -07001#!/usr/bin/python2
2
3# Copyright 2016 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""Unit tests for apache_log_metrics.py"""
8
9from __future__ import print_function
10
11import unittest
12
13import apache_log_metrics
14
15
16STATIC_REQUEST_LINE = (
17 '172.24.26.30 - - [30/Jun/2016:15:34:40 -0700] '
18 '"GET /static/veyron_minnie-release/R52-8350.46.0/'
19 'autotest_server_package.tar.bz2'
20 ' HTTP/1.1" 200 13805917 "-" "Wget/1.15 (linux-gnu)'
21)
22
23
24class TestParsers(unittest.TestCase):
25 """Tests the parsing functions in apache_log_metrics."""
26
27 def testParseStaticResponse(self):
28 match = apache_log_metrics.STATIC_GET_MATCHER.match(
29 STATIC_REQUEST_LINE)
30 self.assertTrue(match)
31
32 ip = match.group('ip_addr')
33 self.assertEqual(ip, '172.24.26.30')
34 self.assertFalse(apache_log_metrics.InLab(ip))
35
36 self.assertEqual(match.group('size'), '13805917')
37
38
39if __name__ == '__main__':
40 unittest.main()