Files
fgAI/tests/test_config.py
larssand f9137bfa6c fix dash
2026-06-30 12:49:33 +02:00

50 lines
2.4 KiB
Python

import tempfile
import unittest
from pathlib import Path
from fgai.config import ConfigStore
class ConfigTests(unittest.TestCase):
def test_public_config_hides_token_and_preserves_blank_update(self):
with tempfile.TemporaryDirectory() as directory:
store = ConfigStore(str(Path(directory) / "config.json"))
store.update({"log_source": "graylog_mcp", "graylog_mcp_token": "secret"})
public = store.update({"graylog_mcp_token": ""})
self.assertEqual(public["log_source"], "graylog_mcp")
self.assertTrue(public["graylog_mcp_token_configured"])
self.assertNotIn("graylog_mcp_token", public)
def test_graylog_range_seconds_is_numeric_and_bounded(self):
with tempfile.TemporaryDirectory() as directory:
store = ConfigStore(str(Path(directory) / "config.json"))
public = store.update({"graylog_range_seconds": "30"})
self.assertEqual(public["graylog_range_seconds"], 60)
public = store.update({"graylog_range_seconds": "7200"})
self.assertEqual(public["graylog_range_seconds"], 7200)
def test_graylog_max_events_per_stream_is_numeric_and_bounded(self):
with tempfile.TemporaryDirectory() as directory:
store = ConfigStore(str(Path(directory) / "config.json"))
public = store.update({"graylog_max_events_per_stream": "0"})
self.assertEqual(public["graylog_max_events_per_stream"], 1)
public = store.update({"graylog_max_events_per_stream": "25000"})
self.assertEqual(public["graylog_max_events_per_stream"], 25000)
def test_graylog_fetch_mode_and_raw_sample_events_are_saved(self):
with tempfile.TemporaryDirectory() as directory:
store = ConfigStore(str(Path(directory) / "config.json"))
public = store.update({"graylog_fetch_mode": "aggregate", "graylog_raw_sample_events": "2500"})
self.assertEqual(public["graylog_fetch_mode"], "aggregate")
self.assertEqual(public["graylog_raw_sample_events"], 2500)
def test_graylog_tls_verify_can_be_disabled(self):
with tempfile.TemporaryDirectory() as directory:
store = ConfigStore(str(Path(directory) / "config.json"))
public = store.update({"graylog_tls_verify": False})
self.assertFalse(public["graylog_tls_verify"])
if __name__ == "__main__":
unittest.main()