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

Function TestQuerySourceMixedBatchSetThenShow

server/query_source_test.go:131–177  ·  view source on GitHub ↗

TestQuerySourceMixedBatchSetThenShow is the regression for the e2e bug: a single simple query batching `SET duckgres.query_source='endpoints'; SHOW duckgres.query_source` must run BOTH statements in order — the SET (session-side) then the SHOW returning the just-set value. Previously the whole-batch

(t *testing.T)

Source from the content-addressed store, hash-verified

129 ctx: context.Background(),
130 cancel: func() {},
131 txStatus: txStatusIdle,
132 executor: exec,
133 }
134 return c, &out
135}
136
137// selectOneExecutor answers any QueryContext with a single-row RowSet, so a
138// SELECT in a batch alongside the query_source GUC actually executes.
139type selectOneExecutor struct {
140 noopProfiling
141 queryCalls int
142}
143
144func (e *selectOneExecutor) QueryContext(context.Context, string, ...any) (RowSet, error) {
145 e.queryCalls++
146 return &staticCountRowSet{count: 1}, nil
147}
148func (e *selectOneExecutor) ExecContext(context.Context, string, ...any) (ExecResult, error) {
149 return &fakeExecResult{}, nil
150}
151func (e *selectOneExecutor) Query(string, ...any) (RowSet, error) {
152 return nil, errors.New("not implemented")
153}
154func (e *selectOneExecutor) Exec(string, ...any) (ExecResult, error) {
155 return nil, errors.New("not implemented")
156}
157func (e *selectOneExecutor) ConnContext(context.Context) (RawConn, error) {
158 return nil, errors.New("not implemented")
159}
160func (e *selectOneExecutor) PingContext(context.Context) error { return nil }
161func (e *selectOneExecutor) Close() error { return nil }
162
163// TestQuerySourceMixedBatchSetThenShow is the regression for the e2e bug: a
164// single simple query batching `SET duckgres.query_source='endpoints'; SHOW
165// duckgres.query_source` must run BOTH statements in order — the SET
166// (session-side) then the SHOW returning the just-set value. Previously the
167// whole-batch transpile surfaced QuerySourceSet on the first statement and
168// returned early, swallowing the trailing SHOW so it never emitted `endpoints`.
169func TestQuerySourceMixedBatchSetThenShow(t *testing.T) {
170 c, out := newBufferedConn(&selectOneExecutor{})
171
172 if err := c.handleQuery([]byte("SET duckgres.query_source = 'endpoints'; SHOW duckgres.query_source\x00")); err != nil {
173 t.Fatalf("handleQuery: %v", err)
174 }
175
176 msgs := parseWireMsgs(t, out.Bytes())
177
178 // Expect: CommandComplete(SET), RowDescription, DataRow(endpoints),
179 // CommandComplete(SHOW), ReadyForQuery — in that order.
180 var sawSetComplete, sawShowRow, sawShowComplete bool

Callers

nothing calls this directly

Calls 5

newBufferedConnFunction · 0.85
parseWireMsgsFunction · 0.85
describeMsgsFunction · 0.85
handleQueryMethod · 0.80
QuerySourceMethod · 0.80

Tested by

no test coverage detected