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 simple but also cheap and runs
fast.
  • Loading branch information
mvo5 committed Nov 6, 2023
1 parent e9d5b01 commit 025e2bd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion osbuild.spec
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bzip2 -9 osbuild.pp
%py3_install

mkdir -p %{buildroot}%{pkgdir}/stages
install -p -m 0755 $(find stages -type f) %{buildroot}%{pkgdir}/stages/
install -p -m 0755 $(find stages -type f -not -name "test_*.py") %{buildroot}%{pkgdir}/stages/

mkdir -p %{buildroot}%{pkgdir}/assemblers
install -p -m 0755 $(find assemblers -type f) %{buildroot}%{pkgdir}/assemblers/
Expand Down
32 changes: 32 additions & 0 deletions stages/test/test_kickstart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/python3

import os.path

import pytest

from osbuild.testutil.imports import import_module_from_path


@pytest.mark.parametrize("test_input,expected", [
({"lang": "en_US.UTF-8"}, "lang en_US.UTF-8"),
({"keyboard": "us"}, "keyboard us"),
({"timezone": "UTC"}, "timezone UTC"),
({"lang": "en_US.UTF-8",
"keyboard": "us",
"timezone": "UTC",
},
"lang en_US.UTF-8\nkeyboard us\ntimezone UTC"),
])
def test_kickstart(tmp_path, test_input, expected):
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"
options = {"path": ks_path}
options.update(test_input)

ks_stage.main(tmp_path, options)

with open(os.path.join(tmp_path, ks_path), encoding="utf-8") as fp:
ks_content = fp.read()
assert ks_content == expected + "\n"
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/*.* stages/test/*.py
TYPEABLES = osbuild

passenv =
Expand Down

0 comments on commit 025e2bd

Please sign in to comment.