Skip to content
Snippets Groups Projects
Commit 79a89866 authored by Kamil Dudka's avatar Kamil Dudka
Browse files

test/*: store each test-case in a separate script

Closes #132
parent e203730a
No related branches found
No related tags found
No related merge requests found
TEST_CASES = \
test-0001.sh \
test-0002.sh \
test-0003.sh \
test-0004.sh \
test-0005.sh \
test-0006.sh \
test-0007.sh \
test-0008.sh \
test-0009.sh \
test-0010.sh \
test-0011.sh \
test-0012.sh \
test-0013.sh \
test-0014.sh \
test-0015.sh \
test-0016.sh \
test-0017.sh \
test-0018.sh \
test-0019.sh \
test-0020.sh \
test-0021.sh \
test-0022.sh \
test-0023.sh \
test-0024.sh \
test-0025.sh \
test-0026.sh \
test-0027.sh \
test-0028.sh \
test-0029.sh \
test-0030.sh \
test-0031.sh \
test-0032.sh \
test-0033.sh \
test-0034.sh \
test-0035.sh \
test-0036.sh \
test-0037.sh \
test-0038.sh \
test-0039.sh \
test-0040.sh \
test-0041.sh \
test-0042.sh \
test-0043.sh \
test-0044.sh \
test-0045.sh \
test-0046.sh \
test-0047.sh \
test-0048.sh \
test-0049.sh \
test-0050.sh \
test-0051.sh \
test-0052.sh \
test-0053.sh \
test-0054.sh \
test-0055.sh \
test-0056.sh \
test-0057.sh \
test-0058.sh \
test-0059.sh \
test-0060.sh \
test-0061.sh \
test-0062.sh \
test-0063.sh \
test-0064.sh \
test-0065.sh \
test-0066.sh \
test-0067.sh \
test-0068.sh \
test-0069.sh \
test-0070.sh \
test-0071.sh \
test-0072.sh \
test-0073.sh \
test-0100.sh \
test-0101.sh
EXTRA_DIST = \
compress \
compress-error \
Loading
Loading
@@ -6,6 +83,7 @@ EXTRA_DIST = \
test-common.sh \
test-common-acl.sh \
test-common-selinux.sh \
$(TEST_CASES) \
$(top_srcdir)/test/test-config.*.in
 
DISTCLEANFILES = \
Loading
Loading
This diff is collapsed.
#!/bin/bash
. ./test-common.sh
# we don't want any stuff left from previous runs
cleanup 1
# ------------------------------- Test 1 -------------------------------------
# Without a log file, no rotations should occur
preptest test.log 1 2
$RLR test-config.1
checkoutput <<EOF
test.log 0 zero
test.log.1 0 first
EOF
# Put in place a state file that will force a rotation
cat > state <<EOF
logrotate state -- version 1
"$PWD/test.log" 2000-1-1
EOF
# Now force the rotation
$RLR test-config.1
checkoutput <<EOF
test.log 0
test.log.1 0 zero
test.log.2 0 first
EOF
# rerun it to make sure nothing happens
$RLR test-config.1
checkoutput <<EOF
test.log
test.log.1 0 zero
test.log.2 0 first
EOF
#!/bin/bash
. ./test-common.sh
cleanup 2
# ------------------------------- Test 2 -------------------------------------
preptest test.log 2 3
$RLR test-config.2 --force
checkoutput <<EOF
test.log.1 0 zero
test.log.2 0 first
EOF
checkmail test.log.3 second
if [ -f test.log ]; then
echo "erroneously created test.log"
fi
#!/bin/bash
. ./test-common.sh
cleanup 3
# ------------------------------- Test 3 -------------------------------------
preptest test.log 3 1
$RLR test-config.3 --force
checkoutput <<EOF
test.log 0
test.log.1 0 zero
scriptout 0 foo
EOF
cleanup
preptest test.log 3 1
preptest test2.log 3 1
$RLR test-config.3 --force
checkoutput <<EOF
test.log 0
test.log.1 0 zero
test2.log 0
test2.log.1 0 zero
scriptout 0 foo foo
EOF
#!/bin/bash
. ./test-common.sh
cleanup 4
# ------------------------------- Test 4 -------------------------------------
preptest test.log 4 1
preptest test2.log 4 1
$RLR test-config.4 --force
checkoutput <<EOF
test.log 0
test.log.1 0 zero
test2.log 0
test2.log.1 0 zero
scriptout 0 foo
EOF
#!/bin/bash
. ./test-common.sh
cleanup 5
# ------------------------------- Test 5 -------------------------------------
preptest test.log 5 1
preptest anothertest.log 5 1
$RLR test-config.5 --force
checkoutput <<EOF
test.log 0
test.log.1 0 zero
anothertest.log 0
anothertest.log.1 0 zero
scriptout 0 foo
EOF
#!/bin/bash
. ./test-common.sh
cleanup 6
# ------------------------------- Test 6 -------------------------------------
preptest test.log 6 1
preptest anothertest.log 6 1
. ./test-common-selinux.sh
if [ $SELINUX_TESTS = 1 ]; then
chcon --type=logrotate_tmp_t test.log
else
echo "Skipping SELinux part of test 6"
fi
$RLR test-config.6 --force
if [ $SELINUX_TESTS = 1 ]; then
ls -Z test.log.0|grep logrotate_tmp_t >/dev/null
if [ $? != 0 ]; then
echo "test.log.0 should have selinux context logrotate_tmp_t."
exit 3
fi
ls -Z anothertest.log.0|grep logrotate_tmp_t >/dev/null
if [ $? = 0 ]; then
echo "anothertest.log.0 should not have selinux context logrotate_tmp_t."
exit 3
fi
fi
checkoutput <<EOF
test.log 0
test.log.0 0 zero
anothertest.log 0
anothertest.log.0 0 zero
scriptout 0 foo
EOF
#!/bin/bash
. ./test-common.sh
cleanup 7
# ------------------------------- Test 7 -------------------------------------
preptest test.log 7 1
preptest anothertest.log 7 1
$RLR test-config.7 --force
checkoutput <<EOF
test.log 0
test.log.6 0 zero
anothertest.log 0
anothertest.log.6 0 zero
scriptout 0 foo
EOF
#!/bin/bash
. ./test-common.sh
cleanup 8
# ------------------------------- Test 8 -------------------------------------
preptest test.log 8 1 1
$RLR test-config.8 --force
checkoutput <<EOF
test.log 0
test.log.1.gz 1 zero
scriptout 0 foo
EOF
checkmail test.log zero
#!/bin/bash
. ./test-common.sh
cleanup 9
# ------------------------------- Test 9 -------------------------------------
preptest test.log 9 1 1
$RLR test-config.9 --force
checkoutput <<EOF
test.log 0
scriptout 0 foo
EOF
checkmail test.log zero
#!/bin/bash
. ./test-common.sh
cleanup 10
# ------------------------------- Test 10 ------------------------------------
preptest test.log 10 1
. ./test-common-selinux.sh
if [ $SELINUX_TESTS = 1 ]; then
chcon --type=logrotate_tmp_t test.log
else
echo "Skipping SELinux part of test 10"
fi
$RLR test-config.10 --force
checkoutput <<EOF
test.log 0
test.log.1 0 zero
EOF
echo "newfile" > test.log
$RLR test-config.10 --force
if [ $SELINUX_TESTS = 1 ]; then
ls -Z test.log.2.gz|grep logrotate_tmp_t >/dev/null
if [ $? != 0 ]; then
echo "test.log.2.gz should have selinux context logrotate_tmp_t."
ls -Z test.log.2.gz
exit 3
fi
ls -Z test.log.1|grep logrotate_tmp_t >/dev/null
if [ $? != 0 ]; then
echo "test.log.1 should have selinux context logrotate_tmp_t."
ls -Z test.log.1
exit 3
fi
fi
checkoutput <<EOF
test.log 0
test.log.1 0 newfile
test.log.2.gz 1 zero
EOF
checkmail test.log.1 newfile
#!/bin/bash
. ./test-common.sh
cleanup 11
# ------------------------------- Test 11 ------------------------------------
preptest test.log 11 2 1
$RLR test-config.11 --force
checkoutput <<EOF
test.log 0
scriptout 0 foo
EOF
checkmail test.log.2.gz first
#!/bin/bash
. ./test-common.sh
# check rotation into a directory given as a relative pathname
cleanup 12
# ------------------------------- Test 12 ------------------------------------
preptest test.log 12 1 0
rm -rf testdir
mkdir testdir
$RLR test-config.12 --force
checkoutput <<EOF
test.log 0
testdir/test.log.1 0 zero
EOF
rm -rf testdir
#!/bin/bash
. ./test-common.sh
# check rotation into a directory given as an absolute pathname
cleanup 13
# ------------------------------- Test 13 ------------------------------------
preptest test.log 13 1 0
rm -rf testdir
$RLR test-config.13 --force
ls -l|grep testdir|grep "drwx------." 2>/dev/null >/dev/null
if [ $? != 0 ]; then
echo "testdir should have mode 2700, but it has:"
ls -l|grep testdir
exit 3
fi
checkoutput <<EOF
test.log 0
testdir/test.log.1 0 zero
EOF
rm -rf testdir
#!/bin/bash
. ./test-common.sh
# sanity rotation check using dateext and dateformat
cleanup 14
# ------------------------------- Test 14 ------------------------------------
preptest test.log 14 1 0
$RLR test-config.14 --force
DATESTRING=$(/bin/date +%Y-%m-%d)
checkoutput <<EOF
test.log 0
test.log.$DATESTRING 0 zero
EOF
rm -rf testdir
#!/bin/bash
. ./test-common.sh
# shred test
cleanup 15
# ------------------------------- Test 15 ------------------------------------
preptest test.log 15 1 0
$RLR test-config.15 --force
# this rotation should use shred
$RLR test-config.15 --force
checkoutput <<EOF
test.log 0
test.log.1 0
EOF
#!/bin/bash
. ./test-common.sh
cleanup 16
# ------------------------------- Test 16 ------------------------------------
preptest test.log 16 1 0
# log with 1 byte should not be rotated
echo "a" > test.log
$RLR test-config.16
if [ -f test.log.1 ]; then
echo "file $file does exist!"
exit 2
fi
# log with 4 bytes should be rotated
echo "zero" > test.log
$RLR test-config.16
checkoutput <<EOF
test.log 0
test.log.1 0 zero
EOF
#!/bin/bash
. ./test-common.sh
cleanup 17
# ------------------------------- Test 17 ------------------------------------
preptest test.log 17 1 0
# log with 1 byte should not be rotated
$RLR test-config.17 -l logrotate.log 2>error.log
grep "unexpected } (missing previous '{')" error.log >/dev/null
if [ $? != 0 ]; then
echo "No error printed, but there should be one."
exit 3
fi
rm error.log
grep "reading config file test-config.17" logrotate.log >/dev/null
if [ $? != 0 ]; then
echo "There is no log output in logrotate.log"
exit 3
fi
rm -f logrotate.log
checkoutput <<EOF
test.log 0 zero
EOF
#!/bin/bash
. ./test-common.sh
cleanup 18
# ------------------------------- Test 18 ------------------------------------
preptest test.log 18 1
$RLR test-config.18 -l syslog --force
checkoutput <<EOF
test.log 0
test.log.1.Z 1 zero
EOF
(echo "gzip -f -9") | diff -u - compress-args
egrep -q '^LOGROTATE_COMPRESSED_FILENAME=.+/test/test.log.1$' compress-env
if [ $? != 0 ]; then
echo "LOGROTATE_COMPRESSED_FILENAME environment variable not found."
cat compress-env++ exit 3
fi
SYSLOG_TESTS=0
logger syslog_test 2>/dev/null
if [ $? = 0 ]; then
journalctl -n 50 2>/dev/null | grep syslog_test 2>/dev/null >/dev/null
if [ $? = 0 ]; then
SYSLOG_TESTS=1
fi
fi
if [ $SYSLOG_TESTS = 1 ]; then
journalctl -n 50 2>/dev/null|grep $PWD/test.log.1 2>/dev/null >/dev/null
if [ $? != 0 ]; then
echo "syslog message not found"
exit 1
fi
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment