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

Function TestNestedBeginDetection

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

Source from the content-addressed store, hash-verified

553 }
554}
555
556func TestNestedBeginDetection(t *testing.T) {
557 // Test that we can detect when a nested BEGIN would occur
558 // The actual warning is sent in handleQuery, but we test the detection logic here
559 c := &clientConn{txStatus: txStatusIdle}
560
561 // First BEGIN should work normally
562 c.updateTxStatus("BEGIN")
563 if c.txStatus != txStatusTransaction {
564 t.Errorf("after first BEGIN txStatus = %c, want %c", c.txStatus, txStatusTransaction)
565 }
566
567 // At this point, a second BEGIN should trigger warning behavior
568 // In handleQuery, when cmdType == "BEGIN" && c.txStatus == txStatusTransaction,
569 // we send a warning and return success without calling DuckDB
570 isNestedBegin := c.txStatus == txStatusTransaction
571 if !isNestedBegin {
572 t.Error("expected nested BEGIN to be detected")
573 }
574
575 // Transaction status should remain 'T' (not change to 'I' or 'E')
576 // The warning is sent but the transaction continues
577 if c.txStatus != txStatusTransaction {
578 t.Errorf("txStatus should still be %c after nested BEGIN detection, got %c", txStatusTransaction, c.txStatus)
579 }
580}
581
582func TestIsConnectionBroken(t *testing.T) {

Callers

nothing calls this directly

Calls 2

updateTxStatusMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected