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
|
package test
import (
"testing"
"encoding/hex"
"strings"
)
func TestUpperHook(t *testing.T) {
const msg = "Hello, World!"
c, s := newClientServer(t)
defer closeClientServer(c, s)
tunnel := "add name %s listen,addr=127.0.0.1:0 upper loop"
c.Exec(tunnel, t.Name())
addr := c.Send("get tunnel.%s.listen", t.Name())
conn := xDial(t, "tcp", addr)
defer conn.Close()
xWrite(t, conn, msg)
buf := make([]byte, len(msg))
xReadFull(t, conn, buf)
if r := string(buf); r != strings.ToUpper(msg) {
t.Fatalf("wrong reply: send '%s', recv '%s'", msg, r)
}
}
func TestHexHook(t *testing.T) {
const msg = "Hello, World!"
c, s := newClientServer(t)
defer closeClientServer(c, s)
listen := xListen(t, "tcp", "127.0.0.1:0")
defer listen.Close()
addr := c.AddListenTunnel(t.Name(), "hex dial,addr=%s", listen.Addr())
out := xDial(t, "tcp", addr)
defer out.Close()
in := xAccept(t, listen)
defer in.Close()
xWrite(t, out, msg)
buf := make([]byte, 2*len(msg))
xReadFull(t, in, buf)
if r := string(buf); r != hex.EncodeToString([]byte(msg)) {
t.Fatalf("wrong reply: send '%s', recv '%s'", msg, r)
}
}
|