40 lines
763 B
Go
40 lines
763 B
Go
package tests
|
|
|
|
import (
|
|
"bytes"
|
|
"lux/crypto"
|
|
"lux/net"
|
|
"lux/proto"
|
|
"testing"
|
|
)
|
|
|
|
func TestDgramChannel(t *testing.T) {
|
|
ks := crypto.NewLuxKeyStore("/tmp/keystore.dat")
|
|
keyA, _ := crypto.NewLuxKey(proto.LuxTypeHost)
|
|
|
|
r := net.NewLuxRouter(keyA, ks)
|
|
err := r.CreateInboundChannel(net.LuxChannelInterior, "127.0.0.2:9979")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
outbound, err := net.NewLuxOutboundChannel("127.0.0.2:9979", net.LuxChannelInterior)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
dgram := net.LuxDatagram{
|
|
Target: outbound.Address,
|
|
Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8},
|
|
}
|
|
|
|
r.Start()
|
|
outbound.Send(dgram)
|
|
|
|
recv := r.RecvDgram()
|
|
if !bytes.Equal(dgram.Payload, recv.Payload) {
|
|
t.Log(dgram)
|
|
t.Log(recv)
|
|
t.Log("payloads are not equal!")
|
|
}
|
|
}
|