Files
fgAI/tests/test_config.py

37 lines
1.6 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)
if __name__ == "__main__":
unittest.main()