Tests that a buffer created with Copy, which when later freed, returns the underlying byte slice to the buffer pool.
(t *testing.T)
| 161 | // Tests that a buffer created with Copy, which when later freed, returns the underlying |
| 162 | // byte slice to the buffer pool. |
| 163 | func (s) TestBuffer_CopyAndFree(t *testing.T) { |
| 164 | data := []byte("abcd") |
| 165 | testPool := &singleBufferPool{ |
| 166 | t: t, |
| 167 | data: &data, |
| 168 | } |
| 169 | |
| 170 | buf := mem.Copy(data, testPool) |
| 171 | if got := buf.ReadOnlyData(); !bytes.Equal(got, data) { |
| 172 | t.Fatalf("Buffer contains data %s, want %s", string(got), string(data)) |
| 173 | } |
| 174 | |
| 175 | // Verify that the free function is invoked when all references are freed. |
| 176 | buf.Free() |
| 177 | if testPool.data != nil { |
| 178 | t.Fatalf("Buffer not freed") |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // Tests that a buffer created with Copy, on which an additional reference is |
| 183 | // acquired, which when later freed, returns the underlying byte slice to the |
nothing calls this directly
no test coverage detected