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

Function TestHandleCopyInCSVWithBlob_NullValues

server/conn_test.go:4054–4118  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4052 if len(conns) != 1 {
4053 t.Fatalf("expected 1 conn, got %d", len(conns))
4054 }
4055 if conns[0].username != "user2" {
4056 t.Errorf("expected username 'user2' after overwrite, got %q", conns[0].username)
4057 }
4058}
4059
4060func TestInitConnsMap(t *testing.T) {
4061 srv := &Server{}
4062 if srv.conns != nil {
4063 t.Fatal("expected nil conns before initConnsMap")
4064 }
4065 srv.initConnsMap()
4066 if srv.conns == nil {
4067 t.Fatal("expected non-nil conns after initConnsMap")
4068 }
4069 // Should be usable
4070 srv.registerConn(&clientConn{pid: 1})
4071 if len(srv.conns) != 1 {
4072 t.Fatalf("expected 1 conn, got %d", len(srv.conns))
4073 }
4074}
4075
4076// writePGMessage writes a PostgreSQL wire protocol message (type byte + int32 length + body)
4077// into w, matching the format wire.ReadMessage() expects.
4078func writePGMessage(w io.Writer, msgType byte, body []byte) {
4079 _ = binary.Write(w, binary.BigEndian, msgType)
4080 _ = binary.Write(w, binary.BigEndian, int32(len(body)+4))
4081 _, _ = w.Write(body)
4082}
4083
4084func TestHandleCopyInCSVWithBlob(t *testing.T) {
4085 db, err := sql.Open("duckdb", ":memory:")
4086 if err != nil {
4087 t.Fatal(err)
4088 }
4089 defer func() { _ = db.Close() }()
4090
4091 // Create table with a BLOB column
4092 _, err = db.Exec("CREATE TABLE test_blob_copy (id VARCHAR, name VARCHAR, data BLOB, count_val INTEGER)")
4093 if err != nil {
4094 t.Fatal(err)
4095 }
4096
4097 // Build CSV data with binary content in the BLOB column
4098 binaryData := make([]byte, 64)
4099 for i := range binaryData {
4100 binaryData[i] = byte(i)
4101 }
4102 var csvBuf bytes.Buffer
4103 csvWriter := csv.NewWriter(&csvBuf)
4104 _ = csvWriter.Write([]string{"id", "name", "data", "count_val"})
4105 _ = csvWriter.Write([]string{"row1", "Alice", string(binaryData), "42"})
4106 _ = csvWriter.Write([]string{"row2", "Bob", string(binaryData[:32]), "99"})
4107 csvWriter.Flush()
4108
4109 // Build protocol messages: CopyData with CSV content, then CopyDone
4110 var msgBuf bytes.Buffer
4111 writePGMessage(&msgBuf, wire.MsgCopyData, csvBuf.Bytes())

Callers

nothing calls this directly

Calls 8

writePGMessageFunction · 0.85
NewLocalExecutorFunction · 0.85
describeColumnTypeTypeAlias · 0.85
CloseMethod · 0.65
ExecMethod · 0.65
ScanMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected