Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roverflow committed Nov 15, 2024
1 parent 5f89a3d commit 0394d50
Show file tree
Hide file tree
Showing 2 changed files with 405 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def generate_commands(self):

# if state is deleted, empty out wantd and set haved to wantd
if self.state == "deleted":
haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd}
haved = self.filter_dict(haved, wantd)
wantd = {}

# remove superfluous config for overridden and deleted
Expand Down Expand Up @@ -166,6 +166,17 @@ def _convert_to_dict(self, vrf_af_item: list, parser_item: str) -> dict:
result[key] = item
return result

def filter_dict(self, haved, wantd):
if isinstance(haved, dict) and isinstance(wantd, dict):
# Only keep keys that are in `wantd` and filter recursively
return {k: self.filter_dict(haved[k], wantd[k]) for k in haved if k in wantd}
elif isinstance(haved, list) and isinstance(wantd, list):
# Filter list elements if they are dictionaries, otherwise return only items that match
return [self.filter_dict(h_item, wantd[0]) for h_item in haved if isinstance(h_item, dict)] if wantd and isinstance(wantd[0], dict) else [item for item in haved if item in wantd]
else:
# For non-dict and non-list values, just return the value if it matches
return haved if haved == wantd else None

def _vrf_address_family_list_to_dict(self, vrf_af_list: list) -> dict:
"""Convert a list of vrf_address_family dictionaries to a dictionary.
Expand Down
Loading

0 comments on commit 0394d50

Please sign in to comment.