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 trivial but also cheap and runs fast.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
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 @@ | ||
../org.osbuild.kickstart |
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,57 @@ | ||
#!/usr/bin/python3 | ||
|
||
import os | ||
import os.path | ||
import shutil | ||
import stat | ||
from tempfile import mkdtemp | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from org_osbuild_kickstart import main as kickstart_main | ||
|
||
test_cases = [ | ||
{ | ||
"options": {"lang": "en_US.UTF-8"}, | ||
"expected": "lang en_US.UTF-8", | ||
}, | ||
{ | ||
"options": {"keyboard": "us"}, | ||
"expected": "keyboard us", | ||
}, | ||
{ | ||
"options": {"timezone": "UTC"}, | ||
"expected": "timezone UTC", | ||
}, | ||
{ | ||
"options": { | ||
"lang": "en_US.UTF-8", | ||
"keyboard": "us", | ||
"timezone": "UTC", | ||
}, | ||
"expected": "lang en_US.UTF-8\nkeyboard us\ntimezone UTC", | ||
}, | ||
# TODO: add test cases for the existing options | ||
] | ||
|
||
|
||
class TestOrgOsbuilderKickstart(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.tmpdir = mkdtemp() | ||
self.addCleanup(shutil.rmtree, self.tmpdir) | ||
|
||
def test_kickstart(self): | ||
ks_path = "kickstart/kfs.cfg" | ||
for tc in test_cases: | ||
options = {"path": ks_path} | ||
options.update(tc["options"]) | ||
kickstart_main(self.tmpdir, options) | ||
|
||
with open(os.path.join(self.tmpdir, ks_path)) as fp: | ||
ks_content = fp.read() | ||
self.assertEqual(ks_content, tc["expected"] + "\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |