From 519003edee5b4a8dae52ae1b9e9ae9f6601e89f1 Mon Sep 17 00:00:00 2001 From: Terje Kvernes Date: Mon, 15 Jan 2024 12:55:14 +0100 Subject: [PATCH] Filter away timestamps from diffs, increase testing. (#199) * Filter away timestamps from diffs, increase testing. - This PR filters away timestamps from test results via a regexp. - The timestamps are replaced inline so other content in the same value are retained. - Adds testing of object history when supported (host, group, atom, role). - Moves filtering testing to a host. - Will conflict with https://github.com/unioslo/mreg-cli/pull/198, due to having to fix group history here as well. * Remove debugging output. --- ci/diff.py | 36 +- ci/testsuite | 14 +- ci/testsuite-result.json | 931 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 960 insertions(+), 21 deletions(-) diff --git a/ci/diff.py b/ci/diff.py index 2f2ef056..bb13a6f8 100644 --- a/ci/diff.py +++ b/ci/diff.py @@ -1,12 +1,39 @@ import difflib import json +import re import sys +from typing import Any, Dict, List -def group_objects(json_file_path): +def replace_timestamps(obj: Any) -> Any: + """Recursively replace timestamp values in a JSON object. + + :param obj: A JSON object (dict, list, or primitive type). + :returns: A new object with timestamps replaced. + """ + timestamp_pattern = re.compile( + r"\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[+-]\d{2}:\d{2})?|\d{4}-\d{2}-\d{2}" + ) + if isinstance(obj, dict): + return {k: replace_timestamps(v) for k, v in obj.items()} + elif isinstance(obj, list): + return [replace_timestamps(elem) for elem in obj] + elif isinstance(obj, str): + return timestamp_pattern.sub("