(t *testing.T)
| 329 | } |
| 330 | |
| 331 | func 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 | |
| 368 | func TestAppendEncodedText(t *testing.T) { |
| 369 | must := func(buf []byte, x any) []byte { |
nothing calls this directly
no test coverage detected
searching dependent graphs…