The testing script is getting too big and not very well organized. In this commit a new module `integration_tests` is introduced that contains parts of the original testing script split into multiple files. The content should be the same, the only difference is that now you can run the tests by invoking `python3 -m test`.
38 lines
1,019 B
Python
38 lines
1,019 B
Python
from dataclasses import dataclass
|
|
from enum import Enum
|
|
from typing import List, Callable, Any
|
|
|
|
from . import evaluate_test, rel_path
|
|
from .build import run_osbuild
|
|
from .run import boot_image, extract_image
|
|
|
|
|
|
class IntegrationTestType(Enum):
|
|
EXTRACT=0
|
|
BOOT_WITH_QEMU=1
|
|
|
|
|
|
@dataclass
|
|
class IntegrationTestCase:
|
|
name: str
|
|
pipeline: str
|
|
output_image: str
|
|
test_cases: List[Callable[[Any], None]]
|
|
type: IntegrationTestType
|
|
|
|
def run(self):
|
|
run_osbuild(rel_path(f"pipelines/{self.pipeline}"))
|
|
if self.type == IntegrationTestType.BOOT_WITH_QEMU:
|
|
self.boot_and_run()
|
|
else:
|
|
self.extract_and_run()
|
|
|
|
def boot_and_run(self):
|
|
with boot_image(self.output_image):
|
|
for test in self.test_cases:
|
|
evaluate_test(test)
|
|
|
|
def extract_and_run(self):
|
|
with extract_image(self.output_image) as fstree:
|
|
for test in self.test_cases:
|
|
evaluate_test(lambda: test(fstree), name=test.__name__)
|