MCPcopy
hub / github.com/grpc/grpc-go / TestSimpleParsing

Method TestSimpleParsing

rpc_util_test.go:201–226  ·  view source on GitHub ↗

ensure EmptyCallOption implements the interface

(t *testing.T)

Source from the content-addressed store, hash-verified

199var _ CallOption = EmptyCallOption{} // ensure EmptyCallOption implements the interface
200
201func (s) TestSimpleParsing(t *testing.T) {
202 bigMsg := bytes.Repeat([]byte{'x'}, 1<<24)
203 for _, test := range []struct {
204 // input
205 p []byte
206 // outputs
207 err error
208 b []byte
209 pt payloadFormat
210 }{
211 {nil, io.EOF, nil, compressionNone},
212 {[]byte{0, 0, 0, 0, 0}, nil, nil, compressionNone},
213 {[]byte{0, 0, 0, 0, 1, 'a'}, nil, []byte{'a'}, compressionNone},
214 {[]byte{1, 0}, io.ErrUnexpectedEOF, nil, compressionNone},
215 {[]byte{0, 0, 0, 0, 10, 'a'}, io.ErrUnexpectedEOF, nil, compressionNone},
216 // Check that messages with length >= 2^24 are parsed.
217 {append([]byte{0, 1, 0, 0, 0}, bigMsg...), nil, bigMsg, compressionNone},
218 } {
219 buf := &fullReader{test.p}
220 parser := &parser{r: buf, bufferPool: mem.DefaultBufferPool()}
221 pt, b, err := parser.recvMsg(math.MaxInt32)
222 if err != test.err || !bytes.Equal(b.Materialize(), test.b) || pt != test.pt {
223 t.Fatalf("parser{%v}.recvMsg(_) = %v, %v, %v\nwant %v, %v, %v", test.p, pt, b, err, test.pt, test.b, test.err)
224 }
225 }
226}
227
228func (s) TestMultipleParsing(t *testing.T) {
229 // Set a byte stream consists of 3 messages with their headers.

Callers

nothing calls this directly

Calls 5

recvMsgMethod · 0.95
DefaultBufferPoolFunction · 0.92
MaterializeMethod · 0.80
EqualMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected