func TestServicePingHandl er testing srv NewTestSrv clm proto NewCloud

 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
func TestServicePingHandler(t *testing.T) {
srv := NewTestSrv()
clm := proto.NewCloudMessage(uuids.UUIDS.Generate().String(), "UniqualIdentificator", "Ident", "", "ping")
data, err := clm.Encode()
if err != nil {
t.Errorf("Cannot encode cloud message to json")
}
pkg := fmt.Sprintf("%s%s", string(data), string('\000'))
visited := false
var handler internet.IMessageHandler = func(Msg internet.IMessage) error {
visited = true
return nil
}
srv.Service.AddHandler("ping", handler)
srv.Service.Start()
con := mocking.NewMockConn(pkg)
srv.Factory.AddConnection(con)
time.Sleep(10 * time.Millisecond)
if visited == false {
t.Errorf("Cannot enter in handler")
}
srv.Service.AddHandler("add", srv.Service.Add)
}