-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·101 lines (80 loc) · 2.22 KB
/
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
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
#!/bin/bash
# local docker test
GREEN='\033[0;32m'
RED='\033[0;31m'
PURPLE='\033[0;35m'
NC='\033[0m' # No Color
# Function to print info messages
info() {
echo -e "${PURPLE}$1${NC}"
}
# Function to print success messages
success() {
echo -e "${GREEN}$1${NC}"
}
# Function to print error messages
error() {
echo -e "${RED}ERROR: $1${NC}"
}
# init
pushd "$(dirname $0)" > /dev/null
EXIT_STATUS=0
img="lang-detect:test"
pltfm="--platform linux/amd64"
info "Building docker image..."
docker build --rm -t $img .
tmp_dir=".test"
if [ -d "$(pwd)/$tmp_dir" ]; then
rm -rf $(pwd)/$tmp_dir
fi
mkdir -p $(pwd)/$tmp_dir
info "List files in cwd"
docker run -v $(pwd):/data -w /data --entrypoint ls $img
info "Test #01: Show help"
docker run $pltfm -v $(pwd):/data -w /data $img --help > /dev/null
if [ $? -eq 0 ]; then
success "passed"
else
error "Failed to run \"--help\" command"
EXIT_STATUS=1
fi
info "Test #02: Extract config"
docker run -v $(pwd):/data -w /data $img config -o $tmp_dir/config.json > /dev/null
if [ -f "$(pwd)/$tmp_dir/config.json" ]; then
success "passed"
else
error "config.json not saved"
EXIT_STATUS=1
fi
info "Test #03: Run lang-detect to pdf"
docker run -v $(pwd):/data -w /data $img lang-detect -i example/air_quality.pdf -o $tmp_dir/air_quality.pdf > /dev/null
if [ -f "$(pwd)/$tmp_dir/air_quality.pdf" ]; then
success "passed"
else
error "lang-detect to pdf failed on example/air_quality.pdf"
EXIT_STATUS=1
fi
info "Test #04: Run lang-detect to txt"
docker run -v $(pwd):/data -w /data $img lang-detect -i example/air_quality.pdf -o $tmp_dir/air_quality.txt > /dev/null
if [ -f "$(pwd)/$tmp_dir/air_quality.txt" ]; then
success "passed"
else
error "lang-detect to pdf failed on example/air_quality.pdf"
EXIT_STATUS=1
fi
info "Test #05: Run lang-detect on pdf with empty page"
docker run -v $(pwd):/data -w /data $img lang-detect -i example/empty_page.pdf -o $tmp_dir/empty_page.txt > /dev/null
if [ -f "$(pwd)/$tmp_dir/empty_page.txt" ]; then
success "passed"
else
error "lang-detect to pdf failed on example/empty_page.pdf"
EXIT_STATUS=1
fi
popd > /dev/null
if [ $EXIT_STATUS -eq 1 ]; then
error "One or more tests failed."
exit 1
else
success "All tests passed."
exit 0
fi