]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (configs) add sorting and masking test
authorKarel Zak <kzak@redhat.com>
Wed, 15 Oct 2025 13:30:06 +0000 (15:30 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 15 Oct 2025 13:30:06 +0000 (15:30 +0200)
Add a new test that verifies:
- Main config file appears first
- Drop-in files are sorted alphabetically
- Files from /etc mask same-named files from /usr
- Priority ordering is correct (etc > usr)

The test creates mmm.conf in both /etc and /usr to verify
that the /etc version takes precedence and /usr version is
masked (not included in output).

Signed-off-by: Karel Zak <kzak@redhat.com>
tests/expected/misc/configs-sorting [new file with mode: 0644]
tests/ts/misc/configs

diff --git a/tests/expected/misc/configs-sorting b/tests/expected/misc/configs-sorting
new file mode 100644 (file)
index 0000000..fe762e8
--- /dev/null
@@ -0,0 +1,12 @@
+@TESTDIR@/etc/proj/example.conf
+@TESTDIR@/etc/proj/example.conf.d/bbb.conf
+@TESTDIR@/etc/proj/example.conf.d/mmm.conf
+@TESTDIR@/usr/proj/example.conf.d/aaa.conf
+@TESTDIR@/usr/proj/example.conf.d/mmm.conf
+@TESTDIR@/usr/proj/example.conf.d/zzz.conf
+Found 5 configuration file(s):
+  @TESTDIR@/etc/proj/example.conf
+  @TESTDIR@/usr/proj/example.conf.d/aaa.conf
+  @TESTDIR@/etc/proj/example.conf.d/bbb.conf
+  @TESTDIR@/etc/proj/example.conf.d/mmm.conf
+  @TESTDIR@/usr/proj/example.conf.d/zzz.conf
index 2f7aacacce53ac0c29c420cf87e667903b0bac32..1457d212c053d9bbf9760289351851927c9d2a53 100755 (executable)
@@ -115,4 +115,24 @@ $TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \
 rm -f "$ETC_DIR/test.conf"
 ts_finalize_subtest
 
+# Test 8: Alphabetical sorting order with main config and masking
+ts_init_subtest "sorting"
+echo "main config" > "$ETC_DIR/proj/example.conf"
+mkdir -p "$ETC_DIR/proj/example.conf.d"
+mkdir -p "$USR_DIR/proj/example.conf.d"
+# Create files with names that test sorting and masking
+echo "aaa from usr" > "$USR_DIR/proj/example.conf.d/aaa.conf"
+echo "zzz from usr" > "$USR_DIR/proj/example.conf.d/zzz.conf"
+echo "mmm from usr" > "$USR_DIR/proj/example.conf.d/mmm.conf"
+echo "bbb from etc" > "$ETC_DIR/proj/example.conf.d/bbb.conf"
+echo "mmm from etc" > "$ETC_DIR/proj/example.conf.d/mmm.conf"  # masks usr/mmm.conf
+find "$TESTDIR" -type f | sed "s|$TESTDIR|@TESTDIR@|g" | sort >> $TS_OUTPUT
+$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 "$USR_DIR/proj/example.conf.d"
+ts_finalize_subtest
+
 ts_finalize