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

Method TestBufferSlice_MaterializeToBuffer

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

Source from the content-addressed store, hash-verified

93}
94
95func (s) TestBufferSlice_MaterializeToBuffer(t *testing.T) {
96 tests := []struct {
97 name string
98 in mem.BufferSlice
99 pool mem.BufferPool
100 wantData []byte
101 }{
102 {
103 name: "single",
104 in: mem.BufferSlice{newBuffer([]byte("abcd"), nil)},
105 pool: nil, // MaterializeToBuffer should not use the pool in this case.
106 wantData: []byte("abcd"),
107 },
108 {
109 name: "multiple",
110 in: mem.BufferSlice{
111 newBuffer([]byte("abcd"), nil),
112 newBuffer([]byte("abcd"), nil),
113 newBuffer([]byte("abcd"), nil),
114 },
115 pool: mem.DefaultBufferPool(),
116 wantData: []byte("abcdabcdabcd"),
117 },
118 }
119 for _, tt := range tests {
120 t.Run(tt.name, func(t *testing.T) {
121 defer tt.in.Free()
122 got := tt.in.MaterializeToBuffer(tt.pool)
123 defer got.Free()
124 if !bytes.Equal(got.ReadOnlyData(), tt.wantData) {
125 t.Errorf("BufferSlice.MaterializeToBuffer() = %s, want %s", string(got.ReadOnlyData()), string(tt.wantData))
126 }
127 })
128 }
129}
130
131func (s) TestBufferSlice_Reader(t *testing.T) {
132 bs := mem.BufferSlice{

Callers

nothing calls this directly

Calls 7

DefaultBufferPoolFunction · 0.92
MaterializeToBufferMethod · 0.80
newBufferFunction · 0.70
FreeMethod · 0.65
EqualMethod · 0.65
ReadOnlyDataMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected