linux observer
at main 69 lines 2.2 kB view raw
1# SPDX-License-Identifier: AGPL-3.0-only 2# Copyright (c) 2026 sol pbc 3 4from pathlib import Path 5 6from solstone_linux.config import Config, load_config, save_config 7 8 9class TestConfig: 10 def test_defaults(self): 11 config = Config() 12 assert config.server_url == "" 13 assert config.key == "" 14 assert config.segment_interval == 300 15 16 def test_captures_dir(self): 17 config = Config() 18 assert config.captures_dir == config.base_dir / "captures" 19 20 def test_restore_token_path(self): 21 config = Config() 22 assert config.restore_token_path == config.base_dir / "config" / "restore_token" 23 24 def test_round_trip(self, tmp_path: Path): 25 config = Config(base_dir=tmp_path) 26 config.server_url = "https://example.com" 27 config.key = "test-key-123" 28 config.stream = "archon" 29 config.segment_interval = 600 30 31 save_config(config) 32 33 loaded = load_config(tmp_path) 34 assert loaded.server_url == "https://example.com" 35 assert loaded.key == "test-key-123" 36 assert loaded.stream == "archon" 37 assert loaded.segment_interval == 600 38 39 def test_load_missing(self, tmp_path: Path): 40 config = load_config(tmp_path) 41 assert config.server_url == "" 42 assert config.key == "" 43 44 def test_load_corrupt(self, tmp_path: Path): 45 config_dir = tmp_path / "config" 46 config_dir.mkdir(parents=True) 47 (config_dir / "config.json").write_text("not json!") 48 49 config = load_config(tmp_path) 50 assert config.server_url == "" 51 52 def test_permissions(self, tmp_path: Path): 53 config = Config(base_dir=tmp_path) 54 config.server_url = "https://example.com" 55 config.key = "secret" 56 save_config(config) 57 58 mode = config.config_path.stat().st_mode & 0o777 59 assert mode == 0o600 60 61 def test_sync_config_roundtrip(self, tmp_path: Path): 62 config = Config(base_dir=tmp_path) 63 config.sync_retry_delays = [10, 60, 300] 64 config.sync_max_retries = 5 65 save_config(config) 66 67 loaded = load_config(tmp_path) 68 assert loaded.sync_retry_delays == [10, 60, 300] 69 assert loaded.sync_max_retries == 5