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 b505894 commit 4e5da79
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions stages/test/org_osbuild_kickstart.py
53 changes: 53 additions & 0 deletions stages/test/test_kickstart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/python3

import os.path
import shutil
import unittest
from tempfile import mkdtemp

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",
},
]


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), encoding="utf-8") as fp:
ks_content = fp.read()
self.assertEqual(ks_content, tc["expected"] + "\n")


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ deps =
pyyaml

setenv =
LINTABLES = osbuild/ assemblers/* devices/* inputs/* mounts/* runners/* sources/* stages/*
LINTABLES = osbuild/ assemblers/* devices/* inputs/* mounts/* runners/* sources/* stages/org.* stages/test/*.py
TYPEABLES = osbuild

passenv =
Expand Down

0 comments on commit 4e5da79

Please sign in to comment.