TestEncodeBinaryJSON verifies that encodeBinary routes JSON/JSONB OIDs through encodeJSON rather than the default text encoder.
(t *testing.T)
| 1447 | // TestEncodeBinaryJSON verifies that encodeBinary routes JSON/JSONB OIDs |
| 1448 | // through encodeJSON rather than the default text encoder. |
| 1449 | func TestEncodeBinaryJSON(t *testing.T) { |
| 1450 | // Simulate what the Go DuckDB driver returns for JSON string "hello": |
| 1451 | // json.Unmarshal('"hello"') produces Go string "hello" (no quotes) |
| 1452 | goValue := "hello" |
| 1453 | |
| 1454 | for _, oid := range []int32{OidJSON, OidJSONB} { |
| 1455 | result := encodeBinary(goValue, oid) |
| 1456 | got := string(result) |
| 1457 | if got != `"hello"` { |
| 1458 | t.Errorf("encodeBinary(%q, OID %d) = %s, want %s", goValue, oid, got, `"hello"`) |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | // Non-JSON OID should NOT add quotes (plain text encoding) |
| 1463 | result := encodeBinary("hello", OidVarchar) |
| 1464 | got := string(result) |
| 1465 | if got != "hello" { |
| 1466 | t.Errorf("encodeBinary(%q, OidVarchar) = %s, want %s", "hello", got, "hello") |
| 1467 | } |
| 1468 | } |
nothing calls this directly
no test coverage detected