ComplianceAsCode/content

View on GitHub
tests/shared/rsyslog_log_utils.sh

Summary

Maintainability
Test Coverage
#!/bin/bash
 
RSYSLOG_CONF appears unused. Verify it or export it.
RSYSLOG_CONF='/etc/rsyslog.conf'
RSYSLOG_CONF_DIR appears unused. Verify it or export it.
RSYSLOG_CONF_DIR='/etc/rsyslog.d'
LOG_FILE_PREFIX=test
RSYSLOG_TEST_DIR=/tmp
declare -a RSYSLOG_TEST_LOGS
 
# This function creates test rsyslog log files
# Parameters: $1 - number of log files to be created
function create_rsyslog_test_logs {
local count=$1
 
RSYSLOG_TEST_DIR=$(mktemp -d)
RSYSLOG_TEST_LOGS=()
 
Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
if [ $? -ne 0 ]; then
echo "Failed to create RSYSLOG_TEST_DIR"
exit 1
fi
 
Double quote to prevent globbing and word splitting.
if ! [[ "$count" =~ ^[0-9]+$ ]] || [ $count -eq 0 ]; then
echo "Argument 'count' is not a positive number: $count"
exit 1
fi
 
Double quote to prevent globbing and word splitting.
for ind in $(seq 1 $count); do
local testlog=${RSYSLOG_TEST_DIR}/${LOG_FILE_PREFIX}${ind}.log
Double quote to prevent globbing and word splitting.
touch ${testlog}
RSYSLOG_TEST_LOGS+=("${testlog}")
done;
}