MCPcopy
hub / github.com/jackc/pgx / TestGetCap

Function TestGetCap

internal/iobufpool/iobufpool_test.go:10–36  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestGetCap(t *testing.T) {
11 tests := []struct {
12 requestedLen int
13 expectedCap int
14 }{
15 {requestedLen: 0, expectedCap: 256},
16 {requestedLen: 128, expectedCap: 256},
17 {requestedLen: 255, expectedCap: 256},
18 {requestedLen: 256, expectedCap: 256},
19 {requestedLen: 257, expectedCap: 512},
20 {requestedLen: 511, expectedCap: 512},
21 {requestedLen: 512, expectedCap: 512},
22 {requestedLen: 513, expectedCap: 1024},
23 {requestedLen: 1023, expectedCap: 1024},
24 {requestedLen: 1024, expectedCap: 1024},
25 {requestedLen: 33554431, expectedCap: 33554432},
26 {requestedLen: 33554432, expectedCap: 33554432},
27
28 // Above 32 MiB skip the pool and allocate exactly the requested size.
29 {requestedLen: 33554433, expectedCap: 33554433},
30 }
31 for _, tt := range tests {
32 buf := iobufpool.Get(tt.requestedLen)
33 assert.Equalf(t, tt.requestedLen, len(*buf), "bad len for requestedLen: %d", len(*buf), tt.requestedLen)
34 assert.Equalf(t, tt.expectedCap, cap(*buf), "bad cap for requestedLen: %d", tt.requestedLen)
35 }
36}
37
38func TestPutHandlesWrongSizedBuffers(t *testing.T) {
39 for putBufSize := range []int{0, 1, 128, 250, 256, 257, 1023, 1024, 1025, 1 << 28} {

Callers

nothing calls this directly

Calls 1

GetFunction · 0.92

Tested by

no test coverage detected