File size: 1,280 Bytes
1e08a04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/sh

if [ "$1" = "" ]; then
    echo "Give me a server start cmd, example: $0 'python index.py production'"
    exit 1
fi

file_map="iDuSh22faxqj:6q1d i0gZ322ututi: i7tit9c:6svq i4wk2oh: iRujgdfrkza: dkbdv7:"
server_run_cmd="$1"
test_server="http://localhost:3000"

$server_run_cmd >/dev/null 2>&1 &
server_pid=$!
sleep 1
if ! kill -0 $server_pid 2>/dev/null; then
    echo "Starting server failed"
    exit 1
fi
while ! curl -sm1 $test_server >/dev/null 2>&1; do sleep 1; done

ln_fmt="%10s%10s%20s%15s\n"
printf "$ln_fmt" RET FUN FID PWD
has_error=0
for file in $file_map; do
    fid=${file%:*}
    pwd=${file#*:}
    url="$test_server/?url=https://wwbg.lanpw.com/$fid&pwd=$pwd"
    status_code=$(curl -sm5 -o /dev/null -I -w "%{http_code}" "$url&type=down")
    ret="OK"
    if [ "$status_code" != "302" ]; then
        ret="FAILED"
        has_error=1
    fi
    printf "$ln_fmt" "$ret" DLOAD "$fid" "$pwd"

    ret="OK"
    json_repl=$(curl -sm5 "$url&type=json")
    code=$(echo "$json_repl" | grep -oP '"code":\K[^,]*')
    if [ "$code" != "200" ]; then
        ret="FAILED"
        has_error=1
    fi
    printf "$ln_fmt" "$ret" GJSON "$fid" "$pwd"
done

if [ $has_error -eq 0 ]; then
    echo "All test passed"
fi

kill $server_pid 1>/dev/null 2>&1
exit $has_error