TEST-22: add --dry-run calls

aCdDefLprRwxXz are tested with --dry-run.
I added a primitive test of bc.
There were no tests for AhHt, and I didn't add those either.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-12-08 10:17:04 +01:00
parent 983dbcefe8
commit b214427752
11 changed files with 225 additions and 11 deletions

View file

@ -14,6 +14,14 @@ mkdir /tmp/{C,d,D,e}
mkdir /tmp/d/2
chmod 777 /tmp/d/2
systemd-tmpfiles --dry-run --create - <<EOF
d /tmp/d/1 0755 daemon daemon - -
d /tmp/d/2 0755 daemon daemon - -
EOF
test ! -d /tmp/d/1
test -d /tmp/d/2
systemd-tmpfiles --create - <<EOF
d /tmp/d/1 0755 daemon daemon - -
d /tmp/d/2 0755 daemon daemon - -
@ -104,6 +112,14 @@ chmod 755 /tmp/C/{1,2,3}-origin/f1
mkdir /tmp/C/{2,3}
touch /tmp/C/3/f1
systemd-tmpfiles --dry-run --create - <<EOF
C /tmp/C/1 0755 daemon daemon - /tmp/C/1-origin
C /tmp/C/2 0755 daemon daemon - /tmp/C/2-origin
EOF
test ! -d /tmp/C/1
test -d /tmp/C/2
systemd-tmpfiles --create - <<EOF
C /tmp/C/1 0755 daemon daemon - /tmp/C/1-origin
C /tmp/C/2 0755 daemon daemon - /tmp/C/2-origin

View file

@ -12,6 +12,14 @@ touch /tmp/file-owned-by-root
#
# 'f'
#
systemd-tmpfiles --dry-run --create - <<EOF
f /tmp/f/1 0644 - - - -
f /tmp/f/2 0644 - - - This string should be written
EOF
test ! -e /tmp/f/1
test ! -e /tmp/f/2
systemd-tmpfiles --create - <<EOF
f /tmp/f/1 0644 - - - -
f /tmp/f/2 0644 - - - This string should be written
@ -189,6 +197,11 @@ touch /tmp/w/overwritten
touch /tmp/w/appended
### nop if the target does not exist.
systemd-tmpfiles --dry-run --create - <<EOF
w /tmp/w/unexistent 0644 - - - new content
EOF
test ! -e /tmp/w/unexistent
systemd-tmpfiles --create - <<EOF
w /tmp/w/unexistent 0644 - - - new content
EOF
@ -200,6 +213,12 @@ w /tmp/w/unexistent 0644 - - - -
EOF
### write into an empty file.
systemd-tmpfiles --dry-run --create - <<EOF
w /tmp/w/overwritten 0644 - - - old content
EOF
test -f /tmp/w/overwritten
test -z "$(< /tmp/w/overwritten)"
systemd-tmpfiles --create - <<EOF
w /tmp/w/overwritten 0644 - - - old content
EOF
@ -207,6 +226,12 @@ test -f /tmp/w/overwritten
test "$(< /tmp/w/overwritten)" = "old content"
### old content is overwritten
systemd-tmpfiles --dry-run --create - <<EOF
w /tmp/w/overwritten 0644 - - - new content
EOF
test -f /tmp/w/overwritten
test "$(< /tmp/w/overwritten)" = "old content"
systemd-tmpfiles --create - <<EOF
w /tmp/w/overwritten 0644 - - - new content
EOF
@ -223,6 +248,10 @@ test -f /tmp/w/appended
test "$(< /tmp/w/appended)" = "$(echo -ne '12\n3')"
### writing into an 'exotic' file should be allowed.
systemd-tmpfiles --dry-run --create - <<EOF
w /dev/null - - - - new content
EOF
systemd-tmpfiles --create - <<EOF
w /dev/null - - - - new content
EOF

View file

@ -9,6 +9,12 @@ rm -fr /tmp/p
mkdir /tmp/p
touch /tmp/p/f1
systemd-tmpfiles --dry-run --create - <<EOF
p /tmp/p/fifo1 0666 - - - -
EOF
test ! -p /tmp/p/fifo1
systemd-tmpfiles --create - <<EOF
p /tmp/p/fifo1 0666 - - - -
EOF

View file

@ -12,6 +12,15 @@ mkdir /tmp/{z,Z}
mkdir /tmp/z/d{1,2}
touch /tmp/z/f1 /tmp/z/d1/f11 /tmp/z/d2/f21
systemd-tmpfiles --dry-run --create - <<EOF
z /tmp/z/f1 0755 daemon daemon - -
z /tmp/z/d1 0755 daemon daemon - -
EOF
test "$(stat -c %U /tmp/z/f1)" = "$USER"
test "$(stat -c %U /tmp/z/d1)" = "$USER"
test "$(stat -c %U /tmp/z/d1/f11)" = "$USER"
systemd-tmpfiles --create - <<EOF
z /tmp/z/f1 0755 daemon daemon - -
z /tmp/z/d1 0755 daemon daemon - -

