TestTranspile_QuerySourceSet asserts that `SET duckgres.query_source = '...'` is intercepted as a duckgres-namespaced custom GUC (QuerySourceSet populated, not forwarded to DuckDB) and the value is extracted from the statement.
(t *testing.T)
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | // TestTranspile_QuerySourceSet asserts that `SET duckgres.query_source = '...'` |
| 10 | // is intercepted as a duckgres-namespaced custom GUC (QuerySourceSet populated, |
| 11 | // not forwarded to DuckDB) and the value is extracted from the statement. |
| 12 | func TestTranspile_QuerySourceSet(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | input string |
| 16 | want string |
| 17 | }{ |
| 18 | {"set endpoints", "SET duckgres.query_source = 'endpoints'", "endpoints"}, |
| 19 | {"set standard", "SET duckgres.query_source = 'standard'", "standard"}, |
| 20 | {"set local", "SET LOCAL duckgres.query_source = 'endpoints'", "endpoints"}, |
| 21 | {"case-insensitive name", "SET DUCKGRES.QUERY_SOURCE = 'endpoints'", "endpoints"}, |
| 22 | {"case-insensitive value normalized", "SET duckgres.query_source = 'ENDPOINTS'", "endpoints"}, |
| 23 | {"whitespace trimmed", "SET duckgres.query_source = ' standard '", "standard"}, |
| 24 | {"unquoted identifier value", "SET duckgres.query_source = endpoints", "endpoints"}, |
| 25 | {"empty string resets to default", "SET duckgres.query_source = ''", ""}, |
| 26 | {"set to default clears to empty", "SET duckgres.query_source TO DEFAULT", ""}, |
| 27 | {"reset clears to empty", "RESET duckgres.query_source", ""}, |
| 28 | } |
| 29 | |
| 30 | tr := New(DefaultConfig()) |
| 31 | |
| 32 | for _, tt := range tests { |
| 33 | t.Run(tt.name, func(t *testing.T) { |
| 34 | result, err := tr.Transpile(tt.input) |
| 35 | if err != nil { |
| 36 | t.Fatalf("Transpile(%q) error: %v", tt.input, err) |
| 37 | } |
| 38 | if result.QuerySourceSet == nil { |
| 39 | t.Fatalf("Transpile(%q): QuerySourceSet = nil, want non-nil", tt.input) |
| 40 | } |
| 41 | if got := *result.QuerySourceSet; got != tt.want { |
| 42 | t.Errorf("Transpile(%q): QuerySourceSet = %q, want %q", tt.input, got, tt.want) |
| 43 | } |
| 44 | // Custom GUC must never be forwarded to DuckDB. |
| 45 | if result.QuerySourceShow { |
nothing calls this directly
no test coverage detected