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

Function TestResultReaderValuesHaveSameCapacityAsLength

pgconn/pgconn_test.go:1397–1423  ·  view source on GitHub ↗

https://github.com/jackc/pgx/issues/859

(t *testing.T)

Source from the content-addressed store, hash-verified

1395
1396// https://github.com/jackc/pgx/issues/859
1397func TestResultReaderValuesHaveSameCapacityAsLength(t *testing.T) {
1398 t.Parallel()
1399
1400 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
1401 defer cancel()
1402
1403 pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_DATABASE"))
1404 require.NoError(t, err)
1405 defer closeConn(t, pgConn)
1406
1407 result := pgConn.ExecParams(ctx, "select $1::text as msg", [][]byte{[]byte("Hello, world")}, nil, nil, nil)
1408 require.Len(t, result.FieldDescriptions(), 1)
1409 assert.Equal(t, "msg", result.FieldDescriptions()[0].Name)
1410
1411 rowCount := 0
1412 for result.NextRow() {
1413 rowCount += 1
1414 assert.Equal(t, "Hello, world", string(result.Values()[0]))
1415 assert.Equal(t, len(result.Values()[0]), cap(result.Values()[0]))
1416 }
1417 assert.Equal(t, 1, rowCount)
1418 commandTag, err := result.Close()
1419 assert.Equal(t, "SELECT 1", commandTag.String())
1420 assert.NoError(t, err)
1421
1422 ensureConnValid(t, pgConn)
1423}
1424
1425// https://github.com/jackc/pgx/issues/1987
1426func TestResultReaderReadNil(t *testing.T) {

Callers

nothing calls this directly

Calls 10

ConnectFunction · 0.92
NextRowMethod · 0.80
closeConnFunction · 0.70
ensureConnValidFunction · 0.70
LenMethod · 0.65
FieldDescriptionsMethod · 0.65
ValuesMethod · 0.65
CloseMethod · 0.65
ExecParamsMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected