Five tests for logger with result check.
This commit is contained in:
14
README.md
14
README.md
@@ -8,9 +8,14 @@ Checks a given folder for certain file extensions recursively. All found files w
|
|||||||
|
|
||||||
The [check_folder_for_extension test folder](cffe_test) contains of 13 files, 12 of them images, which should be found by the test.
|
The [check_folder_for_extension test folder](cffe_test) contains of 13 files, 12 of them images, which should be found by the test.
|
||||||
|
|
||||||
function call:
|
Function call:
|
||||||
```
|
```
|
||||||
check_folder ./cffe_test "*.jpg *.JPG"
|
check_folder $my_folder $extension_list
|
||||||
|
```
|
||||||
|
|
||||||
|
To test the function call:
|
||||||
|
```
|
||||||
|
check_folder_for_extension.sh ./cffe_test "*.jpg *.JPG"
|
||||||
```
|
```
|
||||||
For multiple extensions (or other parts of the file name to match) space separate the list, like shown above.
|
For multiple extensions (or other parts of the file name to match) space separate the list, like shown above.
|
||||||
|
|
||||||
@@ -59,3 +64,8 @@ produces the following message in the log file:
|
|||||||
```
|
```
|
||||||
logger 20231122_22:43:19 Warning: This is my message!
|
logger 20231122_22:43:19 Warning: This is my message!
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For testing the function call the script with just:
|
||||||
|
```
|
||||||
|
logger.sh
|
||||||
|
```
|
||||||
|
|||||||
75
logger.sh
75
logger.sh
@@ -6,10 +6,10 @@ LLWarning=3
|
|||||||
LLInfo=4
|
LLInfo=4
|
||||||
LLDebug=5
|
LLDebug=5
|
||||||
## Actual log level of the logger used
|
## Actual log level of the logger used
|
||||||
Log_Level=$LLDebug
|
Log_Level=$LLInfo
|
||||||
|
|
||||||
## Name of the logging script
|
## base name of the logging script.
|
||||||
Log_Name="myscript";
|
Log_Name="${0##*/}";
|
||||||
|
|
||||||
## Write log of the script.
|
## Write log of the script.
|
||||||
## $1 Loglevel to log the message with.
|
## $1 Loglevel to log the message with.
|
||||||
@@ -34,18 +34,79 @@ function logger() {
|
|||||||
fi
|
fi
|
||||||
printf "$Log_Name ${_now}${_type} ${_log_message}\n" >> $Log_File;
|
printf "$Log_Name ${_now}${_type} ${_log_message}\n" >> $Log_File;
|
||||||
if [[ $Log_Level -eq $LLDebug ]]; then
|
if [[ $Log_Level -eq $LLDebug ]]; then
|
||||||
printf "$Log_Name ${_now}${_type} ${_log_message}\n";
|
printf "${_now}${_type} ${_log_message}\n";
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
echo $DATE
|
printf "Running tests for logger().\n";
|
||||||
|
local _exit_val=0;
|
||||||
|
# Test log level mute: no logfile should be created!
|
||||||
|
Log_Level=$LLMute;
|
||||||
|
logger $LLMdtry "In level mute nothing should be logged!";
|
||||||
|
if [ -e "$Log_File" ]; then # the logfile should not exist!
|
||||||
|
((_exit_val+=1))
|
||||||
|
printf "logger() test on log level Mute: FAILED!\n";
|
||||||
|
rm $Log_File;
|
||||||
|
else
|
||||||
|
printf "logger() test on log level Mute: OK.\n";
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test log level Mdtry, but log with level error: still no logfile should be created!
|
||||||
|
Log_Level=$LLMdtry;
|
||||||
|
logger $LLError "In level Mdtry an error should not be logged!";
|
||||||
|
if [ -e "$Log_File" ]; then # the logfile should not exist!
|
||||||
|
((_exit_val+=1))
|
||||||
|
printf "logger() test on log level Mandatory; logging an error happend, so test FAILED!\n";
|
||||||
|
rm $Log_File;
|
||||||
|
else
|
||||||
|
printf "logger() test on log level Mandatory: when logging an error failed: test OK.\n";
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test log level Info, but log with level error: logfile should be created!
|
||||||
|
Log_Level=$LLInfo;
|
||||||
|
logger $LLError "In level Info an error should be logged!";
|
||||||
|
if [ -e "$Log_File" ]; then # the logfile should now exist.
|
||||||
|
printf "logger() test on log level Info: logging an error succeeded, test OK.\n";
|
||||||
|
rm $Log_File;
|
||||||
|
else
|
||||||
|
((_exit_val+=1))
|
||||||
|
printf "logger() test on log level Info: logging an error FAILED!\n";
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test log level Info, but log with level debug: logfile should not be created!
|
||||||
|
Log_Level=$LLInfo;
|
||||||
|
logger $LLDebug "In level Info a debug message should not be logged!";
|
||||||
|
if [ -e "$Log_File" ]; then # the logfile should not exist.
|
||||||
|
((_exit_val+=1))
|
||||||
|
printf "logger() test on log level Info: logging a debug message succeeded, so test FAILED!\n";
|
||||||
|
rm $Log_File;
|
||||||
|
else
|
||||||
|
printf "logger() test on log level Info: logging a debug message failed: test OK.\n";
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test log level Debug, but log with level debug: logfile should be created!
|
||||||
|
Log_Level=$LLDebug;
|
||||||
|
logger $LLDebug "In level Debug a debug message should be logged. ALso the message should appaer on std out.";
|
||||||
|
if [ -e "$Log_File" ]; then # the logfile should not exist.
|
||||||
|
printf "logger() test on log level Debug: logging a debug message succeeded, so test OK.\n";
|
||||||
|
rm $Log_File;
|
||||||
|
else
|
||||||
|
((_exit_val+=1))
|
||||||
|
printf "logger() test on log level Debug: logging a debug message failed: test FAILED!\n";
|
||||||
|
fi
|
||||||
|
|
||||||
|
return $_exit_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
DATE=$(which date);
|
DATE=$(which date);
|
||||||
|
|
||||||
Run_Date=$($DATE +%Y_%m_%d)
|
Run_Date=$($DATE +%Y_%m_%d)
|
||||||
Log_File="/tmp/${Run_Date}_${Log_Name}.log";
|
Log_File="${Run_Date}_${Log_Name}.log";
|
||||||
|
|
||||||
|
|
||||||
test
|
test
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
printf "All test succeeded.\n";
|
||||||
|
else
|
||||||
|
printf "$? of 5 tests FAILED!\n";
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user