Commit 10d91ee0 authored by Jérome Perrin's avatar Jérome Perrin Committed by Vincent Pelletier

tests: check for zlib/bz2 encoded logs

parent 128167a3
import unittest
import sys
import json
import bz2
import gzip
from StringIO import StringIO
import tempfile
import apachedex
......@@ -60,3 +62,30 @@ class TestCharacterEncoding(ApacheDEXTestCase):
apachedex.main()
with open(fout.name) as f:
self.assertTrue(json.load(f))
class EncodedInputTestMixin:
DEFAULT_LINE = b'127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1754'
def test(self):
with tempfile.NamedTemporaryFile() as fin, tempfile.NamedTemporaryFile() as fout:
fin.write(self._getInputData())
fin.flush()
sys.argv = ['apachedex', '--base=/', fin.name, '-f', 'json', '-o', fout.name]
apachedex.main()
self.assertNotIn('Malformed line', sys.stderr.getvalue())
with open(fout.name) as f:
self.assertTrue(json.load(f))
class TestBzip2Encoding(ApacheDEXTestCase, EncodedInputTestMixin):
def _getInputData(self):
return bz2.compress(self.DEFAULT_LINE)
class TestZlibEncoding(ApacheDEXTestCase, EncodedInputTestMixin):
def _getInputData(self):
f = StringIO()
with gzip.GzipFile(mode="w", fileobj=f) as gzfile:
gzfile.write(self.DEFAULT_LINE)
return f.getvalue()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment