Debian Codegraph @

tests/ts/misc/configs

raw
1 #!/bin/bash
2
3 # This file is part of util-linux.
4 #
5 # This file is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9
10 TS_TOPDIR="${0%/*}/../.."
11 TS_DESC="configs"
12
13 . "$TS_TOPDIR"/functions.sh
14 ts_init "$*"
15
16 [ "$("$TS_HELPER_SYSINFO" scandirat-ok)" = "1" ] || ts_skip "no scandirat"
17
18 ts_check_test_command "$TS_HELPER_CONFIGS"
19
20 # Create test directory structure
21 TESTDIR="$TS_OUTDIR/${TS_TESTNAME}-root"
22 ETC_DIR="$TESTDIR/etc"
23 RUN_DIR="$TESTDIR/run"
24 USR_DIR="$TESTDIR/usr"
25
26 mkdir -p "$ETC_DIR/proj"
27 mkdir -p "$RUN_DIR/proj"
28 mkdir -p "$USR_DIR/proj"
29
30 # Test 1: Main config file in /etc
31 ts_init_subtest "main-etc"
32 echo "main config" > "$ETC_DIR/proj/example.conf"
33 find "$TESTDIR" -type f | sed "s|$TESTDIR|@TESTDIR@|g" | sort >> $TS_OUTPUT
34 $TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \
35 --project "proj" --name "example" --suffix "conf" \
36 | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG
37 rm -f "$ETC_DIR/proj/example.conf"
38 ts_finalize_subtest
39
40 # Test 2: Main config file in /usr (fallback)
41 ts_init_subtest "main-usr"
42 echo "usr config" > "$USR_DIR/proj/example.conf"
43 find "$TESTDIR" -type f | sed "s|$TESTDIR|@TESTDIR@|g" | sort >> $TS_OUTPUT
44 $TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \
45 --project "proj" --name "example" --suffix "conf" \
46 | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG
47 rm -f "$USR_DIR/proj/example.conf"
48 ts_finalize_subtest
49
50 # Test 3: Drop-in files from /etc
51 ts_init_subtest "dropin-etc"
52 mkdir -p "$ETC_DIR/proj/example.conf.d"
53 echo "etc drop-in 1" > "$ETC_DIR/proj/example.conf.d/10-first.conf"
54 echo "etc drop-in 2" > "$ETC_DIR/proj/example.conf.d/20-second.conf"
55 find "$TESTDIR" -type f | sed "s|$TESTDIR|@TESTDIR@|g" | sort >> $TS_OUTPUT
56 $TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \
57 --project "proj" --name "example" --suffix "conf" \
58 | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG
59 rm -rf "$ETC_DIR/proj/example.conf.d"
60 ts_finalize_subtest
61
62 # Test 4: Drop-in files from /usr
63 ts_init_subtest "dropin-usr"
64 mkdir -p "$USR_DIR/proj/example.conf.d"
65 echo "usr drop-in 1" > "$USR_DIR/proj/example.conf.d/10-first.conf"
66 echo "usr drop-in 2" > "$USR_DIR/proj/example.conf.d/20-second.conf"
67 find "$TESTDIR" -type f | sed "s|$TESTDIR|@TESTDIR@|g" | sort >> $TS_OUTPUT
68 $TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \
69 --project "proj" --name "example" --suffix "conf" \
70 | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG
71 rm -rf "$USR_DIR/proj/example.conf.d"
72 ts_finalize_subtest
73
74 # Test 5: Main config + drop-ins from multiple directories (priority order)
75 ts_init_subtest "combined"
76 echo "main config" > "$ETC_DIR/proj/example.conf"
77 mkdir -p "$ETC_DIR/proj/example.conf.d"
78 mkdir -p "$RUN_DIR/proj/example.conf.d"
79 mkdir -p "$USR_DIR/proj/example.conf.d"
80 echo "usr drop-in" > "$USR_DIR/proj/example.conf.d/10-base.conf"
81 echo "run drop-in" > "$RUN_DIR/proj/example.conf.d/20-override.conf"
82 echo "etc drop-in" > "$ETC_DIR/proj/example.conf.d/30-local.conf"
83 find "$TESTDIR" -type f | sed "s|$TESTDIR|@TESTDIR@|g" | sort >> $TS_OUTPUT
84 $TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \
85 --project "proj" --name "example" --suffix "conf" \
86 | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG
87 rm -f "$ETC_DIR/proj/example.conf"
88 rm -rf "$ETC_DIR/proj/example.conf.d"
89 rm -rf "$RUN_DIR/proj/example.conf.d"
90 rm -rf "$USR_DIR/proj/example.conf.d"
91 ts_finalize_subtest
92
93 # Test 6: Same basename in multiple directories (masking behavior)
94 ts_init_subtest "masking"
95 mkdir -p "$ETC_DIR/proj/example.conf.d"
96 mkdir -p "$USR_DIR/proj/example.conf.d"
97 echo "usr version" > "$USR_DIR/proj/example.conf.d/10-config.conf"
98 echo "etc version" > "$ETC_DIR/proj/example.conf.d/10-config.conf"
99 find "$TESTDIR" -type f | sed "s|$TESTDIR|@TESTDIR@|g" | sort >> $TS_OUTPUT
100 $TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \
101 --project "proj" --name "example" --suffix "conf" \
102 | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG
103 rm -rf "$ETC_DIR/proj/example.conf.d"
104 rm -rf "$USR_DIR/proj/example.conf.d"
105 ts_finalize_subtest
106
107 # Test 7: No project subdirectory
108 ts_init_subtest "no-project"
109 mkdir -p "$ETC_DIR"
110 echo "root config" > "$ETC_DIR/test.conf"
111 find "$TESTDIR" -type f | sed "s|$TESTDIR|@TESTDIR@|g" | sort >> $TS_OUTPUT
112 $TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \
113 --name "test" --suffix "conf" \
114 | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG
115 rm -f "$ETC_DIR/test.conf"
116 ts_finalize_subtest
117
118 # Test 8: Alphabetical sorting order with main config and masking
119 ts_init_subtest "sorting"
120 echo "main config" > "$ETC_DIR/proj/example.conf"
121 mkdir -p "$ETC_DIR/proj/example.conf.d"
122 mkdir -p "$USR_DIR/proj/example.conf.d"
123 # Create files with names that test sorting and masking
124 echo "aaa from usr" > "$USR_DIR/proj/example.conf.d/aaa.conf"
125 echo "zzz from usr" > "$USR_DIR/proj/example.conf.d/zzz.conf"
126 echo "mmm from usr" > "$USR_DIR/proj/example.conf.d/mmm.conf"
127 echo "bbb from etc" > "$ETC_DIR/proj/example.conf.d/bbb.conf"
128 echo "mmm from etc" > "$ETC_DIR/proj/example.conf.d/mmm.conf" # masks usr/mmm.conf
129 find "$TESTDIR" -type f | sed "s|$TESTDIR|@TESTDIR@|g" | sort >> $TS_OUTPUT
130 $TS_HELPER_CONFIGS --etc "$ETC_DIR" --run "$RUN_DIR" --usr "$USR_DIR" \
131 --project "proj" --name "example" --suffix "conf" \
132 | sed "s|$TESTDIR|@TESTDIR@|g" >> $TS_OUTPUT 2>> $TS_ERRLOG
133 rm -f "$ETC_DIR/proj/example.conf"
134 rm -rf "$ETC_DIR/proj/example.conf.d"
135 rm -rf "$USR_DIR/proj/example.conf.d"
136 ts_finalize_subtest
137
138 ts_finalize