mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-07-22 02:03:01 +02:00
Update and test the convert_string_to_array function.
This commit is contained in:
@@ -22,10 +22,14 @@ def initialize_monitor(
|
||||
'''
|
||||
|
||||
|
||||
def _convert_string_to_array(value):
|
||||
value = str(value or '')
|
||||
|
||||
return [str(item).strip() for item in value.split(',') if str(item).strip()]
|
||||
def convert_string_to_array(value):
|
||||
value = '' if value is None else str(value)
|
||||
items = []
|
||||
for item in value.split(','):
|
||||
stripped = item.strip()
|
||||
if stripped:
|
||||
items.append(stripped)
|
||||
return items
|
||||
|
||||
|
||||
PRIORITY_NAME_TO_ID = {
|
||||
@@ -72,7 +76,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
|
||||
'title': state_config.get('title'),
|
||||
'message': state_config.get('message'),
|
||||
'priority': PRIORITY_NAME_TO_ID.get(state_config.get('priority'), default_priority),
|
||||
'tags': _convert_string_to_array(state_config.get('tags')),
|
||||
'tags': convert_string_to_array(state_config.get('tags')),
|
||||
}
|
||||
|
||||
try:
|
||||
|
||||
@@ -380,3 +380,11 @@ def test_ping_monitor_with_other_error_logs_warning():
|
||||
monitoring_log_level=1,
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
def test_convert_string_to_array():
|
||||
assert module.convert_string_to_array(None) == []
|
||||
assert module.convert_string_to_array('') == []
|
||||
assert module.convert_string_to_array('foo') == ['foo']
|
||||
assert module.convert_string_to_array(' foo , bar ,baz ') == ['foo', 'bar', 'baz']
|
||||
assert module.convert_string_to_array('foo,,bar,') == ['foo', 'bar']
|
||||
|
||||
Reference in New Issue
Block a user