mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-15 01:24:29 +02:00
add clf-s parser tests
This commit is contained in:
@ -197,7 +197,7 @@ def parse(
|
||||
streaming_line_input_type_check(line)
|
||||
output_line: Dict = {}
|
||||
|
||||
if line == '' or line == '\n':
|
||||
if not line.strip():
|
||||
continue
|
||||
|
||||
clf_match = re.match(clf_pattern, line)
|
||||
|
1
tests/fixtures/generic/common-log-format-streaming.json
vendored
Normal file
1
tests/fixtures/generic/common-log-format-streaming.json
vendored
Normal file
File diff suppressed because one or more lines are too long
50
tests/test_clf_s.py
Normal file
50
tests/test_clf_s.py
Normal file
@ -0,0 +1,50 @@
|
||||
import os
|
||||
import json
|
||||
import unittest
|
||||
from typing import Dict
|
||||
from jc.parsers.clf_s import parse
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# To create streaming output use:
|
||||
# $ cat clf.out | jc --clf-s | jello -c > clf-streaming.json
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
f_in: Dict = {}
|
||||
f_json: Dict = {}
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
fixtures = {
|
||||
'clf_s': (
|
||||
'fixtures/generic/common-log-format.log',
|
||||
'fixtures/generic/common-log-format-streaming.json')
|
||||
}
|
||||
|
||||
for file, filepaths in fixtures.items():
|
||||
with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as a, \
|
||||
open(os.path.join(THIS_DIR, filepaths[1]), 'r', encoding='utf-8') as b:
|
||||
cls.f_in[file] = a.read()
|
||||
cls.f_json[file] = json.loads(b.read())
|
||||
|
||||
|
||||
def test_clf_s_nodata(self):
|
||||
"""
|
||||
Test 'clf-s' with no data
|
||||
"""
|
||||
self.assertEqual(list(parse([], quiet=True)), [])
|
||||
|
||||
|
||||
def test_clf_s_centos_7_7(self):
|
||||
"""
|
||||
Test 'clf-s' with various logs
|
||||
"""
|
||||
self.assertEqual(
|
||||
list(parse(self.f_in['clf_s'].splitlines(), quiet=True)),
|
||||
self.f_json['clf_s']
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user