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

Function TestIsDuckDBUtilityCommand

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

Source from the content-addressed store, hash-verified

22 "github.com/posthog/duckgres/server/wire"
23)
24
25func TestIsDuckDBUtilityCommand(t *testing.T) {
26 tests := []struct {
27 name string
28 query string
29 want bool
30 }{
31 // Secret DDL must bypass the PG transpiler — DuckDB-only syntax.
32 {"create secret", `CREATE SECRET foo (TYPE s3)`, true},
33 {"create or replace secret", `CREATE OR REPLACE SECRET foo (TYPE s3)`, true},
34 {"drop secret", `DROP SECRET foo`, true},
35 {"drop secret if exists", `DROP SECRET IF EXISTS foo`, true},
36 // Regression: DuckDB's own ambiguity hint is "DROP <PERSISTENT|TEMPORARY>
37 // SECRET ...". These don't start with "DROP SECRET", so before the fix
38 // they fell through to pg_query and failed with a syntax error on the
39 // PERSISTENT/TEMPORARY keyword.
40 {"drop persistent secret", `DROP PERSISTENT SECRET foo`, true},
41 {"drop persistent secret if exists quoted", `DROP PERSISTENT SECRET IF EXISTS "tenant_alpha_warehouse_prod_s3"`, true},
42 {"drop temporary secret", `DROP TEMPORARY SECRET foo`, true},
43 {"drop temporary secret if exists", `DROP TEMPORARY SECRET IF EXISTS foo`, true},
44 {"case insensitive", `drop persistent secret foo`, true},
45 {"leading comment", "-- cleanup\nDROP PERSISTENT SECRET foo", true},
46 // Not utility commands — must still go through the transpiler.
47 {"select", `SELECT * FROM duckdb_secrets()`, false},
48 {"drop table", `DROP TABLE foo`, false},
49 // Guard the word-boundary check: a name that merely starts with the
50 // keyword text must not be mistaken for the command.
51 {"drop secretive table", `DROP TABLE secretive`, false},
52 }
53 for _, tt := range tests {
54 t.Run(tt.name, func(t *testing.T) {
55 if got := isDuckDBUtilityCommand(tt.query); got != tt.want {
56 t.Errorf("isDuckDBUtilityCommand(%q) = %v, want %v", tt.query, got, tt.want)
57 }
58 })
59 }
60}
61
62func TestIsEmptyQuery(t *testing.T) {

Callers

nothing calls this directly

Calls 2

isDuckDBUtilityCommandFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected