Skip to content

Commit

Permalink
stages: add new unit test for kickstart stage
Browse files Browse the repository at this point in the history
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
mvo5 committed Nov 2, 2023
1 parent 5a29759 commit 8b7f71d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions stages/test/org_osbuild_kickstart.py
57 changes: 57 additions & 0 deletions stages/test/test_kickstart.py
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()

0 comments on commit 8b7f71d

Please sign in to comment.