30 lines
868 B
Python
30 lines
868 B
Python
import unittest
|
|
import tempfile
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from hysteria_panel import utils
|
|
|
|
|
|
class TestConfigUtils(unittest.TestCase):
|
|
def test_save_load_clear_config(self):
|
|
with tempfile.TemporaryDirectory() as td:
|
|
temp_dir = Path(td)
|
|
temp_file = temp_dir / "config.json"
|
|
|
|
with patch.object(utils, 'CONFIG_DIR', temp_dir), patch.object(utils, 'CONFIG_FILE', temp_file):
|
|
data = {"host": "127.0.0.1", "port": 9999, "secret": "abc", "https": True}
|
|
utils.save_config(data)
|
|
self.assertTrue(temp_file.exists())
|
|
|
|
loaded = utils.load_config()
|
|
self.assertEqual(loaded, data)
|
|
|
|
utils.clear_config()
|
|
self.assertFalse(temp_file.exists())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|
|
|