• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyberShadow / aconfmgr / 373

02 Dec 2023 10:51AM UTC coverage: 84.045% (-9.6%) from 93.666%
373

push

github

CyberShadow-Renovate
Update dependency paru to v20231201221822

0 of 1 new or added line in 1 file covered. (0.0%)

410 existing lines in 22 files now uncovered.

3777 of 4494 relevant lines covered (84.05%)

145.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.64
/test/t/lib-matrix-files.bash
1
# Common code for file matrix tests.
2

3
file_kinds=(
2✔
4
        [1]=file
2✔
5
        [2]=dir  # empty
2✔
6
        [3]=link # broken
2✔
7
        [4]=dir  # non-empty
2✔
8
        [5]=link # link to file
2✔
9
        [6]=link # link to dir
2✔
10
)
2✔
11
file_modes=(
2✔
12
        [1]=766
2✔
13
        [2]=776
2✔
14
        [3]=777
2✔
15
)
2✔
16
file_users=(
2✔
17
        [1]=root
2✔
18
        [2]=billy
2✔
19
        [3]=nobody
2✔
20
)
2✔
21

22
function TestMatrixEvalSpec() {
23
        local spec=$1
99✔
24

25
        if [[ "$spec" =~ ^(.)(.)-(.)(.)(.)(.)-(.)(.)(.)(.)-(.)(.)(.)(.)$ ]]
99✔
26
        then
27
                ignored="${BASH_REMATCH[1]}"
99✔
28
                priority="${BASH_REMATCH[2]}"
99✔
29

30
                p_present="${BASH_REMATCH[3]}"
99✔
31
                p_kind="${BASH_REMATCH[4]}"
99✔
32
                p_content="${BASH_REMATCH[5]}"
99✔
33
                p_attr="${BASH_REMATCH[6]}"
99✔
34

35
                f_present="${BASH_REMATCH[7]}"
99✔
36
                f_kind="${BASH_REMATCH[8]}"
99✔
37
                f_content="${BASH_REMATCH[9]}"
99✔
38
                f_attr="${BASH_REMATCH[10]}"
99✔
39

40
                c_present="${BASH_REMATCH[11]}"
99✔
41
                c_kind="${BASH_REMATCH[12]}"
99✔
42
                c_content="${BASH_REMATCH[13]}"
99✔
43
                c_attr="${BASH_REMATCH[14]}"
99✔
44

45
                fn=/dir/"$spec"
99✔
46
        else
47
                FatalError 'Invalid spec syntax: %s\n' "$spec"
×
48
        fi
49
}
50

