Some checks failed
Checks / Spelling (push) Has been cancelled
Checks / Python Linters (push) Has been cancelled
Checks / Shell Linters (push) Has been cancelled
Checks / 📦 Packit config lint (push) Has been cancelled
Checks / 🔍 Check for valid snapshot urls (push) Has been cancelled
Checks / 🔍 Check JSON files for formatting consistency (push) Has been cancelled
Generate / Documentation (push) Has been cancelled
Generate / Test Data (push) Has been cancelled
Tests / Unittest (push) Has been cancelled
Tests / Assembler test (legacy) (push) Has been cancelled
Tests / Smoke run: unittest as normal user on default runner (push) Has been cancelled
428 lines
15 KiB
Python
428 lines
15 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test Debian Repository Manager for Debian Forge
|
|
|
|
This script tests the Debian repository management system for
|
|
composer builds.
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
# Add current directory to Python path
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
def test_repository_manager_import():
|
|
"""Test importing the repository manager"""
|
|
print("Testing repository manager import...")
|
|
|
|
try:
|
|
from debian_repository_manager import DebianRepositoryManager, DebianRepository, RepositoryMirror
|
|
print(" ✅ Repository manager imported successfully")
|
|
return True
|
|
except ImportError as e:
|
|
print(f" ❌ Failed to import repository manager: {e}")
|
|
return False
|
|
|
|
def test_debian_repository_dataclass():
|
|
"""Test DebianRepository dataclass"""
|
|
print("\nTesting DebianRepository dataclass...")
|
|
|
|
try:
|
|
from debian_repository_manager import DebianRepository
|
|
|
|
repo = DebianRepository(
|
|
name="test-repo",
|
|
url="http://test.debian.org/debian",
|
|
suite="test",
|
|
components=["main", "contrib"],
|
|
enabled=True,
|
|
priority=100
|
|
)
|
|
|
|
if repo.name != "test-repo":
|
|
print(" ❌ Repository name not set correctly")
|
|
return False
|
|
|
|
if repo.url != "http://test.debian.org/debian":
|
|
print(" ❌ Repository URL not set correctly")
|
|
return False
|
|
|
|
if len(repo.components) != 2:
|
|
print(" ❌ Repository components not set correctly")
|
|
return False
|
|
|
|
print(" ✅ DebianRepository dataclass works correctly")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ DebianRepository test failed: {e}")
|
|
return False
|
|
|
|
def test_repository_mirror_dataclass():
|
|
"""Test RepositoryMirror dataclass"""
|
|
print("\nTesting RepositoryMirror dataclass...")
|
|
|
|
try:
|
|
from debian_repository_manager import RepositoryMirror
|
|
|
|
mirror = RepositoryMirror(
|
|
name="test-mirror",
|
|
url="http://test.debian.org/debian",
|
|
region="test-region",
|
|
protocol="https",
|
|
enabled=True,
|
|
health_check=True
|
|
)
|
|
|
|
if mirror.name != "test-mirror":
|
|
print(" ❌ Mirror name not set correctly")
|
|
return False
|
|
|
|
if mirror.protocol != "https":
|
|
print(" ❌ Mirror protocol not set correctly")
|
|
return False
|
|
|
|
print(" ✅ RepositoryMirror dataclass works correctly")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ RepositoryMirror test failed: {e}")
|
|
return False
|
|
|
|
def test_repository_manager_initialization():
|
|
"""Test repository manager initialization"""
|
|
print("\nTesting repository manager initialization...")
|
|
|
|
try:
|
|
from debian_repository_manager import DebianRepositoryManager
|
|
|
|
# Create temporary directory for testing
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
manager = DebianRepositoryManager(temp_dir)
|
|
|
|
# Check if repositories were loaded
|
|
if not hasattr(manager, 'repositories'):
|
|
print(" ❌ Repositories not loaded")
|
|
return False
|
|
|
|
if not hasattr(manager, 'mirrors'):
|
|
print(" ❌ Mirrors not loaded")
|
|
return False
|
|
|
|
# Check default repositories
|
|
repos = manager.list_repositories()
|
|
if len(repos) == 0:
|
|
print(" ❌ No default repositories loaded")
|
|
return False
|
|
|
|
# Check default mirrors
|
|
mirrors = manager.list_mirrors()
|
|
if len(mirrors) == 0:
|
|
print(" ❌ No default mirrors loaded")
|
|
return False
|
|
|
|
print(" ✅ Repository manager initialization works correctly")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Repository manager initialization test failed: {e}")
|
|
return False
|
|
|
|
def test_repository_operations():
|
|
"""Test repository operations"""
|
|
print("\nTesting repository operations...")
|
|
|
|
try:
|
|
from debian_repository_manager import DebianRepositoryManager, DebianRepository
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
manager = DebianRepositoryManager(temp_dir)
|
|
|
|
# Test adding repository
|
|
new_repo = DebianRepository(
|
|
name="test-add-repo",
|
|
url="http://test.debian.org/debian",
|
|
suite="test",
|
|
components=["main"]
|
|
)
|
|
|
|
if not manager.add_repository(new_repo):
|
|
print(" ❌ Failed to add repository")
|
|
return False
|
|
|
|
# Test getting repository
|
|
retrieved = manager.get_repository("test-add-repo")
|
|
if not retrieved:
|
|
print(" ❌ Failed to retrieve added repository")
|
|
return False
|
|
|
|
# Test updating repository
|
|
if not manager.update_repository("test-add-repo", priority=200):
|
|
print(" ❌ Failed to update repository")
|
|
return False
|
|
|
|
updated = manager.get_repository("test-add-repo")
|
|
if updated["priority"] != 200:
|
|
print(" ❌ Repository update not applied")
|
|
return False
|
|
|
|
# Test removing repository
|
|
if not manager.remove_repository("test-add-repo"):
|
|
print(" ❌ Failed to remove repository")
|
|
return False
|
|
|
|
if manager.get_repository("test-add-repo"):
|
|
print(" ❌ Repository not removed")
|
|
return False
|
|
|
|
print(" ✅ Repository operations work correctly")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Repository operations test failed: {e}")
|
|
return False
|
|
|
|
def test_mirror_operations():
|
|
"""Test mirror operations"""
|
|
print("\nTesting mirror operations...")
|
|
|
|
try:
|
|
from debian_repository_manager import DebianRepositoryManager, RepositoryMirror
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
manager = DebianRepositoryManager(temp_dir)
|
|
|
|
# Test adding mirror
|
|
new_mirror = RepositoryMirror(
|
|
name="test-add-mirror",
|
|
url="http://test.debian.org/debian",
|
|
region="test-region"
|
|
)
|
|
|
|
if not manager.add_mirror(new_mirror):
|
|
print(" ❌ Failed to add mirror")
|
|
return False
|
|
|
|
# Test listing mirrors
|
|
mirrors = manager.list_mirrors()
|
|
mirror_names = [m["name"] for m in mirrors]
|
|
if "test-add-mirror" not in mirror_names:
|
|
print(" ❌ Added mirror not found in list")
|
|
return False
|
|
|
|
# Test removing mirror
|
|
if not manager.remove_mirror("test-add-mirror"):
|
|
print(" ❌ Failed to remove mirror")
|
|
return False
|
|
|
|
mirrors_after = manager.list_mirrors()
|
|
mirror_names_after = [m["name"] for m in mirrors_after]
|
|
if "test-add-mirror" in mirror_names_after:
|
|
print(" ❌ Mirror not removed")
|
|
return False
|
|
|
|
print(" ✅ Mirror operations work correctly")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Mirror operations test failed: {e}")
|
|
return False
|
|
|
|
def test_configuration_generation():
|
|
"""Test configuration generation"""
|
|
print("\nTesting configuration generation...")
|
|
|
|
try:
|
|
from debian_repository_manager import DebianRepositoryManager
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
manager = DebianRepositoryManager(temp_dir)
|
|
|
|
# Test sources.list generation
|
|
sources_list = manager.generate_sources_list("bookworm", ["main", "contrib"])
|
|
if not sources_list:
|
|
print(" ❌ Sources list generation failed")
|
|
return False
|
|
|
|
# Check if sources list contains expected content
|
|
if "deb http://deb.debian.org/debian bookworm main" not in sources_list:
|
|
print(" ❌ Sources list missing expected content")
|
|
return False
|
|
|
|
# Test APT configuration generation
|
|
apt_config = manager.generate_apt_config("bookworm", proxy="http://192.168.1.101:3142")
|
|
if not apt_config:
|
|
print(" ❌ APT configuration generation failed")
|
|
return False
|
|
|
|
if "sources" not in apt_config:
|
|
print(" ❌ APT config missing sources")
|
|
return False
|
|
|
|
if apt_config.get("proxy") != "http://192.168.1.101:3142":
|
|
print(" ❌ APT config proxy not set correctly")
|
|
return False
|
|
|
|
print(" ✅ Configuration generation works correctly")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Configuration generation test failed: {e}")
|
|
return False
|
|
|
|
def test_configuration_validation():
|
|
"""Test configuration validation"""
|
|
print("\nTesting configuration validation...")
|
|
|
|
try:
|
|
from debian_repository_manager import DebianRepositoryManager
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
manager = DebianRepositoryManager(temp_dir)
|
|
|
|
# Test validation of valid configuration
|
|
errors = manager.validate_repository_config()
|
|
if errors:
|
|
print(f" ❌ Valid configuration has errors: {errors}")
|
|
return False
|
|
|
|
print(" ✅ Configuration validation works correctly")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Configuration validation test failed: {e}")
|
|
return False
|
|
|
|
def test_configuration_export_import():
|
|
"""Test configuration export and import"""
|
|
print("\nTesting configuration export and import...")
|
|
|
|
try:
|
|
from debian_repository_manager import DebianRepositoryManager
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
manager = DebianRepositoryManager(temp_dir)
|
|
|
|
# Test export
|
|
export_path = os.path.join(temp_dir, "config_export.json")
|
|
if not manager.export_configuration(export_path):
|
|
print(" ❌ Configuration export failed")
|
|
return False
|
|
|
|
# Check if export file exists
|
|
if not os.path.exists(export_path):
|
|
print(" ❌ Export file not created")
|
|
return False
|
|
|
|
# Test import
|
|
new_manager = DebianRepositoryManager(temp_dir + "_import")
|
|
if not new_manager.import_configuration(export_path):
|
|
print(" ❌ Configuration import failed")
|
|
return False
|
|
|
|
# Verify imported configuration
|
|
original_repos = manager.list_repositories()
|
|
imported_repos = new_manager.list_repositories()
|
|
|
|
if len(original_repos) != len(imported_repos):
|
|
print(" ❌ Imported configuration doesn't match original")
|
|
return False
|
|
|
|
print(" ✅ Configuration export and import works correctly")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Configuration export/import test failed: {e}")
|
|
return False
|
|
|
|
def test_enabled_repositories():
|
|
"""Test enabled repositories functionality"""
|
|
print("\nTesting enabled repositories...")
|
|
|
|
try:
|
|
from debian_repository_manager import DebianRepositoryManager
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
manager = DebianRepositoryManager(temp_dir)
|
|
|
|
# Get enabled repositories
|
|
enabled_repos = manager.get_enabled_repositories()
|
|
|
|
# Check if all enabled repositories are actually enabled
|
|
for repo in enabled_repos:
|
|
if not repo.get("enabled", False):
|
|
print(" ❌ Repository marked as enabled but not enabled")
|
|
return False
|
|
|
|
# Get enabled mirrors
|
|
enabled_mirrors = manager.get_enabled_mirrors()
|
|
|
|
# Check if all enabled mirrors are actually enabled
|
|
for mirror in enabled_mirrors:
|
|
if not mirror.get("enabled", False):
|
|
print(" ❌ Mirror marked as enabled but not enabled")
|
|
return False
|
|
|
|
print(" ✅ Enabled repositories functionality works correctly")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Enabled repositories test failed: {e}")
|
|
return False
|
|
|
|
def main():
|
|
"""Main test function"""
|
|
print("Debian Repository Manager Test for Debian Forge")
|
|
print("=" * 60)
|
|
|
|
tests = [
|
|
("Repository Manager Import", test_repository_manager_import),
|
|
("DebianRepository Dataclass", test_debian_repository_dataclass),
|
|
("RepositoryMirror Dataclass", test_repository_mirror_dataclass),
|
|
("Repository Manager Initialization", test_repository_manager_initialization),
|
|
("Repository Operations", test_repository_operations),
|
|
("Mirror Operations", test_mirror_operations),
|
|
("Configuration Generation", test_configuration_generation),
|
|
("Configuration Validation", test_configuration_validation),
|
|
("Configuration Export/Import", test_configuration_export_import),
|
|
("Enabled Repositories", test_enabled_repositories)
|
|
]
|
|
|
|
results = []
|
|
for test_name, test_func in tests:
|
|
try:
|
|
result = test_func()
|
|
results.append((test_name, result))
|
|
except Exception as e:
|
|
print(f" ❌ {test_name} test failed with exception: {e}")
|
|
results.append((test_name, False))
|
|
|
|
# Summary
|
|
print("\n" + "=" * 60)
|
|
print("TEST SUMMARY")
|
|
print("=" * 60)
|
|
|
|
passed = 0
|
|
total = len(results)
|
|
|
|
for test_name, result in results:
|
|
status = "✅ PASS" if result else "❌ FAIL"
|
|
print(f"{test_name}: {status}")
|
|
if result:
|
|
passed += 1
|
|
|
|
print(f"\nOverall: {passed}/{total} tests passed")
|
|
|
|
if passed == total:
|
|
print("🎉 All tests passed! Debian repository manager is ready.")
|
|
return 0
|
|
else:
|
|
print("⚠️ Some tests failed. Please review the issues above.")
|
|
return 1
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|