From ecaa36e085754795b7c79230b177b9991ddfb112 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 2 Nov 2023 16:28:18 +0100 Subject: [PATCH] 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. --- stages/test/org_osbuild_kickstart.py | 1 + stages/test/test_kickstart.py | 53 ++++++++++++++++++++++++++++ tox.ini | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 120000 stages/test/org_osbuild_kickstart.py create mode 100644 stages/test/test_kickstart.py diff --git a/stages/test/org_osbuild_kickstart.py b/stages/test/org_osbuild_kickstart.py new file mode 120000 index 000000000..da529c68f --- /dev/null +++ b/stages/test/org_osbuild_kickstart.py @@ -0,0 +1 @@ +../org.osbuild.kickstart \ No newline at end of file diff --git a/stages/test/test_kickstart.py b/stages/test/test_kickstart.py new file mode 100644 index 000000000..61aab5ba9 --- /dev/null +++ b/stages/test/test_kickstart.py @@ -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() diff --git a/tox.ini b/tox.ini index 30b1b3b72..031a4d90f 100644 --- a/tox.ini +++ b/tox.ini @@ -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/*.* stages/test/*.py TYPEABLES = osbuild passenv =