mirror of
https://github.com/A6-9V/MQL5-Google-Onedrive.git
synced 2026-04-11 10:00:57 +00:00
Consolidated filesystem traversals in scripts/ci_validate_repo.py into a single os.walk pass. Optimized secret scanning by combining regex patterns into a single search operation. Implemented chunked binary reading for NUL byte detection and directory pruning for performance. Resulted in ~30% faster execution time for repository validation.
135 lines
3.1 KiB
Python
135 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Integration test for automation scripts (Sequential version for performance testing).
|
|
"""
|
|
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
import contextlib
|
|
import io
|
|
from pathlib import Path
|
|
import time
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
SCRIPTS_DIR = REPO_ROOT / "scripts"
|
|
CONFIG_DIR = REPO_ROOT / "config"
|
|
|
|
|
|
def test_python_orchestrator():
|
|
"""Test Python orchestrator."""
|
|
result = subprocess.run(
|
|
[sys.executable, str(SCRIPTS_DIR / "startup_orchestrator.py"), "--help"],
|
|
capture_output=True,
|
|
text=True
|
|
)
|
|
assert result.returncode == 0
|
|
|
|
result = subprocess.run(
|
|
[sys.executable, str(SCRIPTS_DIR / "startup_orchestrator.py"), "--dry-run"],
|
|
capture_output=True,
|
|
text=True
|
|
)
|
|
assert result.returncode == 0
|
|
|
|
|
|
def test_example_script():
|
|
"""Test example custom script."""
|
|
result = subprocess.run(
|
|
[sys.executable, str(SCRIPTS_DIR / "example_custom_script.py"), "--help"],
|
|
capture_output=True,
|
|
text=True
|
|
)
|
|
assert result.returncode == 0
|
|
|
|
result = subprocess.run(
|
|
[sys.executable, str(SCRIPTS_DIR / "example_custom_script.py")],
|
|
capture_output=True,
|
|
text=True
|
|
)
|
|
assert result.returncode == 0
|
|
|
|
|
|
def test_echo_hello():
|
|
"""Test echo and hello window scripts."""
|
|
result = subprocess.run(
|
|
[sys.executable, str(SCRIPTS_DIR / "echo_hello.py"), "--help"],
|
|
capture_output=True,
|
|
text=True
|
|
)
|
|
assert result.returncode == 0
|
|
|
|
result = subprocess.run(
|
|
[sys.executable, str(SCRIPTS_DIR / "echo_hello.py")],
|
|
capture_output=True,
|
|
text=True
|
|
)
|
|
assert result.returncode == 0
|
|
|
|
script = SCRIPTS_DIR / "echo_hello.sh"
|
|
result = subprocess.run(
|
|
["bash", "-n", str(script)],
|
|
capture_output=True,
|
|
text=True
|
|
)
|
|
assert result.returncode == 0
|
|
|
|
result = subprocess.run(
|
|
["bash", str(script)],
|
|
capture_output=True,
|
|
text=True
|
|
)
|
|
assert result.returncode == 0
|
|
|
|
|
|
def test_config_file():
|
|
"""Test configuration file."""
|
|
config_file = CONFIG_DIR / "startup_config.json"
|
|
assert config_file.exists()
|
|
|
|
with open(config_file, 'r') as f:
|
|
config = json.load(f)
|
|
|
|
assert "components" in config
|
|
|
|
|
|
def test_shell_script():
|
|
"""Test shell script syntax."""
|
|
script = SCRIPTS_DIR / "startup.sh"
|
|
assert script.exists()
|
|
|
|
result = subprocess.run(
|
|
["bash", "-n", str(script)],
|
|
capture_output=True,
|
|
text=True
|
|
)
|
|
assert result.returncode == 0
|
|
|
|
|
|
def test_validator():
|
|
"""Test repository validator."""
|
|
result = subprocess.run(
|
|
[sys.executable, str(SCRIPTS_DIR / "ci_validate_repo.py")],
|
|
capture_output=True,
|
|
text=True
|
|
)
|
|
assert result.returncode == 0
|
|
|
|
|
|
def main():
|
|
"""Run all tests sequentially."""
|
|
tests = [
|
|
test_config_file,
|
|
test_python_orchestrator,
|
|
test_example_script,
|
|
test_echo_hello,
|
|
test_shell_script,
|
|
test_validator,
|
|
]
|
|
|
|
for test in tests:
|
|
test()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|