51
function TestMatrixFileSetup() {
52
        declare -ag specs
2✔
53
        if [[ $# -gt 0 ]]
2✔
54
        then
55
                specs=("$@")
2✔
56
        else
57
                LogEnter 'Expanding specs...\n'
×
58
                specs=({0..1}{0..1}-{0..2}{1..6}{1..1}{1..1}-{0..1}{1..6}{1..2}{1..2}-{0..2}{1..6}{0..3}{1..3})
59
                LogLeave 'Done (%s specs).\n' "$(Color G "${#specs[@]}")"
×
60
        fi
61

62
        LogEnter 'Filtering specs...\n'
2✔
63
        [[ -v BASH_XTRACEFD ]] && set +x
4✔
64
        local specs2=()
65
        local spec
×
66
        for spec in "${specs[@]}"
×
67
        do
68
                local ignored priority p_present p_kind p_content p_attr f_present f_kind f_content f_attr c_present c_kind c_content c_attr fn
×
69
                TestMatrixEvalSpec "$spec"
×
70

71
                # Cull varying properties of absent files
72
                [[ "$p_present" != 0 || ( "$p_kind" == 1 && "$p_content" == 1 && "$p_attr" == 1 ) ]] || continue
×
73
                [[ "$f_present" != 0 || ( "$f_kind" == 1 && "$f_content" == 2 && "$f_attr" == 2 ) ]] || continue
×
74
                [[ "$c_present" == 1 || ( "$c_kind" == 1 && "$c_content" == 3 && "$c_attr" == 3 ) ]] || continue
×
75

76
                # Cull using "same" properties as absent objects
77
                if [[ "$p_present" == 0 && ( "$f_content" == 1 || "$f_attr" == 1 ) ]] ; then continue ; fi
×
78
                if [[ "$p_present" == 0 && ( "$c_content" == 1 || "$c_attr" == 1 ) ]] ; then continue ; fi
×
79
                if [[ "$f_present" == 0 && ( "$c_content" == 2 || "$c_attr" == 2 ) ]] ; then continue ; fi
×
80

81
                # Cull varying content for directories
82
                [[ "$p_kind" != 2 || "$p_content" == 1 ]] || continue
×
83
                [[ "$f_kind" != 2 || "$f_content" == 2 ]] || continue
×
84
                [[ "$c_kind" != 2 || "$c_content" == 3 ]] || continue
×
85

86
                # Cull varying type for content-less config files
87
                if [[ "$c_content" == 0 && "$c_kind" != 1 ]] ; then continue ; fi
×
88

89
                # Cull bad config: if a file is not in a package, asking to delete it doesn't make sense
90
                if [[ "$p_present" == 0 && "$c_present" == 2 ]] ; then continue ; fi
×
91

92
                # Cull bad config: if a package is about to get removed, simultaneously asking to remove a file in that package doesn't make sense
93
                if [[ "$p_present" == 1 && "$c_present" == 2 ]] ; then continue ; fi
×
94

95
                # Cull bad config: if we are not providing the content of some file in the config, it should be in a package
96
                if [[ "$c_content" == 0 && "$p_present" != 2 ]] ; then continue ; fi
×
97

98
                # Cull bad config: configurations should not mention a file if it is in the ignore list
99
                if [[ "$c_present" != 0 && "$ignored" == 1 ]] ; then continue ; fi
×
100

101
                # Cull bad config: can't overwrite a non-empty directory
102
                if [[ "$p_present" != 0 && "$c_present" == 1 && "$p_kind" == 4 && "$c_kind" != [24] ]] ; then continue ; fi
×
103
                if [[ "$f_present" != 0 && "$c_present" == 1 && "$f_kind" == 4 && "$c_kind" != [24] ]] ; then continue ; fi
×
104

105
                specs2+=("$spec")
106
        done
107
        specs=("${specs2[@]}")
108
        unset specs2
×
109
        [[ -v BASH_XTRACEFD ]] && set -x
×
110
        LogLeave 'Done (%s specs).\n' "$(Color G "${#specs[@]}")"
4✔
111

112
        # Check that we didn't cull any given tests
113
        if [[ $# -gt 0 && "${#specs[@]}" -ne $# ]]
4✔
114
        then
115
                local -A saw_fn
×
116

117
                for spec in "${specs[@]}"
×
118
                do
119
                        local ignored priority p_present p_kind p_content p_attr f_present f_kind f_content f_attr c_present c_kind c_content c_attr fn
×
120
                        TestMatrixEvalSpec "$spec"
×
121
                        saw_fn[$spec]=y
×
122
                done
123

124
                LogEnter 'Some tests were culled (%s/%s):\n' \
×
125
                                 "$(Color G "${#specs[@]}")" \
×
126
                                 "$(Color G $#)"
×
127
                local test
×
128
                for test in "$@"
×
129
                do
130
                        if [[ -z "${saw_fn[$test]+x}" ]]
×
131
                        then
132
                                Log 'Test was not included: %q\n' "$test"
×
133
                        fi
134
                done
135
                false
×
136
        fi
137

138
        LogEnter 'Creating package files...\n'
2✔
139
        # shellcheck disable=SC2154
140
        for spec in "${specs[@]}"
33✔
141
        do
142
                local ignored priority p_present p_kind p_content p_attr f_present f_kind f_content f_attr c_present c_kind c_content c_attr fn
33✔
143
                TestMatrixEvalSpec "$spec"
33✔
144

145
                if ((ignored))
33✔
146
                then
147
                        ignore_paths+=("$fn" "$fn/*")
4✔
148
                fi
149

150
                if ((priority))
33✔
151
                then
152
                        priority_files+=("$fn")
6✔
153
                fi
154

155
                if ((p_present))
33✔
156
                then
157
                        TestMatrixAddObj test-package-"$p_present" "$fn" "$p_kind" "$p_content" "$p_attr"
29✔
158
                fi
159
        done
160
        LogLeave
2✔
161

162
        # Non-broken link targets
163
        local i
2✔
164
        for i in 1 2 3
6✔
165
        do
166
                TestAddPackageFile test-package-2 /f$i $i
6✔
167
                TestAddPackageDir test-package-2 /d$i
6✔
168
        done
169

170
        LogEnter 'Installing packages...\n'
2✔
171
        TestAddPackage test-package-1 native explicit
2✔
172
        TestAddPackage test-package-2 native explicit
2✔
173
        TestAddConfig AddPackage test-package-2
2✔
174
        LogLeave
2✔
175

176
        LogEnter 'Creating filesystem/config files...\n'
2✔
177
        # shellcheck disable=SC2154
178
        for spec in "${specs[@]}"
33✔
179
        do
180
                local ignored priority p_present p_kind p_content p_attr f_present f_kind f_content f_attr c_present c_kind c_content c_attr fn
33✔
181
                TestMatrixEvalSpec "$spec"
33✔
182

183
                if ((p_present))
33✔
184
                then
185
                        TestDeleteFile "$fn"
29✔
186
                fi
187
                if ((f_present))
33✔
188
                then
189
                        TestMatrixAddObj '' "$fn" "$f_kind" "$f_content" "$f_attr"
30✔
190
                fi
191

192
                if [[ $c_present == 1 ]]
33✔
193
                then
194
                        if [[ $c_content == 0 ]]
22✔
195
                        then
UNCOV
196
                                TestAddConfig "$(printf 'SetFileProperty %q owner %q' \
×
197
                                                                                "$fn" "${file_users[$c_attr]}")"
2✔
UNCOV
198
                                TestAddConfig "$(printf 'SetFileProperty %q group %q' \
×
199
                                                                                "$fn" "${file_users[$c_attr]}")"
2✔
200
                                if [[ $p_kind != [356] ]]
1✔
201
                                then
UNCOV
202
                                        TestAddConfig "$(printf 'SetFileProperty %q mode %q' \
×
203
                                                                                        "$fn" "${file_modes[$c_attr]}")"
2✔
204
                                fi
205
                        else
206
                                # shellcheck disable=SC2016
207
                                case $c_kind in
42✔
208
                                        1) # file
UNCOV
209
                                                TestAddConfig "$(printf 'printf %%s %q > "$(CreateFile %q %q %q %q)"' \
×
210
                                                                                                "$c_content" "$fn" "${file_modes[$c_attr]}" "${file_users[$c_attr]}" "${file_users[$c_attr]}")"
10✔
211
                                                ;;
212
                                        2) # empty dir
UNCOV
213
                                                TestAddConfig "$(printf 'CreateDir %q %q %q %q' \
×
214
                                                                                                "$fn" "${file_modes[$c_attr]}" "${file_users[$c_attr]}" "${file_users[$c_attr]}")"
8✔
215
                                                ;;
216
                                        3) # broken link
