stages/cloud-init: test datasource_list dump format

Add a simple unit test, which ensures that the `datasource_list` key
is dumped in the configuration file on a single line if defined in
the stage options.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2024-01-26 20:37:37 +01:00 committed by Michael Vogt
parent c6edc710f2
commit 73cb074f4b

View file

@ -0,0 +1,29 @@
#!/usr/bin/python3
import os.path
from osbuild.testutil.imports import import_module_from_path
# Test that the 'datasource_list' option is dumped as a single line
# in the configuration file.
def test_cloud_init_datasource_list_single_line(tmp_path):
treedir = tmp_path / "tree"
confpath = treedir / "etc/cloud/cloud.cfg.d/datasource_list.cfg"
confpath.parent.mkdir(parents=True, exist_ok=True)
stage_path = os.path.join(os.path.dirname(__file__), "../org.osbuild.cloud-init")
stage = import_module_from_path("stage", stage_path)
options = {
"filename": confpath.name,
"config": {
"datasource_list": [
"Azure",
]
}
}
stage.main(treedir, options)
assert os.path.exists(confpath)
assert confpath.read_text() == "datasource_list: [Azure]\n"