From 27e1e9f774888a0a5d537c3965801def4da14f87 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Thu, 15 Aug 2024 16:35:46 +0200 Subject: [PATCH] test/bootc_install_config: parse config for result Different toml libraries write arrays differently, so we can't know exactly what the file contents will look like. Some will write an array in a single line (toml) while others will break it into one element per line (tomli_w). Parse the file that's written by the stage so we can compare the objects instead of the text contents directly. --- stages/test/test_bootc_install_config.py | 29 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/stages/test/test_bootc_install_config.py b/stages/test/test_bootc_install_config.py index 853eb553..c839f6f4 100644 --- a/stages/test/test_bootc_install_config.py +++ b/stages/test/test_bootc_install_config.py @@ -4,6 +4,7 @@ import re import pytest from osbuild import testutil +from osbuild.util import toml STAGE_NAME = "org.osbuild.bootc.install.config" @@ -24,7 +25,15 @@ STAGE_NAME = "org.osbuild.bootc.install.config" } } }, - '[install.filesystem.root]\ntype = "xfs"\n', + { + "install": { + "filesystem": { + "root": { + "type": "xfs" + } + } + } + }, ), ( { @@ -39,7 +48,11 @@ STAGE_NAME = "org.osbuild.bootc.install.config" } } }, - '[install]\nkargs = [ "ro", "biosdevname=0", "net.ifnames=0",]\n', + { + "install": { + "kargs": ["ro", "biosdevname=0", "net.ifnames=0"], + } + }, ), ( { @@ -52,14 +65,20 @@ STAGE_NAME = "org.osbuild.bootc.install.config" } }, }, - '[install]\nblock = [ "tmp2-luks",]\n', + { + "install": { + "block": ["tmp2-luks"] + } + } ) ] ) def test_bootc_install_config(tmp_path, stage_module, options, expected_config): stage_module.main(tmp_path, options) - with open(os.path.join(tmp_path, "usr/lib/bootc/install", options["filename"]), encoding="utf-8") as config_file: - assert config_file.read() == expected_config + # different toml libraries write out arrays in different ways (one line vs many), so we need to parse the result + # to compare + config_data = toml.load_from_file(os.path.join(tmp_path, "usr/lib/bootc/install", options["filename"])) + assert config_data == expected_config @pytest.mark.parametrize(