From 5ace0aa5bdaf9424cdeb281d44a0da1e97ef72f5 Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Mon, 24 Feb 2020 11:05:20 -0500 Subject: [PATCH] Change the assertion for fileset modules (#16493) 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. (cherry picked from commit fa506a67cd7a7a284fff48e11580061c9c8afd98) --- filebeat/tests/system/test_modules.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/filebeat/tests/system/test_modules.py b/filebeat/tests/system/test_modules.py index fb802920bf0c..5f58f65a3775 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(): @@ -199,21 +200,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):