Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GCU] Fix JsonPointerFilter bug #2477

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions generic_config_updater/patch_sorter.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,10 @@ def _get_paths_recursive(self, config, pattern_tokens, matching_tokens, idx, com
if token == "*":
matching_keys = config.keys()
elif token.startswith("*|"):
suffix = token[2:]
suffix = token[1:]
matching_keys = [key for key in config.keys() if key.endswith(suffix)]
elif token.endswith("|*"):
prefix = token[:-2]
prefix = token[:-1]
matching_keys = [key for key in config.keys() if key.startswith(prefix)]
elif token in config:
matching_keys = [token]
Expand Down
35 changes: 35 additions & 0 deletions tests/generic_config_updater/patch_sorter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,41 @@ def test_simulate__applies_move(self):
# Assert
self.assertIs(self.any_diff, actual)

class TestJsonPointerFilter(unittest.TestCase):
def test_get_paths__common_prefix__exact_match_returned(self):
config = {
"BUFFER_PG": {
"Ethernet1|0": {},
"Ethernet12|0": {},
"Ethernet120|0": {}, # 'Ethernet12' is a common prefix with the previous line
},
}

filter = ps.JsonPointerFilter([["BUFFER_PG", "Ethernet12|*"]], PathAddressing())

expected_paths = ["/BUFFER_PG/Ethernet12|0"]

actual_paths = list(filter.get_paths(config))

self.assertCountEqual(expected_paths, actual_paths)

def test_get_paths__common_suffix__exact_match_returned(self):
config = {
"QUEUE": {
"Ethernet1|0": {},
"Ethernet1|10": {},
"Ethernet1|110": {}, # 10 is a common suffix with the previous line
},
}

filter = ps.JsonPointerFilter([["QUEUE", "*|10"]], PathAddressing())

expected_paths = ["/QUEUE/Ethernet1|10"]

actual_paths = list(filter.get_paths(config))

self.assertCountEqual(expected_paths, actual_paths)

class TestRequiredValueIdentifier(unittest.TestCase):
def test_hard_coded_required_value_data(self):
identifier = ps.RequiredValueIdentifier(PathAddressing())
Expand Down