View file

@ -6,7 +6,14 @@ set -eux
set -o pipefail
test_snippet() {
systemd-tmpfiles "$@" - <<EOF
# First call with --dry-run to test the code paths
systemd-tmpfiles --dry-run "$@" - <<EOF
d /var/tmp/foobar-test-06
d /var/tmp/foobar-test-06/important
R /var/tmp/foobar-test-06
EOF
systemd-tmpfiles "$@" - <<EOF
d /var/tmp/foobar-test-06
d /var/tmp/foobar-test-06/important
R /var/tmp/foobar-test-06

View file

@ -12,6 +12,19 @@ mkdir /tmp/x
mkdir -p /tmp/x/{1,2}
touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2}
systemd-tmpfiles --clean --dry-run - <<EOF
d /tmp/x - - - 0
x /tmp/x/1
EOF
find /tmp/x | sort
test -f /tmp/x/1/x1
test -f /tmp/x/1/x2
test -f /tmp/x/2/y1
test -f /tmp/x/2/y2
test -f /tmp/x/z1
test -f /tmp/x/z2
systemd-tmpfiles --clean - <<EOF
d /tmp/x - - - 0
x /tmp/x/1
@ -34,6 +47,19 @@ test ! -f /tmp/x/z2
mkdir -p /tmp/x/{1,2}
touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2}
systemd-tmpfiles --dry-run --clean - <<EOF
d /tmp/x - - - 0
X /tmp/x/1
EOF
find /tmp/x | sort
test -f /tmp/x/1/x1
test -f /tmp/x/1/x2
test -f /tmp/x/2/y1
test -f /tmp/x/2/y2
test -f /tmp/x/z1
test -f /tmp/x/z2
systemd-tmpfiles --clean - <<EOF
d /tmp/x - - - 0
X /tmp/x/1
@ -56,6 +82,20 @@ test ! -f /tmp/x/z2
mkdir -p /tmp/x/{1,2}
touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2}
systemd-tmpfiles --dry-run --clean - <<EOF
d /tmp/x - - - 0
x /tmp/x/[1345]
x /tmp/x/z*
EOF
find /tmp/x | sort
test -f /tmp/x/1/x1
test -f /tmp/x/1/x2
test -f /tmp/x/2/y1
test -f /tmp/x/2/y2
test -f /tmp/x/z1
test -f /tmp/x/z2
systemd-tmpfiles --clean - <<EOF
d /tmp/x - - - 0
x /tmp/x/[1345]
@ -79,6 +119,20 @@ test -f /tmp/x/z2
mkdir -p /tmp/x/{1,2}
touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2}
systemd-tmpfiles --dry-run --clean - <<EOF
d /tmp/x - - - 0
X /tmp/x/[1345]
X /tmp/x/?[12]
EOF
find /tmp/x | sort
test -f /tmp/x/1/x1
test -f /tmp/x/1/x2
test -f /tmp/x/2/y1
test -f /tmp/x/2/y2
test -f /tmp/x/z1
test -f /tmp/x/z2
systemd-tmpfiles --clean - <<EOF
d /tmp/x - - - 0
X /tmp/x/[1345]
@ -102,6 +156,19 @@ test -f /tmp/x/z2
mkdir -p /tmp/x/{1,2}/a
touch /tmp/x/1/a/{x1,x2} /tmp/x/2/a/{y1,y2}
systemd-tmpfiles --dry-run --clean - <<EOF
# x/X is not supposed to influence r
x /tmp/x/1/a
X /tmp/x/2/a
r /tmp/x/1
r /tmp/x/2
EOF
test -f /tmp/x/1/a/x1
test -f /tmp/x/1/a/x2
test -f /tmp/x/2/a/y1
test -f /tmp/x/2/a/y2
systemd-tmpfiles --clean - <<EOF
# x/X is not supposed to influence r
x /tmp/x/1/a
@ -125,6 +192,18 @@ test -f /tmp/x/2/a/y2
mkdir -p /tmp/x/{1,2}/a
touch /tmp/x/1/a/{x1,x2} /tmp/x/2/a/{y1,y2}
systemd-tmpfiles --dry-run --remove - <<EOF
# Check that X is honoured below R
X /tmp/x/1/a
X /tmp/x/2/a
R /tmp/x/1
EOF
test -f /tmp/x/1/a/x1
test -f /tmp/x/1/a/x2
test -f /tmp/x/2/a/y1
test -f /tmp/x/2/a/y2
systemd-tmpfiles --remove - <<EOF
# Check that X is honoured below R
X /tmp/x/1/a
@ -146,6 +225,17 @@ test -f /tmp/x/2/a/y2
touch /tmp/x/{11,22,33}
systemd-tmpfiles --dry-run --remove - <<EOF
# Check that X is honoured below R
r /tmp/x/11
R /tmp/x/22
D /tmp/x/33
EOF
test -f /tmp/x/11
test -f /tmp/x/22
test -f /tmp/x/33
systemd-tmpfiles --remove - <<EOF
# Check that X is honoured below R
r /tmp/x/11

