forked from osbuild/osbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stages: add new unit test for kickstart stage
This commit adds a simple and lightweight unit test for the new kickstart options. It's pretty simple but also cheap and runs fast.
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/python3 | ||
|
||
import os.path | ||
import tempfile | ||
from dataclasses import dataclass | ||
|
||
import pytest | ||
|
||
from osbuild.testutil.imports import import_module_from_path | ||
|
||
|
||
@dataclass | ||
class KsTestCase: | ||
"""KsTestCase is a single test case for the kickstart stage | ||
options: a dict with the options passed to the kickstart stage | ||
expected: the expected string in the generated kickstart file | ||
""" | ||
options: str | ||
expected: str | ||
|
||
|
||
@pytest.fixture(name="ks_test_cases") | ||
def ks_test_cases_fixtures(): | ||
return [ | ||
KsTestCase( | ||
options={"lang": "en_US.UTF-8"}, expected="lang en_US.UTF-8"), | ||
KsTestCase( | ||
options={"keyboard": "us"}, expected="keyboard us"), | ||
KsTestCase( | ||
options={"timezone": "UTC"}, expected="timezone UTC"), | ||
KsTestCase( | ||
options={ | ||
"lang": "en_US.UTF-8", | ||
"keyboard": "us", | ||
"timezone": "UTC", | ||
}, | ||
expected="lang en_US.UTF-8\nkeyboard us\ntimezone UTC", | ||
), | ||
] | ||
|
||
|
||
def test_kickstart(ks_test_cases): | ||
ks_stage_path = os.path.join(os.path.dirname(__file__), "../org.osbuild.kickstart") | ||
ks_stage = import_module_from_path("ks_stage", ks_stage_path) | ||
|
||
ks_path = "kickstart/kfs.cfg" | ||
with tempfile.TemporaryDirectory("kickstart-test-") as tmpdir: | ||
for tc in ks_test_cases: | ||
options = {"path": ks_path} | ||
options.update(tc.options) | ||
ks_stage.main(tmpdir, options) | ||
|
||
with open(os.path.join(tmpdir, ks_path), encoding="utf-8") as fp: | ||
ks_content = fp.read() | ||
assert ks_content == tc.expected + "\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters