268 lines
9 KiB
Python
268 lines
9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to validate deb-mock API structure for osbuild integration.
|
|
This test works without requiring sbuild to be installed.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import json
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
# Add deb_mock to sys.path
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
|
|
def test_api_imports():
|
|
"""Test that all API components can be imported"""
|
|
print("🧪 Testing API Imports")
|
|
print("=" * 30)
|
|
|
|
try:
|
|
from deb_mock.api import MockAPIClient, MockEnvironment, MockConfigBuilder, create_client, create_config
|
|
from deb_mock.environment_manager import EnvironmentManager, EnvironmentInfo, BuildResult, create_environment_manager
|
|
from deb_mock.config import Config
|
|
from deb_mock.exceptions import SbuildError, ChrootError, ConfigurationError
|
|
print(" ✅ All API imports successful")
|
|
return True
|
|
except Exception as e:
|
|
print(f" ❌ Import error: {e}")
|
|
return False
|
|
|
|
def test_config_builder():
|
|
"""Test MockConfigBuilder functionality"""
|
|
print("\n🧪 Testing Config Builder")
|
|
print("=" * 30)
|
|
|
|
try:
|
|
from deb_mock.api import MockConfigBuilder
|
|
|
|
# Test basic config
|
|
config = (MockConfigBuilder()
|
|
.environment("test-env")
|
|
.architecture("amd64")
|
|
.suite("bookworm")
|
|
.packages(["build-essential", "git"])
|
|
.cache_enabled(True)
|
|
.parallel_jobs(4)
|
|
.verbose(True)
|
|
.build())
|
|
|
|
print(f" ✅ Config created: {config.chroot_name}")
|
|
print(f" 📦 Architecture: {config.architecture}")
|
|
print(f" 📦 Suite: {config.suite}")
|
|
print(f" 📦 Packages: {config.chroot_additional_packages}")
|
|
print(f" ⚡ Caching: {config.use_root_cache}")
|
|
print(f" 🔄 Parallel jobs: {config.parallel_jobs}")
|
|
print(f" 📝 Verbose: {config.verbose}")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f" ❌ Error: {e}")
|
|
return False
|
|
|
|
def test_osbuild_manifest_simulation():
|
|
"""Simulate osbuild manifest structure"""
|
|
print("\n🧪 Testing OSBuild Manifest Simulation")
|
|
print("=" * 40)
|
|
|
|
try:
|
|
from deb_mock.api import MockConfigBuilder
|
|
|
|
# Simulate osbuild manifest options
|
|
manifest_options = {
|
|
"environment_name": "osbuild-test-env",
|
|
"architecture": "amd64",
|
|
"suite": "bookworm",
|
|
"packages": ["build-essential", "git", "curl"],
|
|
"caching": True,
|
|
"parallel_jobs": 2,
|
|
"mirror": "http://deb.debian.org/debian"
|
|
}
|
|
|
|
print("1. Simulating osbuild manifest options...")
|
|
for key, value in manifest_options.items():
|
|
print(f" {key}: {value}")
|
|
|
|
# Create config from manifest options
|
|
config = (MockConfigBuilder()
|
|
.environment(manifest_options["environment_name"])
|
|
.architecture(manifest_options["architecture"])
|
|
.suite(manifest_options["suite"])
|
|
.packages(manifest_options["packages"])
|
|
.cache_enabled(manifest_options["caching"])
|
|
.parallel_jobs(manifest_options["parallel_jobs"])
|
|
.mirror(manifest_options["mirror"])
|
|
.build())
|
|
|
|
print("2. Created config from manifest options...")
|
|
print(f" ✅ Config: {config.chroot_name}")
|
|
print(f" ✅ Architecture: {config.architecture}")
|
|
print(f" ✅ Suite: {config.suite}")
|
|
|
|
# Simulate what osbuild would do
|
|
print("3. Simulating osbuild operations...")
|
|
print(" - Environment creation (would call deb-mock API)")
|
|
print(" - Package installation (would call deb-mock API)")
|
|
print(" - Build execution (would call deb-mock API)")
|
|
print(" - Artifact collection (would call deb-mock API)")
|
|
print(" ✅ OSBuild integration simulation complete")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f" ❌ Error: {e}")
|
|
return False
|
|
|
|
def test_plugin_system_structure():
|
|
"""Test plugin system structure"""
|
|
print("\n🧪 Testing Plugin System Structure")
|
|
print("=" * 35)
|
|
|
|
try:
|
|
from deb_mock.plugins.registry import PluginRegistry
|
|
from deb_mock.plugins.base import BasePlugin
|
|
|
|
print("1. Testing plugin registry creation...")
|
|
registry = PluginRegistry()
|
|
print(" ✅ Plugin registry created")
|
|
|
|
print("2. Testing plugin listing...")
|
|
plugins = registry.list_plugins()
|
|
print(f" ✅ Found {len(plugins)} registered plugins")
|
|
|
|
print("3. Testing plugin base class...")
|
|
class TestPlugin(BasePlugin):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.name = "test-plugin"
|
|
self.version = "1.0.0"
|
|
|
|
def execute(self, context):
|
|
return {"status": "success", "plugin": "test"}
|
|
|
|
plugin = TestPlugin()
|
|
print(f" ✅ Test plugin created: {plugin.name} v{plugin.version}")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f" ❌ Error: {e}")
|
|
return False
|
|
|
|
def test_environment_manager_structure():
|
|
"""Test environment manager structure"""
|
|
print("\n🧪 Testing Environment Manager Structure")
|
|
print("=" * 40)
|
|
|
|
try:
|
|
from deb_mock.environment_manager import EnvironmentManager, EnvironmentInfo, BuildResult
|
|
from deb_mock.config import Config
|
|
|
|
print("1. Testing EnvironmentInfo dataclass...")
|
|
info = EnvironmentInfo(
|
|
name="test-env",
|
|
architecture="amd64",
|
|
suite="bookworm",
|
|
status="created",
|
|
created="2024-01-01T00:00:00Z",
|
|
modified="2024-01-01T00:00:00Z",
|
|
size=1024000,
|
|
packages_installed=["build-essential"],
|
|
mounts=["/proc", "/sys"]
|
|
)
|
|
print(f" ✅ EnvironmentInfo created: {info.name}")
|
|
|
|
print("2. Testing BuildResult dataclass...")
|
|
result = BuildResult(
|
|
success=True,
|
|
environment="test-env",
|
|
packages_built=["test-package_1.0-1_amd64.deb"],
|
|
artifacts=["test-package_1.0-1_amd64.deb", "test-package_1.0-1.changes"],
|
|
build_log="Build completed successfully",
|
|
duration=120.5
|
|
)
|
|
print(f" ✅ BuildResult created: {result.success}")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f" ❌ Error: {e}")
|
|
return False
|
|
|
|
def test_exception_handling():
|
|
"""Test exception handling structure"""
|
|
print("\n🧪 Testing Exception Handling")
|
|
print("=" * 30)
|
|
|
|
try:
|
|
from deb_mock.exceptions import SbuildError, ChrootError, ConfigurationError
|
|
|
|
print("1. Testing SbuildError...")
|
|
try:
|
|
raise SbuildError("sbuild not found")
|
|
except SbuildError as e:
|
|
print(f" ✅ SbuildError caught: {e}")
|
|
|
|
print("2. Testing ChrootError...")
|
|
try:
|
|
raise ChrootError("Environment not found")
|
|
except ChrootError as e:
|
|
print(f" ✅ ChrootError caught: {e}")
|
|
|
|
print("3. Testing ConfigurationError...")
|
|
try:
|
|
raise ConfigurationError("Invalid configuration")
|
|
except ConfigurationError as e:
|
|
print(f" ✅ ConfigurationError caught: {e}")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f" ❌ Error: {e}")
|
|
return False
|
|
|
|
def main():
|
|
"""Run all structure tests"""
|
|
print("🚀 Testing deb-mock API Structure for OSBuild Integration")
|
|
print("=" * 65)
|
|
|
|
tests = [
|
|
("API Imports", test_api_imports),
|
|
("Config Builder", test_config_builder),
|
|
("OSBuild Simulation", test_osbuild_manifest_simulation),
|
|
("Plugin System", test_plugin_system_structure),
|
|
("Environment Manager", test_environment_manager_structure),
|
|
("Exception Handling", test_exception_handling)
|
|
]
|
|
|
|
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} failed with exception: {e}")
|
|
results.append((test_name, False))
|
|
|
|
# Summary
|
|
print("\n📊 Test Results Summary")
|
|
print("=" * 65)
|
|
|
|
passed = 0
|
|
total = len(results)
|
|
|
|
for test_name, result in results:
|
|
status = "✅ PASS" if result else "❌ FAIL"
|
|
print(f"{test_name:20} {status}")
|
|
if result:
|
|
passed += 1
|
|
|
|
print(f"\nOverall: {passed}/{total} tests passed")
|
|
|
|
if passed == total:
|
|
print("🎉 All structure tests passed! deb-mock API is ready for osbuild integration.")
|
|
return 0
|
|
else:
|
|
print("⚠️ Some tests failed. Check the output above for details.")
|
|
return 1
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|