@@ -51,11 +51,63 @@ def model_obj():
5151 )
5252
5353
54+ @pytest .fixture
55+ def multiple_dev ():
56+ return StorageDataModel (
57+ storage_data = {
58+ "dev1" : DeviceStorageData (total = 100 , free = 90 , used = 10 , percent = 10 ),
59+ "dev2" : DeviceStorageData (total = 100 , free = 5 , used = 95 , percent = 95 ),
60+ }
61+ )
62+
63+
5464@pytest .fixture
5565def analyzer (system_info ):
5666 return StorageAnalyzer (system_info = system_info )
5767
5868
69+ def test_filter_exact_match (analyzer ):
70+ assert analyzer ._matches_device_filter ("foo" , ["foo" , "bar" ], regex_match = False )
71+ assert not analyzer ._matches_device_filter ("baz" , ["foo" , "bar" ], regex_match = False )
72+
73+
74+ def test_filter_regex_match (analyzer ):
75+ assert analyzer ._matches_device_filter ("disk0" , [r"disk\d" ], regex_match = True )
76+ assert not analyzer ._matches_device_filter ("diskA" , [r"disk\d" ], regex_match = True )
77+
78+
79+ def test_filter_invalid_regex (analyzer , monkeypatch ):
80+ calls = []
81+ monkeypatch .setattr (analyzer , "_log_event" , lambda ** kw : calls .append (kw ))
82+ assert not analyzer ._matches_device_filter ("somestring" , ["[invalid" ], regex_match = True )
83+ assert len (calls ) == 1
84+ event = calls [0 ]
85+ assert event ["category" ] == EventCategory .STORAGE
86+ assert event ["priority" ] == EventPriority .ERROR
87+ assert "Invalid regex pattern" in event ["description" ]
88+
89+
90+ def test_check_devices_only (analyzer , multiple_dev ):
91+ args = StorageAnalyzerArgs (min_required_free_space_prct = 50 , check_devices = ["dev1" ])
92+ res = analyzer .analyze_data (multiple_dev , args )
93+ assert res .status == ExecutionStatus .OK
94+
95+
96+ def test_ignore_devices (analyzer , multiple_dev ):
97+ args = StorageAnalyzerArgs (min_required_free_space_prct = 50 , ignore_devices = ["dev2" ])
98+ res = analyzer .analyze_data (multiple_dev , args )
99+ assert res .status == ExecutionStatus .OK
100+
101+
102+ def test_check_overrides_ignore (analyzer , multiple_dev ):
103+ args = StorageAnalyzerArgs (
104+ min_required_free_space_prct = 50 , check_devices = ["dev2" ], ignore_devices = ["dev2" , "dev1" ]
105+ )
106+ res = analyzer .analyze_data (multiple_dev , args )
107+ assert res .status == ExecutionStatus .ERROR
108+ assert any (e .category == EventCategory .STORAGE .value for e in res .events )
109+
110+
59111def test_only_absolute_threshold_fails (analyzer , model_obj ):
60112 args = StorageAnalyzerArgs (min_required_free_space_abs = "800GB" )
61113 result = analyzer .analyze_data (model_obj , args )
0 commit comments