From 7ab32489bf93f6fff6d2164a177a09ae0a147979 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 9 Oct 2025 22:04:19 +0200 Subject: [PATCH] tests: add regression tests for ul_configs_file_list() Add comprehensive test script for configuration file list functionality with the following test cases: - main-etc: Main config file in /etc - main-usr: Main config file fallback to /usr - dropin-etc: Drop-in files from /etc - dropin-usr: Drop-in files from /usr - combined: Main config + drop-ins from multiple directories - masking: Same basename in multiple directories (masking behavior) - no-project: Configuration without project subdirectory The tests verify proper file discovery, priority ordering across /etc, /run, and /usr directories, and file masking behavior according to the Configuration Files Specification. Signed-off-by: Karel Zak --- tests/commands.sh | 1 + tests/expected/misc/configs-combined | 5 ++ tests/expected/misc/configs-dropin-etc | 3 + tests/expected/misc/configs-dropin-usr | 3 + tests/expected/misc/configs-main-etc | 2 + tests/expected/misc/configs-main-usr | 2 + tests/expected/misc/configs-masking | 2 + tests/expected/misc/configs-no-project | 2 + tests/ts/misc/configs | 109 +++++++++++++++++++++++++ 9 files changed, 129 insertions(+) create mode 100644 tests/expected/misc/configs-combined create mode 100644 tests/expected/misc/configs-dropin-etc create mode 100644 tests/expected/misc/configs-dropin-usr create mode 100644 tests/expected/misc/configs-main-etc create mode 100644 tests/expected/misc/configs-main-usr create mode 100644 tests/expected/misc/configs-masking create mode 100644 tests/expected/misc/configs-no-project create mode 100755 tests/ts/misc/configs diff --git a/tests/commands.sh b/tests/commands.sh index 44b0be660..19f51529c 100644 --- a/tests/commands.sh +++ b/tests/commands.sh @@ -6,6 +6,7 @@ TS_HELPER_BOILERPLATE="${ts_helpersdir}test_boilerplate" TS_HELPER_BYTESWAP="${ts_helpersdir}test_byteswap" TS_HELPER_CANONICALIZE="${ts_helpersdir}test_canonicalize" TS_HELPER_COLORS="${ts_helpersdir}test_colors" +TS_HELPER_CONFIGS="${ts_helpersdir}test_configs" TS_HELPER_CPUSET="${ts_helpersdir}test_cpuset" TS_HELPER_CAP="${ts_helpersdir}test_cap" TS_HELPER_DMESG="${ts_helpersdir}test_dmesg" diff --git a/tests/expected/misc/configs-combined b/tests/expected/misc/configs-combined new file mode 100644 index 000000000..d0ab0edf6 --- /dev/null +++ b/tests/expected/misc/configs-combined @@ -0,0 +1,5 @@ +Found 6 configuration file(s): + @TESTDIR@/etc/proj/example.conf + @TESTDIR@/usr/proj/example.conf.d/10-base.conf + @TESTDIR@/run/proj/example.conf.d/20-override.conf + @TESTDIR@/etc/proj/example.conf.d/30-local.conf diff --git a/tests/expected/misc/configs-dropin-etc b/tests/expected/misc/configs-dropin-etc new file mode 100644 index 000000000..0e567397b --- /dev/null +++ b/tests/expected/misc/configs-dropin-etc @@ -0,0 +1,3 @@ +Found 4 configuration file(s): + @TESTDIR@/etc/proj/example.conf.d/10-first.conf + @TESTDIR@/etc/proj/example.conf.d/20-second.conf diff --git a/tests/expected/misc/configs-dropin-usr b/tests/expected/misc/configs-dropin-usr new file mode 100644 index 000000000..892bf41e0 --- /dev/null +++ b/tests/expected/misc/configs-dropin-usr @@ -0,0 +1,3 @@ +Found 2 configuration file(s): + @TESTDIR@/usr/proj/example.conf.d/10-first.conf + @TESTDIR@/usr/proj/example.conf.d/20-second.conf diff --git a/tests/expected/misc/configs-main-etc b/tests/expected/misc/configs-main-etc new file mode 100644 index 000000000..d5f7afd60 --- /dev/null +++ b/tests/expected/misc/configs-main-etc @@ -0,0 +1,2 @@ +Found 1 configuration file(s): + @TESTDIR@/etc/proj/example.conf diff --git a/tests/expected/misc/configs-main-usr b/tests/expected/misc/configs-main-usr new file mode 100644 index 000000000..c0877030d --- /dev/null +++ b/tests/expected/misc/configs-main-usr @@ -0,0 +1,2 @@ +Found 1 configuration file(s): + @TESTDIR@/usr/proj/example.conf diff --git a/tests/expected/misc/configs-masking b/tests/expected/misc/configs-masking new file mode 100644 index 000000000..4f06221e9 --- /dev/null +++ b/tests/expected/misc/configs-masking @@ -0,0 +1,2 @@ +Found 2 configuration file(s): + @TESTDIR@/etc/proj/example.conf.d/10-config.conf diff --git a/tests/expected/misc/configs-no-project b/tests/expected/misc/configs-no-project new file mode 100644 index 000000000..fbc18d5f6 --- /dev/null +++ b/tests/expected/misc/configs-no-project @@ -0,0 +1,2 @@ +Found 1 configuration file(s): + @TESTDIR@/etc//test.conf diff --git a/tests/ts/misc/configs b/tests/ts/misc/configs new file mode 100755 index 000000000..6df41595d --- /dev/null +++ b/tests/ts/misc/configs @@ -0,0 +1,109 @@ +#!/bin/bash + +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +TS_TOPDIR="${0%/*}/../.." +TS_DESC="configs" + +. "$TS_TOPDIR"/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_HELPER_CONFIGS" + +# Create test directory structure +TESTDIR="$TS_OUTDIR/${TS_TESTNAME}-root" +ETC_DIR="$TESTDIR/etc" +RUN_DIR="$TESTDIR/run" +USR_DIR="$TESTDIR/usr" + +mkdir -p "$ETC_DIR/proj" +mkdir -p "$RUN_DIR/proj" +mkdir -p "$USR_DIR/proj" + +# Test 1: Main config file in /etc +ts_init_subtest "main-etc" +echo "main config" > "$ETC_DIR/proj/example.conf" +$TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \ + --project "proj" --name "example" --suffix "conf" \ + | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG +rm -f "$ETC_DIR/proj/example.conf" +ts_finalize_subtest + +# Test 2: Main config file in /usr (fallback) +ts_init_subtest "main-usr" +echo "usr config" > "$USR_DIR/proj/example.conf" +$TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \ + --project "proj" --name "example" --suffix "conf" \ + | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG +rm -f "$USR_DIR/proj/example.conf" +ts_finalize_subtest + +# Test 3: Drop-in files from /etc +ts_init_subtest "dropin-etc" +mkdir -p "$ETC_DIR/proj/example.conf.d" +echo "etc drop-in 1" > "$ETC_DIR/proj/example.conf.d/10-first.conf" +echo "etc drop-in 2" > "$ETC_DIR/proj/example.conf.d/20-second.conf" +$TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \ + --project "proj" --name "example" --suffix "conf" \ + | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG +rm -rf "$ETC_DIR/proj/example.conf.d" +ts_finalize_subtest + +# Test 4: Drop-in files from /usr +ts_init_subtest "dropin-usr" +mkdir -p "$USR_DIR/proj/example.conf.d" +echo "usr drop-in 1" > "$USR_DIR/proj/example.conf.d/10-first.conf" +echo "usr drop-in 2" > "$USR_DIR/proj/example.conf.d/20-second.conf" +$TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \ + --project "proj" --name "example" --suffix "conf" \ + | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG +rm -rf "$USR_DIR/proj/example.conf.d" +ts_finalize_subtest + +# Test 5: Main config + drop-ins from multiple directories (priority order) +ts_init_subtest "combined" +echo "main config" > "$ETC_DIR/proj/example.conf" +mkdir -p "$ETC_DIR/proj/example.conf.d" +mkdir -p "$RUN_DIR/proj/example.conf.d" +mkdir -p "$USR_DIR/proj/example.conf.d" +echo "usr drop-in" > "$USR_DIR/proj/example.conf.d/10-base.conf" +echo "run drop-in" > "$RUN_DIR/proj/example.conf.d/20-override.conf" +echo "etc drop-in" > "$ETC_DIR/proj/example.conf.d/30-local.conf" +$TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \ + --project "proj" --name "example" --suffix "conf" \ + | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG +rm -f "$ETC_DIR/proj/example.conf" +rm -rf "$ETC_DIR/proj/example.conf.d" +rm -rf "$RUN_DIR/proj/example.conf.d" +rm -rf "$USR_DIR/proj/example.conf.d" +ts_finalize_subtest + +# Test 6: Same basename in multiple directories (masking behavior) +ts_init_subtest "masking" +mkdir -p "$ETC_DIR/proj/example.conf.d" +mkdir -p "$USR_DIR/proj/example.conf.d" +echo "usr version" > "$USR_DIR/proj/example.conf.d/10-config.conf" +echo "etc version" > "$ETC_DIR/proj/example.conf.d/10-config.conf" +$TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \ + --project "proj" --name "example" --suffix "conf" \ + | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG +rm -rf "$ETC_DIR/proj/example.conf.d" +rm -rf "$USR_DIR/proj/example.conf.d" +ts_finalize_subtest + +# Test 7: No project subdirectory +ts_init_subtest "no-project" +mkdir -p "$ETC_DIR" +echo "root config" > "$ETC_DIR/test.conf" +$TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \ + --name "test" --suffix "conf" \ + | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG +rm -f "$ETC_DIR/test.conf" +ts_finalize_subtest + +ts_finalize -- 2.47.3