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

Method TestBufferSlice_ReadAll_WriteTo

mem/buffer_slice_test.go:367–411  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

365}
366
367func (s) TestBufferSlice_ReadAll_WriteTo(t *testing.T) {
368 testcases := []struct {
369 name string
370 size int
371 }{
372 {
373 name: "small",
374 size: minReadSize,
375 },
376 {
377 name: "exact size",
378 size: readAllBufSize,
379 },
380 {
381 name: "big",
382 size: readAllBufSize * 3,
383 },
384 }
385 for _, tc := range testcases {
386 t.Run(tc.name, func(t *testing.T) {
387 pool := &testPool{
388 allocated: make(map[*[]byte]struct{}),
389 }
390 buf := make([]byte, tc.size)
391 _, err := rand.Read(buf)
392 if err != nil {
393 t.Fatal(err)
394 }
395 r := bytes.NewBuffer(buf)
396 data, err := mem.ReadAll(r, pool)
397 if err != nil {
398 t.Fatal(err)
399 }
400
401 gotData := data.Materialize()
402 if !bytes.Equal(buf, gotData) {
403 t.Fatalf("ReadAll() = %q, wanted %q", gotData, buf)
404 }
405 data.Free()
406 if len(pool.allocated) > 0 {
407 t.Fatalf("wanted no allocated buffers, got %d", len(pool.allocated))
408 }
409 })
410 }
411}
412
413func ExampleNewWriter() {
414 var bs mem.BufferSlice

Callers

nothing calls this directly

Calls 7

ReadAllFunction · 0.92
MaterializeMethod · 0.80
ReadMethod · 0.65
FatalMethod · 0.65
EqualMethod · 0.65
FatalfMethod · 0.65
FreeMethod · 0.65

Tested by

no test coverage detected