MCPcopy
hub / github.com/nats-io/nats.go / TestParserSplitMsg

Function TestParserSplitMsg

nats_test.go:710–921  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

708}
709
710func TestParserSplitMsg(t *testing.T) {
711 nc := &Conn{}
712 nc.ps = &parseState{}
713
714 buf := []byte("MSG a\r\n")
715 err := nc.parse(buf)
716 if err == nil {
717 t.Fatal("Expected an error")
718 }
719 nc.ps = &parseState{}
720
721 buf = []byte("MSG a b c\r\n")
722 err = nc.parse(buf)
723 if err == nil {
724 t.Fatal("Expected an error")
725 }
726 nc.ps = &parseState{}
727
728 expectedCount := uint64(1)
729 expectedSize := uint64(3)
730
731 buf = []byte("MSG a")
732 err = nc.parse(buf)
733 if err != nil {
734 t.Fatalf("Parser error: %v", err)
735 }
736 if nc.ps.argBuf == nil {
737 t.Fatal("Arg buffer should have been created")
738 }
739
740 buf = []byte(" 1 3\r\nf")
741 err = nc.parse(buf)
742 if err != nil {
743 t.Fatalf("Parser error: %v", err)
744 }
745 if nc.ps.ma.size != 3 {
746 t.Fatalf("Wrong msg size: %d instead of 3", nc.ps.ma.size)
747 }
748 if nc.ps.ma.sid != 1 {
749 t.Fatalf("Wrong sid: %d instead of 1", nc.ps.ma.sid)
750 }
751 if string(nc.ps.ma.subject) != "a" {
752 t.Fatalf("Wrong subject: '%s' instead of 'a'", string(nc.ps.ma.subject))
753 }
754 if nc.ps.msgBuf == nil {
755 t.Fatal("Msg buffer should have been created")
756 }
757
758 buf = []byte("oo\r\n")
759 err = nc.parse(buf)
760 if err != nil {
761 t.Fatalf("Parser error: %v", err)
762 }
763 if (nc.Statistics.InMsgs != expectedCount) || (nc.Statistics.InBytes != expectedSize) {
764 t.Fatalf("Wrong stats: %d - %d instead of %d - %d", nc.Statistics.InMsgs, nc.Statistics.InBytes, expectedCount, expectedSize)
765 }
766 if (nc.ps.argBuf != nil) || (nc.ps.msgBuf != nil) {
767 t.Fatal("Buffers should be nil now")

Callers

nothing calls this directly

Calls 2

parseMethod · 0.95
FatalfMethod · 0.80

Tested by

no test coverage detected