mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Better split buffer testing for CONNECT, fixes issue #63.
This commit is contained in:
@@ -241,3 +241,51 @@ func TestSplitBufferPubOp5(t *testing.T) {
|
||||
t.Fatalf("c.msgBuf did not snaphot the msg")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitConnectArg(t *testing.T) {
|
||||
c := &client{subs: hashmap.New()}
|
||||
connectAll := []byte("CONNECT {\"verbose\":false,\"ssl_required\":false," +
|
||||
"\"user\":\"test\",\"pedantic\":true,\"pass\":\"pass\"}\r\n")
|
||||
|
||||
argJson := connectAll[8:]
|
||||
|
||||
c1 := connectAll[:5]
|
||||
c2 := connectAll[5:22]
|
||||
c3 := connectAll[22 : len(connectAll)-2]
|
||||
c4 := connectAll[len(connectAll)-2:]
|
||||
|
||||
if err := c.parse(c1); err != nil {
|
||||
t.Fatalf("Unexpected parse error: %v\n", err)
|
||||
}
|
||||
if c.argBuf != nil {
|
||||
t.Fatalf("Unexpected argBug placeholder.\n")
|
||||
}
|
||||
|
||||
if err := c.parse(c2); err != nil {
|
||||
t.Fatalf("Unexpected parse error: %v\n", err)
|
||||
}
|
||||
if c.argBuf == nil {
|
||||
t.Fatalf("Expected argBug to not be nil.\n")
|
||||
}
|
||||
if !bytes.Equal(c.argBuf, argJson[:14]) {
|
||||
t.Fatalf("argBuf not correct, received %q, wanted %q\n", argJson[:14], c.argBuf)
|
||||
}
|
||||
|
||||
if err := c.parse(c3); err != nil {
|
||||
t.Fatalf("Unexpected parse error: %v\n", err)
|
||||
}
|
||||
if c.argBuf == nil {
|
||||
t.Fatalf("Expected argBug to not be nil.\n")
|
||||
}
|
||||
if !bytes.Equal(c.argBuf, argJson[:len(argJson)-2]) {
|
||||
t.Fatalf("argBuf not correct, received %q, wanted %q\n",
|
||||
argJson[:len(argJson)-2], c.argBuf)
|
||||
}
|
||||
|
||||
if err := c.parse(c4); err != nil {
|
||||
t.Fatalf("Unexpected parse error: %v\n", err)
|
||||
}
|
||||
if c.argBuf != nil {
|
||||
t.Fatalf("Unexpected argBug placeholder.\n")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user