Files
NixMsg/test/accept/tcp_accept_test.go
T

47 lines
1.1 KiB
Go

package accept
import (
"testing"
"time"
"git.asio.asia/nixevol/NixMsg/test/harness"
)
func TestF21BareTCPLoginSendRecvAck(t *testing.T) {
srv, err := harness.Start(harness.Options{})
if err != nil {
t.Fatal(err)
}
defer func() { _ = srv.Stop() }()
ac := AdminLogin(t, srv)
const password = "password1234"
CreateEndpoint(t, ac, "tcpalice1", password)
CreateEndpoint(t, ac, "tcpbob001", password)
alice := MQTTLoginTCP(t, srv.Addr, "tcpalice1", password)
defer alice.Close()
bob := MQTTLoginTCP(t, srv.Addr, "tcpbob001", password)
defer bob.Close()
send := alice.Request(t, map[string]any{
"v": 1, "type": "send", "rid": "tcp1", "id": "tcp-msg-1",
"to": map[string]any{"kind": "endpoint", "id": "tcpbob001"},
"body": map[string]any{"enc": "utf8", "data": "over-tcp"},
"delay_ms": int64(0),
})
if !send.OK {
t.Fatalf("send: %+v", send)
}
msg := bob.WaitType(t, "msg", 15*time.Second)
if msg["id"] != "tcp-msg-1" {
t.Fatalf("msg: %v", msg)
}
ack := bob.Request(t, map[string]any{
"v": 1, "type": "ack", "rid": "tcp2", "from": "tcpalice1", "id": "tcp-msg-1",
})
if !ack.OK {
t.Fatalf("ack: %+v", ack)
}
}