Skip to content

Commit

Permalink
system-tests: make it possible to test more than 10 logs
Browse files Browse the repository at this point in the history
Previously, only 10 logs could be in *.log and *-expected.json files,
as it is the default page size of ES. However, to be more future proof
the test was extended, so it can validate more than 10 logs and events.
  • Loading branch information
kvch committed Aug 3, 2017
1 parent bd3c901 commit c36915d
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions filebeat/tests/system/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ def test_modules(self):
test_file=test_file,
cfgfile=cfgfile)

def _test_expected_events(self, module, test_file, res, objects):
with open(test_file + "-expected.json", "r") as f:
expected = json.load(f)

if len(expected) > len(objects):
res = self.es.search(index=self.index_name,
body={"query": {"match_all": {}},
"size": len(expected)})
objects = [o["_source"] for o in res["hits"]["hits"]]

assert len(expected) == res['hits']['total'], "expected {} but got {}".format(len(expected), len(objects))

for ev in expected:
found = False
for obj in objects:
if ev["_source"][module] == obj[module]:
found = True
break
assert found, "The following expected object was not found: {}".format(obj)

def run_on_file(self, module, fileset, test_file, cfgfile):
print("Testing {}/{} on {}".format(module, fileset, test_file))

Expand Down Expand Up @@ -116,18 +136,7 @@ def run_on_file(self, module, fileset, test_file, cfgfile):
self.assert_fields_are_documented(obj)

if os.path.exists(test_file + "-expected.json"):
with open(test_file + "-expected.json", "r") as f:
expected = json.load(f)
assert len(expected) == len(objects), "expected {} but got {}".format(len(expected), len(objects))
for ev in expected:
found = False
for obj in objects:
if ev["_source"][module] == obj[module]:
found = True
break
if not found:
raise Exception("The following expected object was" +
" not found: {}".format(obj))
self._test_expected_events(module, test_file, res, objects)

@unittest.skipIf(not INTEGRATION_TESTS or
os.getenv("TESTING_ENVIRONMENT") == "2x",
Expand Down

0 comments on commit c36915d

Please sign in to comment.