test: add TEST-21-SYSUSERS test

This test tests the systemd-sysuser binary via the --root=$TESTDIR
option and ensures that for the given inputs the expected passwd
and group files will be generated.
This commit is contained in:
Michael Vogt 2018-01-24 11:18:46 +01:00
parent 5bc9c980d0
commit 1e589ed264
11 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,4 @@
BUILD_DIR=$(shell ../../tools/find-build-dir.sh)
all setup clean run:
@basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@

View File

@ -0,0 +1,2 @@
g1:x:111:
u1:x:222:

View File

@ -0,0 +1 @@
u1:x:222:222::/:/sbin/nologin

View File

@ -0,0 +1,3 @@
#Type Name ID GECOS HOMEDIR
u u1 222 - -
g g1 111 - -

View File

@ -0,0 +1 @@
u1:x:999:

View File

@ -0,0 +1 @@
u1:x:999:999:some gecos:/random/dir:/sbin/nologin

View File

@ -0,0 +1,2 @@
#Type Name ID GECOS HOMEDIR
u u1 - "some gecos" /random/dir

View File

@ -0,0 +1,4 @@
hoge:x:300:
baz:x:302:
foo:x:301:
ccc:x:306:

View File

@ -0,0 +1,4 @@
foo:x:301:301::/:/sbin/nologin
aaa:x:303:302::/:/sbin/nologin
bbb:x:304:302::/:/sbin/nologin
ccc:x:305:306::/:/sbin/nologin

View File

@ -0,0 +1,7 @@
g hoge 300 - -
u foo 301 - -
g baz 302 - -
u aaa 303:302 - -
u bbb 304:302 - -
u ccc 305:306 - -

30
test/TEST-21-SYSUSERS/test.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
set -e
TEST_DESCRIPTION="Sysuser-related tests"
. $TEST_BASE_DIR/test-functions
test_setup() {
mkdir -p $TESTDIR/etc $TESTDIR/usr/lib/sysusers.d $TESTDIR/tmp
}
test_run() {
for f in test-*.input; do
echo "***** Running $f"
rm -f $TESTDIR/etc/*
cp $f $TESTDIR/usr/lib/sysusers.d/test.conf
${BUILD_DIR}/systemd-sysusers --root=$TESTDIR
if ! diff -u $TESTDIR/etc/passwd ${f%.*}.expected-passwd; then
echo "**** Unexpected output for $f"
exit 1
fi
if ! diff -u $TESTDIR/etc/group ${f%.*}.expected-group; then
echo "**** Unexpected output for $f"
exit 1
fi
done
}
do_test "$@"