89 lines
2.6 KiB
Python
89 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script for the upgrade method in corecfg_manager.py
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
|
|
from scientific_surfing.corecfg_manager import CoreConfigManager
|
|
|
|
def test_upgrade():
|
|
"""Test the upgrade method functionality."""
|
|
manager = CoreConfigManager()
|
|
|
|
print("Testing upgrade method...")
|
|
print("=" * 50)
|
|
|
|
# Test 1: Check if upgrade method exists
|
|
if hasattr(manager, 'upgrade'):
|
|
print("[OK] upgrade method exists")
|
|
else:
|
|
print("[FAIL] upgrade method not found")
|
|
return False
|
|
|
|
# Test 2: Test OS detection (without actually downloading)
|
|
import platform
|
|
system = platform.system().lower()
|
|
machine = platform.machine().lower()
|
|
|
|
print(f"Detected OS: {system}")
|
|
print(f"Detected Architecture: {machine}")
|
|
|
|
# Test 3: Test platform mapping
|
|
platform_map = {
|
|
'windows': {
|
|
'amd64': 'mihomo-windows-amd64.exe',
|
|
'386': 'mihomo-windows-386.exe',
|
|
'arm64': 'mihomo-windows-arm64.exe',
|
|
'arm': 'mihomo-windows-arm32v7.exe'
|
|
},
|
|
'linux': {
|
|
'amd64': 'mihomo-linux-amd64',
|
|
'386': 'mihomo-linux-386',
|
|
'arm64': 'mihomo-linux-arm64',
|
|
'arm': 'mihomo-linux-armv7'
|
|
},
|
|
'darwin': {
|
|
'amd64': 'mihomo-darwin-amd64',
|
|
'arm64': 'mihomo-darwin-arm64'
|
|
}
|
|
}
|
|
|
|
arch_map = {
|
|
'x86_64': 'amd64',
|
|
'amd64': 'amd64',
|
|
'i386': '386',
|
|
'i686': '386',
|
|
'arm64': 'arm64',
|
|
'aarch64': 'arm64',
|
|
'armv7l': 'arm',
|
|
'arm': 'arm'
|
|
}
|
|
|
|
normalized_arch = arch_map.get(machine, machine)
|
|
|
|
if system in platform_map and normalized_arch in platform_map[system]:
|
|
binary_name = platform_map[system][normalized_arch]
|
|
print(f"[OK] Would download: {binary_name}")
|
|
else:
|
|
print(f"[FAIL] Unsupported platform: {system}/{normalized_arch}")
|
|
return False
|
|
|
|
# Test 4: Test directory creation
|
|
from scientific_surfing.storage import StorageManager
|
|
storage = StorageManager()
|
|
binary_dir = storage.config_dir / "bin"
|
|
print(f"Binary directory: {binary_dir}")
|
|
|
|
print("\n[OK] All tests passed! The upgrade method is ready to use.")
|
|
print("\nUsage examples:")
|
|
print(" manager.upgrade() # Download latest version")
|
|
print(" manager.upgrade(version='v1.18.5') # Download specific version")
|
|
print(" manager.upgrade(force=True) # Force re-download")
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
test_upgrade() |