MCPcopy
hub / github.com/sqldef/sqldef / TestParseIndexAsync

Function TestParseIndexAsync

database/postgres/parser_test.go:70–116  ·  view source on GitHub ↗

TestParseIndexAsync tests parsing of CREATE INDEX ASYNC without database execution. This is a parse-only test since regular PostgreSQL doesn't support ASYNC (Aurora DSQL only). The parser uses testing=false to allow fallback to the generic parser.

(t *testing.T)

Source from the content-addressed store, hash-verified

68// This is a parse-only test since regular PostgreSQL doesn't support ASYNC (Aurora DSQL only).
69// The parser uses testing=false to allow fallback to the generic parser.
70func TestParseIndexAsync(t *testing.T) {
71 // Create parser with testing=false to enable generic parser fallback
72 sqlParser := NewParser()
73
74 // Test parsing CREATE INDEX ASYNC
75 sql := `CREATE TABLE users (
76 id BIGINT NOT NULL PRIMARY KEY,
77 name VARCHAR(128) DEFAULT 'konsumer'
78);
79CREATE INDEX ASYNC username on users (name);`
80
81 // Parse the schema - should not error (will use generic parser fallback)
82 statements, err := sqlParser.Parse(sql)
83 if err != nil {
84 t.Fatalf("failed to parse CREATE INDEX ASYNC: %v", err)
85 }
86
87 // Verify we got 2 statements
88 if len(statements) != 2 {
89 t.Fatalf("expected 2 statements, got %d", len(statements))
90 }
91
92 // Verify second statement is CREATE INDEX with Async flag
93 indexStmt := statements[1].Statement
94 ddl, ok := indexStmt.(*parser.DDL)
95 if !ok {
96 t.Fatalf("expected DDL statement, got %T", indexStmt)
97 }
98
99 if ddl.Action != parser.CreateIndex {
100 t.Fatalf("expected CreateIndex action, got %v", ddl.Action)
101 }
102
103 if ddl.IndexSpec == nil {
104 t.Fatal("expected IndexSpec to be non-nil")
105 }
106
107 if !ddl.IndexSpec.Async {
108 t.Error("expected Async flag to be true")
109 }
110
111 // Verify the generated DDL string contains ASYNC
112 generatedDDL := statements[1].DDL
113 if !strings.Contains(strings.ToUpper(generatedDDL), "ASYNC") {
114 t.Errorf("expected ASYNC in generated DDL, got: %s", generatedDDL)
115 }
116}
117
118func TestCreateFunctionWithPgquery(t *testing.T) {
119 t.Setenv("PSQLDEF_PARSER", "pgquery")

Callers

nothing calls this directly

Calls 6

ParseMethod · 0.95
NewParserFunction · 0.70
FatalfMethod · 0.65
FatalMethod · 0.65
ErrorMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected