-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean-up.test.sh
executable file
·65 lines (52 loc) · 1.46 KB
/
clean-up.test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# test script for clean-up.sh script
# font attributes
NORMAL="\e[0m"
BOLD="\e[1m"
# colors
DEFAULT="\e[39m"
GREEN="\e[32m"
RED="\e[31m"
# get dir of script and change into
function changeIntoCurrentDir() {
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$DIR"
}
function setColorSuccessful() {
echo -e -n "$BOLD$GREEN"
}
function setColorFailed() {
echo -e -n "$BOLD$RED"
}
function resetColorAndFontFormat() {
echo -e -n "$NORMAL$DEFAULT"
}
function test_scriptShouldRemoveAllArchivesExceptConfiguredAmount() {
# before: create folders to test script
./test-prep.sh
INITIAL_STATE=($(ls *.zip -1 --sort=time))
# testrun: execute script
./clean-up.sh --number-of-elements 3 --path .
# assert: only the newest 3 acrhives should remain
REMAINING_ARCHIVES=($(ls *.zip -1 --sort=time))
DIFF_EXIT_CODE=$(diff <(printf "${INITIAL_STATE[@]}") <(printf "${REMAINING_ARCHIVES[@]}"); echo $?)
if [[ ${DIFF_EXIT_CODE} -eq 0 ]]; then
setColorSuccessful
echo -e -n "Test succesfully run"
resetColorAndFontFormat
else
setColorFailed
echo -e -n "Test failed"
resetColorAndFontFormat
fi
# clean up after run
for archive in ${REMAINING_ARCHIVES[@]}; do
rm $archive
done
echo -e "$NORMAL $DEFAULT"
}
function runTests() {
changeIntoCurrentDir
test_scriptShouldRemoveAllArchivesExceptConfiguredAmount
}
runTests