MCPcopy
hub / github.com/sqldef/sqldef / TestCreateFunctionAutoModeFallbackRetry

Function TestCreateFunctionAutoModeFallbackRetry

database/postgres/parser_test.go:147–183  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestCreateFunctionAutoModeFallbackRetry(t *testing.T) {
148 // Force Auto mode regardless of an ambient PSQLDEF_PARSER (the dev/CI default
149 // is generic, which would skip pgquery entirely and never exercise this path).
150 t.Setenv("PSQLDEF_PARSER", "")
151 postgresParser := NewParserWithMode(PsqldefParserModeAuto)
152
153 // The table uses a storage parameter the generic parser rejects, forcing a
154 // whole-file fallback to pgquery. The CREATE FUNCTION must survive that
155 // fallback instead of being dropped as an Ignore, otherwise the diff engine
156 // emits a spurious DROP FUNCTION for a function that is in the desired schema.
157 statements, err := postgresParser.Parse(`
158 CREATE TABLE t (id int) WITH (fillfactor = 70);
159 CREATE FUNCTION increment(i integer) RETURNS integer
160 LANGUAGE plpgsql
161 AS $$
162 BEGIN
163 RETURN i + 1;
164 END;
165 $$;
166 `)
167 if err != nil {
168 t.Fatalf("failed to parse: %v", err)
169 }
170
171 var foundFunction bool
172 for _, stmt := range statements {
173 if _, ok := stmt.Statement.(*parser.Ignore); ok {
174 t.Errorf("statement was dropped as Ignore: %q", stmt.DDL)
175 }
176 if ddl, ok := stmt.Statement.(*parser.DDL); ok && ddl.Action == parser.CreateFunction {
177 foundFunction = true
178 }
179 }
180 if !foundFunction {
181 t.Error("CREATE FUNCTION was not preserved across pgquery fallback in Auto mode")
182 }
183}
184
185func TestParseCheckConstraintMultiArgBoolExprWithPgquery(t *testing.T) {
186 t.Setenv("PSQLDEF_PARSER", "pgquery")

Callers

nothing calls this directly

Calls 5

NewParserWithModeFunction · 0.85
ParseMethod · 0.65
FatalfMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected