From 73cb074f4bde9a94a7aad2eb18b36cd62d88fe67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Fri, 26 Jan 2024 20:37:37 +0100 Subject: [PATCH] stages/cloud-init: test datasource_list dump format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- stages/test/test_cloud-init.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 stages/test/test_cloud-init.py diff --git a/stages/test/test_cloud-init.py b/stages/test/test_cloud-init.py new file mode 100644 index 00000000..ea994b7f --- /dev/null +++ b/stages/test/test_cloud-init.py @@ -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"