Skip to content

Commit

Permalink
validate the max_match in test
Browse files Browse the repository at this point in the history
Signed-off-by: Xiangce Liu <[email protected]>
  • Loading branch information
xiangce committed Jan 2, 2025
1 parent 02c9dbb commit dde8128
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions insights/core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def inner(comp, patterns):

FILTERS[comp].update(max_matchs(FILTERS[comp], patterns))

if max_match is None or (type(max_match) is not int or max_match <= 0):
raise Exception("Invalid argument 'max_match' to the add_filter: {0}".format(max_match))

if not plugins.is_datasource(component):
deps = get_dependency_datasources(component)
if deps:
Expand Down
18 changes: 18 additions & 0 deletions insights/tests/core/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,24 @@ def test_add_filter_exception_None():
filters.add_filter(Specs.ps_aux, None)


def test_add_filter_exception_with_invalid_max_match():
with pytest.raises(Exception) as ex:
filters.add_filter(Specs.ps_aux, 'abctest', 'str')
assert "Invalid argument 'max_match' to the add_filter: str" in str(ex)

with pytest.raises(Exception) as ex:
filters.add_filter(Specs.ps_aux, 'abctest', 0)
assert "Invalid argument 'max_match' to the add_filter: 0" in str(ex)

with pytest.raises(Exception) as ex:
filters.add_filter(Specs.ps_aux, 'abctest', -1)
assert "Invalid argument 'max_match' to the add_filter: -1" in str(ex)

with pytest.raises(Exception) as ex:
filters.add_filter(Specs.ps_aux, 'abctest', None)
assert "Invalid argument 'max_match' to the add_filter: None" in str(ex)


def test_get_filters():
_filter = 'A filter'
filters.add_filter(MySpecs.has_filters, _filter)
Expand Down

0 comments on commit dde8128

Please sign in to comment.