UNCOV
217
                                                TestAddConfig "$(printf 'CreateLink %q %q %q %q' \
×
218
                                                                                                "$fn" "$c_content" "${file_users[$c_attr]}" "${file_users[$c_attr]}")"
14✔
219
                                                ;;
220
                                        4) # non-empty dir
UNCOV
221
                                                TestAddConfig "$(printf 'CreateDir %q %q %q %q' \
×
222
                                                                                                "$fn" "${file_modes[$c_attr]}" "${file_users[$c_attr]}" "${file_users[$c_attr]}")"
8✔
UNCOV
223
                                                TestAddConfig "$(printf 'printf %%s %q > "$(CreateFile %q/%q)"' \
×
224
                                                                                                "$c_content" "$fn" "$c_content")"
8✔
225
                                                ;;
226
                                        5) # link to file
227
                                                TestAddConfig "$(printf 'CreateLink %q %q %q %q' \
×
228
                                                                                                "$fn" "/f$c_content" "${file_users[$c_attr]}" "${file_users[$c_attr]}")"
×
229
                                                ;;
230
                                        6) # link to directory
UNCOV
231
                                                TestAddConfig "$(printf 'CreateLink %q %q %q %q' \
×
232
                                                                                                "$fn" "/d$c_content" "${file_users[$c_attr]}" "${file_users[$c_attr]}")"
