-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathtests.sh
executable file
·96 lines (79 loc) · 3.59 KB
/
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
#!/usr/bin/env bash
#
# Some unit-tests
# (require bash and socat to be installed)
set -ue
port=${1:-12345}
pidfile=/tmp/sockproc-test.pid
sockfile=/tmp/sockproc-test.sock
function cleanup() {
kill `cat $pidfile` && rm -f $pidfile
}
trap cleanup EXIT
function runtests() {
dest=$1
title=$2
echo -e "======= $title =================="
# simple commands
echo -e "uname -a\r\n0\r\n" | socat -t10 - $dest
echo -e "id\r\n0\r\n" | socat -t10 - $dest
# long-running command
echo -e "date +%s; sleep 1; date +%s\r\n0\r\n" | socat -t10 - $dest
# commands with some input
echo -e "wc -l\r\n12\r\nline1\r\nline2" | socat -t10 - $dest
echo -e "grep line\r\n20\r\nline1\r\nline2\r\nfoobar" | socat -t10 - $dest
# bad command.expecting non-empty error stream
echo -e "thisshouldfail\r\n0\r\n" | socat -t10 - $dest
# this should have data in both output and error streams
echo -e "echo hello output && echo hello error >&2\r\n0\r\n" | socat -t10 - $dest
# long command line strings
echo -e "echo "\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"1234567890123456789012345678901234567890"\
"\r\n0\r\n" | socat -t10 - $dest
}
./sockproc $port $pidfile
runtests tcp-connect:127.0.0.1:$port "TCP mode"
cleanup
./sockproc $sockfile $pidfile
runtests $sockfile "UNIX-socket mode"
echo -e "================================"