/
linker_internal_test.go
79 lines (67 loc) · 1.66 KB
/
linker_internal_test.go
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
package roc
import (
"testing"
"time"
"github.com/Remote-Oculus-Controller/R.O.C-CONTROLS/test"
"github.com/Remote-Oculus-Controller/proto"
"github.com/Remote-Oculus-Controller/proto/go"
"github.com/golang/protobuf/proto"
)
type ConnParam struct {
lIp, rIp string
lT, rT bool
}
var connParamDefault = ConnParam{
lIp: "",
lT: false,
rIp: ":8004",
rT: true,
}
var l *Linker = newLinker(connParamDefault.lIp, connParamDefault.rIp, connParamDefault.lT, connParamDefault.rT)
func TestLinker_Start(t *testing.T) {
l.start()
client := roc_test.ClientWs{}
go client.Start(connParamDefault.rIp)
<-time.After(time.Millisecond * 200)
if l.local.conn != nil {
t.Error("Local connection should not be set")
}
if l.remote.ws == nil {
t.Error("Remote connection websocket should have been created")
}
client.Stop()
<-time.After(time.Millisecond * 1200)
}
func TestLinker_SendRemote(t *testing.T) {
client := roc_test.ClientWs{}
go client.Start(connParamDefault.rIp)
defer client.Stop()
<-time.After(time.Millisecond * 200)
p := goPack.Prepare(1, rocproto.Packet_COMMAND, rocproto.Packet_CONTROL_SERVER, rocproto.Packet_VIDEO_CLIENT)
err := l.send(p)
if err != nil {
t.Error(err)
}
select {
case <-time.After(time.Millisecond * 5):
t.Error("Time out > 5ms")
default:
b := client.Rcv()
p2 := rocproto.Packet{}
err := proto.Unmarshal(b, &p2)
if err != nil {
t.Error(err)
}
if *p != p2 {
t.Error("Message different from original")
}
}
}
func TestLinker_Stop(t *testing.T) {
l.stop()
in := <-l.remote.in
out := <-l.local.in
if l.remote.ws != nil && in != nil && out != nil {
t.Error("All ressources have not been closed", l.remote)
}
}