-
Notifications
You must be signed in to change notification settings - Fork 346
/
Copy pathtest_validate_multimedia.sh
executable file
·134 lines (112 loc) · 3.65 KB
/
test_validate_multimedia.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
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2016-05-01 20:46:42 +0100 (Sun, 01 May 2016)
#
# https://github.com/HariSekhon/DevOps-Python-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help improve or steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$srcdir/..";
# shellcheck disable=SC1091
. ./tests/utils.sh
section "Testing validate_multimedia.py"
export TIMEOUT=3
if ! type -P ffmpeg &>/dev/null; then
# repos are broken on both Ubuntu until 15 and RHEL/CentOS :-(
# not gonna cause major compilation for this when it works on my dev systems
echo "WARNING: ffmpeg not installed, skipping validate_multimedia.py tests"
exit 0
if type -P apt-get &>/dev/null; then
sudo apt-get install -o DPkg::Lock::Timeout=1200 -y ffmpeg
elif type -P yum &>/dev/null; then
echo "WARNING: cannot auto-install ffmpeg on RHEL/CentOS, the 3rd party repos and deps are seriously broken"
fi
fi
if [ $# -gt 0 ]; then
echo "validate_multimedia.py $*"
./validate_multimedia.py "$@"
echo
fi
data_dir="tests/data"
broken_dir="tests/media_broken"
test_file="$data_dir/sample.mp3"
if ! [ -f "$test_file" ]; then
wget http://www.sample-videos.com/audio/mp3/crowd-cheering.mp3 -O "$test_file"
fi
rm -fr "$broken_dir" || :
mkdir "$broken_dir"
./validate_multimedia.py "$test_file"
echo
echo "checking quick mode"
./validate_multimedia.py --quick "$test_file"
echo
echo "checking directory recursion (mixed with explicit file given)"
./validate_multimedia.py "$test_file" .
echo
echo "checking regex with directory recursion"
./validate_multimedia.py "$test_file" -r '\.mp3$' .
echo
echo "checking symlink handling"
ln -sfv "sample.mp3" "$data_dir/testlink.mp3"
./validate_multimedia.py "$data_dir/testlink.mp3"
rm "$data_dir/testlink.mp3"
echo
echo "checking media file without an extension"
cp -iv "$(find "${1:-.}" -iname '*.mp3' | grep -v -e 'broken' -e 'error' | head -n1)" "$broken_dir/no_extension_testfile"
./validate_multimedia.py "$broken_dir/no_extension_testfile"
echo
check_broken(){
local filename="$1"
local expected_exitcode="${2:-2}"
local options="${*:3}"
set +e
# shellcheck disable=SC2086
./validate_multimedia.py -t 1 $options "$filename"
exitcode=$?
set -e
if [ "$exitcode" = "$expected_exitcode" ]; then
echo "successfully detected broken media in '$filename', returned exit code $exitcode"
echo
#elif [ $exitcode != 0 ]; then
# echo "returned unexpected non-zero exit code $exitcode for broken media in '$filename'"
# exit 1
else
echo "FAILED, returned unexpected exit code $exitcode for broken media in '$filename'"
exit 1
fi
}
check_broken "$data_dir/multirecord.json"
# turns out this isn't broken and still plays
#echo 'blah' > "$broken_dir/broken.mp3"
#cat "$test_file" >> "$broken_dir/broken.mp3"
cp -av "$data_dir/test.csv" "$broken_dir/broken.mp3"
check_broken "$broken_dir/broken.mp3"
echo
echo "Checking failure with continue switch for entire tree"
check_broken . 2 "$test_file" -c
echo "Checking catches broken regex"
check_broken . 3 -r "*.mp3"
echo
echo "checking regex with directory recursion will skip broken file"
./validate_multimedia.py -r 'sample.mp3' .
echo
check_broken_sample_files mp3
rm -fr "$broken_dir"
echo
echo "checking for non-existent file"
check_broken nonexistentfile 2
echo
echo "======="
echo "SUCCESS"
echo "======="
echo
echo