(t *testing.T)
| 820 | } |
| 821 | |
| 822 | func TestDecodeBinary(t *testing.T) { |
| 823 | tests := []struct { |
| 824 | name string |
| 825 | data []byte |
| 826 | oid int32 |
| 827 | expected interface{} |
| 828 | wantErr bool |
| 829 | }{ |
| 830 | {"nil data", nil, OidInt4, nil, false}, |
| 831 | {"bool true", []byte{1}, OidBool, true, false}, |
| 832 | {"bool false", []byte{0}, OidBool, false, false}, |
| 833 | {"int2", []byte{0x00, 0x2A}, OidInt2, int16(42), false}, |
| 834 | {"int4", []byte{0x00, 0x00, 0x00, 0x2A}, OidInt4, int32(42), false}, |
| 835 | {"int4 zero", []byte{0x00, 0x00, 0x00, 0x00}, OidInt4, int32(0), false}, |
| 836 | {"int8", []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A}, OidInt8, int64(42), false}, |
| 837 | {"bytea", []byte{0x01, 0x02, 0x03}, OidBytea, []byte{0x01, 0x02, 0x03}, false}, |
| 838 | {"text", []byte("hello"), OidText, "hello", false}, |
| 839 | {"unknown type defaults to text", []byte("test"), int32(9999), "test", false}, |
| 840 | // Error cases |
| 841 | {"int4 insufficient data", []byte{0x00, 0x00}, OidInt4, nil, true}, |
| 842 | {"int8 insufficient data", []byte{0x00, 0x00, 0x00, 0x00}, OidInt8, nil, true}, |
| 843 | } |
| 844 | |
| 845 | for _, tt := range tests { |
| 846 | t.Run(tt.name, func(t *testing.T) { |
| 847 | result, err := decodeBinary(tt.data, tt.oid) |
| 848 | if tt.wantErr { |
| 849 | if err == nil { |
| 850 | t.Errorf("decodeBinary(%v, %d) expected error, got nil", tt.data, tt.oid) |
| 851 | } |
| 852 | return |
| 853 | } |
| 854 | if err != nil { |
| 855 | t.Errorf("decodeBinary(%v, %d) unexpected error: %v", tt.data, tt.oid, err) |
| 856 | return |
| 857 | } |
| 858 | |
| 859 | // Special handling for byte slices |
| 860 | if expectedBytes, ok := tt.expected.([]byte); ok { |
| 861 | resultBytes, ok := result.([]byte) |
| 862 | if !ok { |
| 863 | t.Errorf("decodeBinary(%v, %d) = %T, want []byte", tt.data, tt.oid, result) |
| 864 | return |
| 865 | } |
| 866 | if len(resultBytes) != len(expectedBytes) { |
| 867 | t.Errorf("decodeBinary(%v, %d) length = %d, want %d", tt.data, tt.oid, len(resultBytes), len(expectedBytes)) |
| 868 | return |
| 869 | } |
| 870 | for i, b := range resultBytes { |
| 871 | if b != expectedBytes[i] { |
| 872 | t.Errorf("decodeBinary(%v, %d)[%d] = %d, want %d", tt.data, tt.oid, i, b, expectedBytes[i]) |
| 873 | } |
| 874 | } |
| 875 | return |
| 876 | } |
| 877 | |
| 878 | if result != tt.expected { |
| 879 | t.Errorf("decodeBinary(%v, %d) = %v (%T), want %v (%T)", tt.data, tt.oid, result, result, tt.expected, tt.expected) |
nothing calls this directly
no test coverage detected