-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctional_tests.sh
162 lines (131 loc) · 5.02 KB
/
functional_tests.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
# Undupes: Find duplicate files.
# Copyright (C) 2024 Mmanu Chaturvedi <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# SPDX-License-Identifier: AGPL-3.0
# SPDX-FileCopyrightText: 2024 Mmanu Chaturvedi <[email protected]>
set -euo pipefail
TMP_DIR=$(mktemp -d /tmp/func_test-XXXXX)
export TMP_DIR
function cleanup() {
declare -i ret_code=$?
if [[ $ret_code -ne 0 ]]; then
echo "Test failed."
fi
rm -rf ${TMP_DIR}
}
trap 'cleanup' EXIT
declare -r UNDUPES=${UNDUPES:-${PWD}/build/install/bin/undupes}
export UNDUPES
declare -r ORIG_DIR=${PWD}
function vanilla_test() {
find tests/artifacts/dir_3 -type f -print0 | sort -z | ${UNDUPES} |
jq '.[].file_list' >${TMP_DIR}/a.txt
diff ${TMP_DIR}/a.txt tests/artifacts/functional_test/expected_dir_3_output.txt
}
function summary_test() {
find tests/artifacts/dir_3 -type f -print0 | sort -z | ${UNDUPES} -m >${TMP_DIR}/b.txt
diff ${TMP_DIR}/b.txt tests/artifacts/functional_test/expected_dir_3_summary.txt
}
function test_with_j_f_dupes() {
declare -a DIRS_TO_CHECK=(
${PWD}
$HOME/Downloads
$HOME/Music
$HOME/Desktop
$HOME/bin
)
for dir_name in ${DIRS_TO_CHECK[@]}; do
if [[ -d $dir_name ]]; then
# Checks with jdupes
python3 test_with_fdupes.py $dir_name | grep 'Perfect Match!'
# Checkes with fdupes
PROG_NAME="fdupes" python3 test_with_fdupes.py $dir_name | grep 'Perfect Match!'
fi
done
}
function delete_test() {
# remove 1KB_1.copy.1 1_KB_1.copy.3 1KB_2.copy.3 3KB_1.copy.2 all 4KB_1
cp -R tests/artifacts/dir_3 ${TMP_DIR}
# TODO: Read up.
# https://stackoverflow.com/questions/20532195/socat-with-a-virtual-tty-link-and-fork-removes-my-pty-link
cat tests/artifacts/functional_test/expected_dir_3_delete_1.in |
socat stdio exec:'bash -x tests/artifacts/functional_test/delete_script.sh',pty,setsid,echo=0
pushd ${TMP_DIR}/dir_3
declare -a DOES_NOT_EXIST=(1KB_1.copy.1 1KB_1.copy.3 1KB_2.copy.3 3KB_1.copy.2
4KB_1 4KB_1.copy.1 4KB_1.copy.2 4KB_1.copy.3 4KB_1.copy.4 4KB_1.copy.5)
declare -a EXISTS=(1KB_1 1KB_1.copy.2 1KB_2 1KB_2.copy.1 1KB_2.copy.2 1KB_3 1KB_4 1KB_5 3KB_1 3KB_1.copy.1 3KB_1.copy.3 3KB_2 4KB_4)
for f in ${DOES_NOT_EXIST[@]}; do
if [[ -e $f ]]; then false; fi
done
for f in ${EXISTS[@]}; do
if ! [[ -e $f ]]; then false; fi
done
popd
cp -R tests/artifacts/dir_3 ${TMP_DIR}
pushd ${TMP_DIR}
find . -type f -print0 | ${UNDUPES} >${TMP_DIR}/dir_3_op.json
popd
diff ${TMP_DIR}/dir_3_op.json tests/artifacts/functional_test/expected_dir_3.json
diff <(ls -1 tests/artifacts/dir_3) <(ls -1 ${TMP_DIR}/dir_3)
}
function dry_run_test() {
cp -R tests/artifacts/dir_3 ${TMP_DIR}
declare -a DOES_NOT_EXIST=(1KB_1.copy.1 1KB_1.copy.3 1KB_2.copy.3 3KB_1.copy.2
4KB_1 4KB_1.copy.1 4KB_1.copy.2 4KB_1.copy.3 4KB_1.copy.4 4KB_1.copy.5)
cat tests/artifacts/functional_test/expected_dir_3_delete_1.in |
socat stdio exec:'bash -x tests/artifacts/functional_test/delete_script_dry_run.sh',pty,setsid,echo=0
for f in ${DOES_NOT_EXIST[@]}; do
echo "\"${TMP_DIR}/dir_3/$f\"" >>${TMP_DIR}/expected_dry_run.out
done
diff <(cat ${TMP_DIR}/dry_run.out | sort) <(cat ${TMP_DIR}/expected_dry_run.out | sort)
diff <(ls -1 tests/artifacts/dir_3) <(ls -1 ${TMP_DIR}/dir_3)
}
function warnings_test() {
find tests/artifacts -print0 |
${UNDUPES} -m 2>${TMP_DIR}/warnings_test.out
cat ${TMP_DIR}/warnings_test.out | cut -f16 -d' ' >${TMP_DIR}/warning_file_names.out
find tests/artifacts -type d >${TMP_DIR}/artifacts_dir_names.txt
echo "tests/artifacts/broken_symlink_1" >>${TMP_DIR}/artifacts_dir_names.txt
echo "tests/artifacts/nested_broken_symlink_1" >>${TMP_DIR}/artifacts_dir_names.txt
echo "tests/artifacts/symlink_3" >>${TMP_DIR}/artifacts_dir_names.txt
diff <(cat ${TMP_DIR}/warning_file_names.out | sort) \
<(cat ${TMP_DIR}/artifacts_dir_names.txt | sort)
}
function timeout_test() {
sleep 10 | ${UNDUPES} >${TMP_DIR}/timeout.stdout 2>${TMP_DIR}/timeout.stderr
if [[ $(cat ${TMP_DIR}/timeout.stdout) != "" ]]; then false; fi
stderr_content=$(
cat <<EOF
Timeout occurred.
terminate called without an active exception
EOF
)
if [[ $(cat ${TMP_DIR}/timeout.stderr) != "$stderr_content" ]]; then false; fi
}
function sorting_test() {
find tests/artifacts/dir_3 -type f -print0 | sort -z |
${UNDUPES} >${TMP_DIR}/sorted.out
diff ${TMP_DIR}/sorted.out tests/io/sorted_file_list.out
}
# timeout_test
vanilla_test
summary_test
test_with_j_f_dupes
delete_test
dry_run_test
warnings_test
sorting_test
echo "Tests passed."