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

Function TestDecode

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

Source from the content-addressed store, hash-verified

290}
291
292func TestDecode(t *testing.T) {
293 tests := []struct {
294 typ oid.Oid
295 format format
296 in []byte
297 want any
298 wantErr string
299 }{
300 {oid.T_char, formatText, []byte("hello world"), "hello world", ``},
301 {oid.T_bpchar, formatText, []byte("hello world"), "hello world", ``},
302 {oid.T_varchar, formatText, []byte("hello world"), "hello world", ``},
303 {oid.T_text, formatText, []byte("hello world"), "hello world", ``},
304
305 {oid.T_uuid, formatBinary, []byte{0x12, 0x34}, ([]byte)(nil), `pq: unable to decode uuid; bad length: 2`},
306 }
307
308 for _, tt := range tests {
309 t.Run("", func(t *testing.T) {
310 have, err := decode(nil, tt.in, tt.typ, tt.format)
311 if !pqtest.ErrorContains(err, tt.wantErr) {
312 t.Fatalf("wrong error:\nhave: %s\nwant: %s", err, tt.wantErr)
313 }
314 if !reflect.DeepEqual(have, tt.want) {
315 t.Errorf("\nhave: %#v\nwant: %#v", have, tt.want)
316 }
317 })
318 }
319}
320
321func TestEncodeBytea(t *testing.T) {
322 have, err := encode([]byte("\\x\x00\x01\x02\xFF\xFEabcdefg0123"), oid.T_bytea)

Callers

nothing calls this directly

Calls 2

ErrorContainsFunction · 0.92
decodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…