(t *testing.T)
| 495 | } |
| 496 | |
| 497 | func TestEncodeBinary(t *testing.T) { |
| 498 | // Test that encodeBinary dispatches to the correct encoder |
| 499 | tests := []struct { |
| 500 | name string |
| 501 | value interface{} |
| 502 | oid int32 |
| 503 | wantNil bool |
| 504 | checkLen int // expected length, 0 to skip check |
| 505 | }{ |
| 506 | {"nil value", nil, OidInt4, true, 0}, |
| 507 | {"bool true", true, OidBool, false, 1}, |
| 508 | {"int2", int16(42), OidInt2, false, 2}, |
| 509 | {"int4", int32(42), OidInt4, false, 4}, |
| 510 | {"int8", int64(42), OidInt8, false, 8}, |
| 511 | {"float4", float32(3.14), OidFloat4, false, 4}, |
| 512 | {"float8", float64(3.14), OidFloat8, false, 8}, |
| 513 | {"date", time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), OidDate, false, 4}, |
| 514 | {"timestamp", time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), OidTimestamp, false, 8}, |
| 515 | {"bytea", []byte{1, 2, 3}, OidBytea, false, 3}, |
| 516 | {"text", "hello", OidText, false, 5}, |
| 517 | {"varchar", "world", OidVarchar, false, 5}, |
| 518 | } |
| 519 | |
| 520 | for _, tt := range tests { |
| 521 | t.Run(tt.name, func(t *testing.T) { |
| 522 | result := encodeBinary(tt.value, tt.oid) |
| 523 | if tt.wantNil { |
| 524 | if result != nil { |
| 525 | t.Errorf("encodeBinary(%v, %d) should return nil", tt.value, tt.oid) |
| 526 | } |
| 527 | return |
| 528 | } |
| 529 | if result == nil { |
| 530 | t.Errorf("encodeBinary(%v, %d) returned nil unexpectedly", tt.value, tt.oid) |
| 531 | return |
| 532 | } |
| 533 | if tt.checkLen > 0 && len(result) != tt.checkLen { |
| 534 | t.Errorf("encodeBinary(%v, %d) length = %d, want %d", tt.value, tt.oid, len(result), tt.checkLen) |
| 535 | } |
| 536 | }) |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | // Tests for binary parameter decoding functions |
| 541 |
nothing calls this directly
no test coverage detected