View file

@ -52,6 +52,16 @@ sleep 1
touch /tmp/ageby/d{3,4}/f{2..4}
# Check for cleanup of "f1" in each of "/tmp/d{1..4}".
systemd-tmpfiles --dry-run --clean - <<-EOF
d /tmp/ageby/d1 - - - a:1m -
e /tmp/ageby/d2 - - - m:3m -
D /tmp/ageby/d3 - - - c:2s -
EOF
for d in d{1..3}; do
test -f "/tmp/ageby/${d}/f1"
done
systemd-tmpfiles --clean - <<-EOF
d /tmp/ageby/d1 - - - a:1m -
e /tmp/ageby/d2 - - - m:3m -

View file

@ -12,6 +12,12 @@ mkdir /tmp/L
home='/somewhere'
dst='/tmp/L/1'
src="$home"
HOME="$home" \
systemd-tmpfiles --dry-run --create - <<EOF
L $dst - - - - %h
EOF
test ! -h "$dst"
HOME="$home" \
systemd-tmpfiles --create - <<EOF
L $dst - - - - %h
@ -25,6 +31,12 @@ home='/%U'
src="/usr/share/factory$home"
mkdir -p "$root$src"
dst="$root$home"
HOME="$home" \
systemd-tmpfiles --create --dry-run --root="$root" - <<EOF
L %h - - - -
EOF
test ! -h "$dst"
HOME="$home" \
systemd-tmpfiles --create --root="$root" - <<EOF
L %h - - - -

View file

@ -12,6 +12,11 @@ rm -f /tmp/acl_exec
touch /tmp/acl_exec
# No ACL set yet
systemd-tmpfiles --dry-run --create - <<EOF
a /tmp/acl_exec - - - - u:root:rwX
EOF
assert_not_in 'user:root:rw-' "$(getfacl -Ec /tmp/acl_exec)"
systemd-tmpfiles --create - <<EOF
a /tmp/acl_exec - - - - u:root:rwX
EOF

View file

@ -8,26 +8,27 @@ set -o pipefail
export SYSTEMD_LOG_LEVEL=debug
systemd-tmpfiles --create - <<EOF
c='
d /tmp/somedir
f /tmp/somedir/somefile - - - - baz
EOF
'
systemd-tmpfiles --create - <<<"$c"
test -f /tmp/somedir/somefile
grep -q baz /tmp/somedir/somefile
systemd-tmpfiles --purge - <<EOF
d /tmp/somedir
f /tmp/somedir/somefile - - - - baz
EOF
systemd-tmpfiles --purge --dry-run - <<<"$c"
test -f /tmp/somedir/somefile
grep -q baz /tmp/somedir/somefile
systemd-tmpfiles --purge - <<<"$c"
test ! -f /tmp/somedir/somefile
test ! -d /tmp/somedir/
systemd-tmpfiles --create --purge - <<EOF
d /tmp/somedir
f /tmp/somedir/somefile - - - - baz
EOF
systemd-tmpfiles --create --purge --dry-run - <<<"$c"
test ! -f /tmp/somedir/somefile
test ! -d /tmp/somedir/
systemd-tmpfiles --create --purge - <<<"$c"
test -f /tmp/somedir/somefile
grep -q baz /tmp/somedir/somefile

29
test/units/testsuite-22.19.sh Executable file
View file

@ -0,0 +1,29 @@
#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# Tests for character and block device creation
#
set -eux
set -o pipefail
rm -rf /tmp/dev
mkdir /tmp/dev
# We are running tests in /tmp, which would normally be mounted nodev,
# so we only try with --dry-run.
systemd-tmpfiles --dry-run --create - <<EOF
c /tmp/dev/char - - - - 11:12
b /tmp/dev/block - - - - 11:14
EOF
test ! -e /tmp/dev/char
test ! -e /tmp/dev/block
systemd-tmpfiles --dry-run --create - <<EOF
c+ /tmp/dev/char - - - - 11:12
b+ /tmp/dev/block - - - - 11:14
EOF
test ! -e /tmp/dev/char
test ! -e /tmp/dev/block