重构
This commit is contained in:
61
tests/test_conf_parity.py
Normal file
61
tests/test_conf_parity.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
ROOT_DIR = Path(__file__).resolve().parent.parent
|
||||
if str(ROOT_DIR) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT_DIR))
|
||||
|
||||
|
||||
def _write_sample_source(path: Path) -> None:
|
||||
path.write_text(
|
||||
"\n".join(
|
||||
[
|
||||
"proxies:",
|
||||
" - name: hk-demo",
|
||||
" type: ss",
|
||||
" server: 1.1.1.1",
|
||||
" port: 443",
|
||||
" cipher: aes-128-gcm",
|
||||
" password: demo-pass",
|
||||
" - name: us-demo",
|
||||
" type: ss",
|
||||
" server: 2.2.2.2",
|
||||
" port: 443",
|
||||
" cipher: aes-128-gcm",
|
||||
" password: demo-pass",
|
||||
]
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
class ConfParityTest(unittest.TestCase):
|
||||
def test_compare_script_core_matches(self) -> None:
|
||||
with TemporaryDirectory() as tmp:
|
||||
sample = Path(tmp) / "sample.yaml"
|
||||
_write_sample_source(sample)
|
||||
os.environ["AIRPORT_A_URL"] = str(sample)
|
||||
os.environ["AIRPORT_B_URL"] = str(sample)
|
||||
os.environ["AIRPORT_C_URL"] = str(sample)
|
||||
|
||||
from scripts.compare_conf_outputs import compare_outputs
|
||||
|
||||
result = compare_outputs("mihomo", "default", "airport-a,airport-b", sample_source=sample)
|
||||
|
||||
self.assertTrue(result["thin"]["proxy_provider_match"])
|
||||
self.assertTrue(result["thin"]["rule_provider_match"])
|
||||
self.assertTrue(result["thin"]["group_name_match"])
|
||||
self.assertTrue(result["bundle"]["group_name_match"])
|
||||
self.assertTrue(result["bundle"]["proxy_count_match"])
|
||||
self.assertTrue(result["bundle"]["rules_count_match"])
|
||||
self.assertEqual(result["thin"]["legacy"]["rules_head"], result["thin"]["conf"]["rules_head"])
|
||||
self.assertEqual(result["bundle"]["legacy"]["rules_tail"], result["bundle"]["conf"]["rules_tail"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user