MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestEncodeBinaryJSON

Function TestEncodeBinaryJSON

server/types_test.go:1449–1468  ·  view source on GitHub ↗

TestEncodeBinaryJSON verifies that encodeBinary routes JSON/JSONB OIDs through encodeJSON rather than the default text encoder.

(t *testing.T)

Source from the content-addressed store, hash-verified

1447// TestEncodeBinaryJSON verifies that encodeBinary routes JSON/JSONB OIDs
1448// through encodeJSON rather than the default text encoder.
1449func 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}

Callers

nothing calls this directly

Calls 1

encodeBinaryFunction · 0.85

Tested by

no test coverage detected