From 0288ae1b6143dfbb3344f1343b8142e4355a2ff4 Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Fri, 21 Feb 2020 13:04:24 -0500 Subject: [PATCH] Change the assertion for fileset modules In the previous module assertion we were checking the keys manually and if they didn't match we would just output the raw dictionary into the tests. This is not really useful because you have to either inspect them manually or user a local diff to know what exactly changes. This PR use DeepDiff to actually diff the two dictionary together and will output diff of the two dictionnary. This make debugging a little easier. --- filebeat/tests/system/test_modules.py | 22 ++++++++++------------ libbeat/tests/system/requirements.txt | 1 + 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/filebeat/tests/system/test_modules.py b/filebeat/tests/system/test_modules.py index b6c55e15d285..37e5e63537a1 100644 --- a/filebeat/tests/system/test_modules.py +++ b/filebeat/tests/system/test_modules.py @@ -9,6 +9,7 @@ import json import logging from parameterized import parameterized +from deepdiff import DeepDiff def load_fileset_test_cases(): @@ -197,21 +198,18 @@ def _test_expected_events(self, test_file, objects): assert len(expected) == len(objects), "expected {} events to compare but got {}".format( len(expected), len(objects)) - for ev in expected: - clean_keys(ev) - found = False - for obj in objects: + for idx in range(len(expected)): + ev = expected[idx] + obj = objects[idx] - # Flatten objects for easier comparing - obj = self.flatten_object(obj, {}, "") - clean_keys(obj) + # Flatten objects for easier comparing + obj = self.flatten_object(obj, {}, "") + clean_keys(obj) + clean_keys(ev) - if ev == obj: - found = True - break + d = DeepDiff(ev, obj, ignore_order=True) - assert found, "The following expected object was not found:\n {}\nSearched in: \n{}".format( - pretty_json(ev), pretty_json(objects)) + assert len(d) == 0, "The following expected object doesn't match:\n Diff:\n{}, full object: \n{}".format(d, obj) def clean_keys(obj): diff --git a/libbeat/tests/system/requirements.txt b/libbeat/tests/system/requirements.txt index c6a9ac33a2dc..52c360334062 100644 --- a/libbeat/tests/system/requirements.txt +++ b/libbeat/tests/system/requirements.txt @@ -31,3 +31,4 @@ parameterized==0.7.0 jsondiff==1.1.2 semver==2.8.1 stomp.py==4.1.22 +deepdiff==4.2.0