MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / TestRead

Function TestRead

IceFireDB-PubSub/test/proto/proto_test.go:31–118  ·  view source on GitHub ↗

https://github.com/antirez/RESP3/blob/master/spec.md

(t *testing.T)

Source from the content-addressed store, hash-verified

29
30// https://github.com/antirez/RESP3/blob/master/spec.md
31func TestRead(t *testing.T) {
32 test := func(t *testing.T, payload string) {
33 t.Helper()
34
35 r := bufio.NewReader(strings.NewReader(payload + "+ping\r\n"))
36 cmd, err := Read(r)
37 if err != nil {
38 t.Errorf("read: %s", err)
39 return
40 }
41 if cmd != payload {
42 t.Errorf("have %q, want %q", cmd, payload)
43 return
44 }
45
46 // should not have eaten bytes for the next command
47 peek, err := r.Peek(7)
48 if err != nil {
49 t.Errorf("peek: %s", err)
50 return
51 }
52 if have, want := string(peek), "+ping\r\n"; have != want {
53 t.Errorf("have %q, want %q", have, want)
54 }
55 }
56
57 t.Run("blob strings", func(t *testing.T) {
58 test(t, "$11\r\nhello world\r\n")
59 test(t, "$0\r\n\r\n")
60 })
61
62 t.Run("simple strings", func(t *testing.T) {
63 test(t, "+abc\r\n")
64 test(t, "+\r\n")
65 })
66
67 t.Run("simple errors", func(t *testing.T) {
68 test(t, "-ERR wrong\r\n")
69 })
70
71 t.Run("numbers", func(t *testing.T) {
72 test(t, ":10\r\n")
73 })
74
75 t.Run("floats", func(t *testing.T) {
76 test(t, ",10\r\n")
77 test(t, ",10.0\r\n")
78 test(t, ",10.123\r\n")
79 test(t, ",inf\r\n")
80 test(t, ",-inf\r\n")
81 })
82
83 t.Run("null", func(t *testing.T) {
84 test(t, "_\r\n")
85 })
86
87 t.Run("array", func(t *testing.T) {
88 test(t, "*0\r\n")

Callers

nothing calls this directly

Calls 2

ReadFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected