MCPcopy Create free account
hub / github.com/lib/pq / TestByteaOutputFormats

Function TestByteaOutputFormats

encode_test.go:331–366  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

329}
330
331func TestByteaOutputFormats(t *testing.T) {
332 t.Parallel()
333 db := pqtest.MustDB(t)
334 for _, format := range []string{"hex", "escape"} {
335 t.Run("", func(t *testing.T) {
336 // Use transaction to avoid relying on getting the same connection
337 tx := pqtest.Begin(t, db)
338 pqtest.Exec(t, tx, `set local bytea_output to `+format)
339
340 rows := pqtest.Query[[]byte](t, tx, `select decode('5c7800ff6162630108', 'hex')`)
341 want := []byte("\x5c\x78\x00\xff\x61\x62\x63\x01\x08")
342 if !bytes.Equal(rows[0]["decode"], want) {
343 t.Errorf("\nhave: %v\nwant: %v", rows[0]["decode"], want)
344 }
345
346 { // Same but with Prepare
347 stmt := pqtest.Prepare(t, tx, `select decode('5c7800ff6162630108', 'hex')`, db)
348 rows, err := stmt.Query()
349 if err != nil {
350 t.Fatal(err)
351 }
352 if !rows.Next() {
353 t.Fatal(rows.Err())
354 }
355 var have []byte
356 err = rows.Scan(&have)
357 if err != nil {
358 t.Fatal(err)
359 }
360 if !bytes.Equal(have, want) {
361 t.Errorf("\nhave: %v\nwant: %v", have, want)
362 }
363 }
364 })
365 }
366}
367
368func TestAppendEncodedText(t *testing.T) {
369 must := func(buf []byte, x any) []byte {

Callers

nothing calls this directly

Calls 10

MustDBFunction · 0.92
BeginFunction · 0.92
ExecFunction · 0.92
QueryFunction · 0.92
PrepareFunction · 0.92
NextMethod · 0.80
FatalMethod · 0.65
QueryMethod · 0.45
ErrMethod · 0.45
ScanMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…