Files
routeros-suricata-tzsp/tests/test_redis_service.py
T

51 lines
2.2 KiB
Python

import tempfile
from unittest.mock import patch
from app.redis_service import RedisSupervisor
def test_redis_uses_aof_everysec_and_rdb_snapshot():
with tempfile.TemporaryDirectory() as td:
supervisor = RedisSupervisor(True, td, port=6380, snapshot_seconds=900, aof=True)
supervisor.executable = "/usr/bin/redis-server"
with patch("app.redis_service.subprocess.Popen") as popen:
process = popen.return_value
process.poll.return_value = None
process.pid = 123
supervisor._spawn()
cmd = popen.call_args.args[0]
assert cmd[cmd.index("--appendonly") + 1] == "yes"
assert cmd[cmd.index("--appendfsync") + 1] == "everysec"
assert cmd[cmd.index("--save") + 1:cmd.index("--save") + 3] == ["900", "100"]
assert cmd[cmd.index("--dir") + 1] == td
assert cmd[cmd.index("--maxmemory") + 1] == "128mb"
assert cmd[cmd.index("--maxmemory-policy") + 1] == "noeviction"
def test_redis_status_exposes_runtime_details_for_system_ui():
with tempfile.TemporaryDirectory() as td:
supervisor = RedisSupervisor(True, td, port=6381, snapshot_seconds=1200, aof=True)
supervisor.executable = "/usr/bin/redis-server"
status = supervisor.status()
assert status["managed"] is True
assert status["port"] == 6381
assert status["data_dir"] == td
assert status["snapshot_seconds"] == 1200
assert status["persistence"] == "AOF everysec + RDB"
def test_redis_defaults_to_bounded_transient_buffer():
with tempfile.TemporaryDirectory() as td:
supervisor = RedisSupervisor(True, td, port=6382)
supervisor.executable = "/usr/bin/redis-server"
with patch("app.redis_service.subprocess.Popen") as popen:
process = popen.return_value
process.poll.return_value = None
process.pid = 124
supervisor._spawn()
cmd = popen.call_args.args[0]
assert cmd[cmd.index("--appendonly") + 1] == "no"
assert cmd[cmd.index("--save") + 1] == ""
assert cmd[cmd.index("--maxmemory") + 1] == "128mb"
assert supervisor.status()["persistence"] == "disabled (SQLite archive is durable)"