2✔
233
                                                ;;
234
                                esac
235

236
                                if [[ $p_present == 2 && $p_kind == 4 && ( $c_kind != 4 || $p_content != "$c_content" ) ]]
36✔
237
                                then
UNCOV
238
                                        TestAddConfig "$(printf 'SetFileProperty %q/%q deleted y' \
×
239
                                                                                        "$fn" "$p_content")"
4✔
240
                                fi
241
                        fi
242
                elif [[ $c_present == 2 ]]
11✔
243
                then
UNCOV
244
                        TestAddConfig "$(printf 'SetFileProperty %q deleted y' \
×
245
                                                                        "$fn")"
4✔
246
                        if [[ $p_present == 2 && $p_kind == 4 ]]
4✔
247
                        then
UNCOV
248
                                TestAddConfig "$(printf 'SetFileProperty %q/%q deleted y' \
×
249
                                                                                "$fn" "$p_content")"
2✔
250
                        fi
251
                fi
252
        done
253
        LogLeave
2✔
254
}
255

256
function TestMatrixAddObj() {
257
        local package=$1
59✔
258
        local fn=$2
59✔
259
        local kind=$3
59✔
260
        local content=$4
59✔
261
        local attr=$5
59✔
262

263
        local ocontent=$content
59✔
264
        [[ "$kind" != 2 ]] || content= # Directories may not have "content"
71✔
265
        [[ "$kind" != 4 ]] || content= # Ditto (but use content for file name)
69✔
266
        [[ "$kind" != 5 ]] || content=/f$content # Link to file
60✔
267
        [[ "$kind" != 6 ]] || content=/d$content # Link to dir
62✔
268

269
        local mode="${file_modes[$attr]}"
59✔
270
        [[ "$kind" != 3 ]] || mode= # Symlinks can't have a mode
77✔
271

272
        TestAddFSObj "$package" "$fn" "${file_kinds[$kind]}" "$content" "$mode" "${file_users[$attr]}" "${file_users[$attr]}"
59✔
273
        [[ "$kind" != 4 ]] || TestAddFSObj "$package" "$fn"/"$ocontent" file "$ocontent"
69✔
274
}
275

276
function TestMatrixCheckObj() {
277
        local path=$1
28✔
278
        local kind=$2
28✔
279
        local content=$3
28✔
280
        local attr=$4
28✔
281

282
        case "$kind" in
28✔
283
                1) # file
284
                        test -f "$path"
8✔
285
                        diff "$path" <(printf %s "$content")
16✔
286
                        diff <(stat --format=%a "$path") <(printf '%s\n' "${file_modes[$attr]}")
24✔
287
                        diff <(stat --format=%U "$path") <(printf '%s\n' "${file_users[$attr]}")
24✔
288
                        diff <(stat --format=%G "$path") <(printf '%s\n' "${file_users[$attr]}")
24✔
289
                        ;;
290
                2) # dir (empty)
291
                        test -d "$path"
6✔
292
                        diff <(stat --format=%a "$path") <(printf '%s\n' "${file_modes[$attr]}")
18✔
293
                        diff <(stat --format=%U "$path") <(printf '%s\n' "${file_users[$attr]}")
18✔
294
                        diff <(stat --format=%G "$path") <(printf '%s\n' "${file_users[$attr]}")
18✔
295
                        diff <(find "$path" -mindepth 1 -printf '%P\n') /dev/null
12✔
296
                        ;;
297
                3) # link (broken)
298
                        test -h "$path"
8✔
299
                        diff <(readlink "$path") <(printf '%s\n' "$content")
24✔
300
                        diff <(stat --format=%U "$path") <(printf '%s\n' "${file_users[$attr]}")
24✔
301
                        diff <(stat --format=%G "$path") <(printf '%s\n' "${file_users[$attr]}")
24✔
302
                        ;;
303
                4) # dir (non-empty)
304
                        test -d "$path"
5✔
305
                        diff <(stat --format=%a "$path") <(printf '%s\n' "${file_modes[$attr]}")
15✔
306
                        diff <(stat --format=%U "$path") <(printf '%s\n' "${file_users[$attr]}")
15✔
307
                        diff <(stat --format=%G "$path") <(printf '%s\n' "${file_users[$attr]}")
15✔
308
                        sudo test -f "$path"/"$content"
5✔
309
                        diff <(sudo find "$path" -mindepth 1 -printf '%P\n') <(printf '%s\n' "$content")
15✔
310
                        ;;
311
                5) # link to file
312
                        test -h "$path"
×
313
                        diff <(readlink "$path") <(printf '/f%s\n' "$content")
×
314
                        diff <(stat --format=%U "$path") <(printf '%s\n' "${file_users[$attr]}")
×
315
                        diff <(stat --format=%G "$path") <(printf '%s\n' "${file_users[$attr]}")
×
316
                        ;;
317
                6) # link to dir
318
                        test -h "$path"
1✔
319
                        diff <(readlink "$path") <(printf '/d%s\n' "$content")
3✔
320
                        diff <(stat --format=%U "$path") <(printf '%s\n' "${file_users[$attr]}")
3✔
321
                        diff <(stat --format=%G "$path") <(printf '%s\n' "${file_users[$attr]}")
3✔
322
                        ;;
323
        esac
324
}
325

326
function TestMatrixFileCheckApply() {
327
        local spec
1✔
328
        for spec in "${specs[@]}"
27✔
329
        do
330
                local ignored priority p_present p_kind p_content p_attr f_present f_kind f_content f_attr c_present c_kind c_content c_attr fn
27✔
331
                TestMatrixEvalSpec "$spec"
27✔
332

333
                LogEnter '%s\n' "$spec"
27✔
334
                if [[ $c_present == 2 ]] # Present as SetFileProperty deleted y
27✔
335
                then
336
                        test ! -e "$fn" -a ! -h "$fn" # Must not exist
2✔
337
                elif [[ $c_present == 1 ]]
25✔
338
                then
339
                        if [[ $c_content == 0 ]]
17✔
340
                        then
341
                                TestMatrixCheckObj "$fn" "$p_kind" "$p_content" "$c_attr" # Kind/content as in package, attr as in config
1✔
342
                        else
343
                                TestMatrixCheckObj "$fn" "$c_kind" "$c_content" "$c_attr" # Must be as in config
16✔
344
                        fi
345
                elif [[ $ignored == 1 && $p_present != 1 && $f_present == 1 ]]
13✔
346
                then
347
                        TestMatrixCheckObj "$fn" "$f_kind" "$f_content" "$f_attr" # Must be as in filesystem
1✔
348
                elif [[ $ignored == 1 && $p_present == 1 && $f_present == 1 && $f_kind == 4 &&
×
349
                                        ( $p_kind != 4 || $p_content != "$f_content" ) ]] # pacman will not delete a non-empty directory
19✔
350
                then
351
                        TestMatrixCheckObj "$fn" "$f_kind" "$f_content" "$f_attr" # Must be as in filesystem
2✔
352
                elif [[ $p_present == 2 ]]
5✔
353
                then
354
                        TestMatrixCheckObj "$fn" "$p_kind" "$p_content" "$p_attr" # Must be as in package
2✔
355
                else
356
                        test ! -e "$fn" -a ! -h "$fn" # Must not exist
3✔
357
                fi
358
                LogLeave 'OK!\n'
27✔
359
        done
360

361
        unset specs file_kinds file_modes file_users
1✔
362
}
363

364
function TestMatrixFileCheckRoundtrip() {
365
        local spec
1✔
366
        for spec in "${specs[@]}"
6✔
367
        do
368
                local ignored priority p_present p_kind p_content p_attr f_present f_kind f_content f_attr c_present c_kind c_content c_attr fn
6✔
369
                TestMatrixEvalSpec "$spec"
6✔
370

371
                LogEnter '%s\n' "$spec"
6✔
372
                if [[ $f_present == 0 ]]
6✔
373
                then
374
                        test ! -e "$fn" -a ! -h "$fn" # Must not exist
×
375
                else
376
                        TestMatrixCheckObj "$fn" "$f_kind" "$f_content" "$f_attr" # Must be as in filesystem
6✔
377
                fi
378
                LogLeave 'OK!\n'
6✔
379
        done
380

381
        unset specs file_kinds file_modes file_users
1✔
382
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc