Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

test: fix TestPGXxx tests (#1818)

rebelice0f794605d241
diff --git a/plugin/parser/engine/pg/convert_test.go b/plugin/parser/engine/pg/convert_test.go
index 55d4c15599..cb748876a2 100644
--- a/plugin/parser/engine/pg/convert_test.go
+++ b/plugin/parser/engine/pg/convert_test.go
@@ -12,8 +12,9 @@ import (
)
type testData struct {
- stmt string
- want []ast.Node
+ stmt string
+ want []ast.Node
+ textList []string
}
func runTests(t *testing.T, tests []testData) {
@@ -22,6 +23,9 @@ func runTests(t *testing.T, tests []testData) {
for _, test := range tests {
res, err := p.Parse(parser.Context{}, test.stmt)
require.NoError(t, err)
+ for i := range test.want {
+ test.want[i].SetText(test.textList[i])
+ }
require.Equal(t, test.want, res, test.stmt)
}
}
@@ -42,6 +46,9 @@ func TestPGConvertCreateTableStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "CREATE TABLE \"techBook\" (a int, b int)",
+ },
},
{
stmt: "CREATE TABLE IF NOT EXISTS techBook (\"A\" int, b int)",
@@ -57,6 +64,9 @@ func TestPGConvertCreateTableStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "CREATE TABLE IF NOT EXISTS techBook (\"A\" int, b int)",
+ },
},
{
stmt: "CREATE TABLE tech_book(a INT CONSTRAINT t_pk_a PRIMARY KEY)",
@@ -79,6 +89,9 @@ func TestPGConvertCreateTableStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "CREATE TABLE tech_book(a INT CONSTRAINT t_pk_a PRIMARY KEY)",
+ },
},
{
stmt: "CREATE TABLE tech_book(a INT, b int CONSTRAINT uk_b UNIQUE, CONSTRAINT t_pk_a PRIMARY KEY(a))",
@@ -111,6 +124,9 @@ func TestPGConvertCreateTableStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "CREATE TABLE tech_book(a INT, b int CONSTRAINT uk_b UNIQUE, CONSTRAINT t_pk_a PRIMARY KEY(a))",
+ },
},
{
stmt: "CREATE TABLE tech_book(a INT CONSTRAINT fk_a REFERENCES people(id), CONSTRAINT fk_a_people_b FOREIGN KEY (a) REFERENCES people(b))",
@@ -148,6 +164,9 @@ func TestPGConvertCreateTableStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "CREATE TABLE tech_book(a INT CONSTRAINT fk_a REFERENCES people(id), CONSTRAINT fk_a_people_b FOREIGN KEY (a) REFERENCES people(b))",
+ },
},
}
@@ -175,6 +194,9 @@ func TestPGAddColumnStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "ALTER TABLE techbook ADD COLUMN a int",
+ },
},
{
stmt: "ALTER TABLE techbook ADD COLUMN a int CONSTRAINT uk_techbook_a UNIQUE",
@@ -204,6 +226,9 @@ func TestPGAddColumnStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "ALTER TABLE techbook ADD COLUMN a int CONSTRAINT uk_techbook_a UNIQUE",
+ },
},
}
@@ -222,6 +247,9 @@ func TestPGRenameTableStmt(t *testing.T) {
NewName: "techBook",
},
},
+ textList: []string{
+ "ALTER TABLE techbook RENAME TO \"techBook\"",
+ },
},
}
@@ -241,6 +269,9 @@ func TestPGRenameColumnStmt(t *testing.T) {
NewName: "ABC",
},
},
+ textList: []string{
+ "ALTER TABLE techbook RENAME abc TO \"ABC\"",
+ },
},
}
@@ -258,6 +289,9 @@ func TestPGRenameConstraintStmt(t *testing.T) {
NewName: "UK_TECH_A",
},
},
+ textList: []string{
+ "ALTER TABLE tech_book RENAME CONSTRAINT uk_tech_a to \"UK_TECH_A\"",
+ },
},
}
@@ -283,6 +317,9 @@ func TestPGCreateIndexStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "CREATE INDEX idx_id ON tech_book (id)",
+ },
},
{
stmt: "CREATE UNIQUE INDEX idx_id ON tech_book (id)",
@@ -301,6 +338,9 @@ func TestPGCreateIndexStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "CREATE UNIQUE INDEX idx_id ON tech_book (id)",
+ },
},
}
@@ -322,6 +362,9 @@ func TestPGDropIndexStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "DROP INDEX xschema.idx_id, idx_x",
+ },
},
}
@@ -339,6 +382,9 @@ func TestPGAlterIndexStmt(t *testing.T) {
NewName: "IDX_ID",
},
},
+ textList: []string{
+ "ALTER INDEX xschema.idx_id RENAME TO \"IDX_ID\"",
+ },
},
{
stmt: "ALTER INDEX idx_id RENAME TO \"IDX_ID\"",
@@ -348,6 +394,9 @@ func TestPGAlterIndexStmt(t *testing.T) {
NewName: "IDX_ID",
},
},
+ textList: []string{
+ "ALTER INDEX idx_id RENAME TO \"IDX_ID\"",
+ },
},
}
@@ -369,6 +418,9 @@ func TestPGDropConstraintStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "ALTER TABLE tech_book DROP CONSTRAINT uk_tech_a",
+ },
},
}
@@ -394,6 +446,9 @@ func TestPGAddConstraintStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "ALTER TABLE tech_book ADD CONSTRAINT uk_tech_book_id UNIQUE (id)",
+ },
},
{
stmt: "ALTER TABLE tech_book ADD CONSTRAINT pk_tech_book_id PRIMARY KEY (id)",
@@ -412,6 +467,9 @@ func TestPGAddConstraintStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "ALTER TABLE tech_book ADD CONSTRAINT pk_tech_book_id PRIMARY KEY (id)",
+ },
},
{
stmt: "ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_id FOREIGN KEY (id) REFERENCES people(id)",
@@ -434,6 +492,9 @@ func TestPGAddConstraintStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_id FOREIGN KEY (id) REFERENCES people(id)",
+ },
},
{
stmt: "ALTER TABLE tech_book ADD CONSTRAINT uk_tech_book_id UNIQUE USING INDEX uk_id",
@@ -452,6 +513,9 @@ func TestPGAddConstraintStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "ALTER TABLE tech_book ADD CONSTRAINT uk_tech_book_id UNIQUE USING INDEX uk_id",
+ },
},
{
stmt: "ALTER TABLE tech_book ADD CONSTRAINT pk_tech_book_id PRIMARY KEY USING INDEX pk_id",
@@ -470,6 +534,9 @@ func TestPGAddConstraintStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "ALTER TABLE tech_book ADD CONSTRAINT pk_tech_book_id PRIMARY KEY USING INDEX pk_id",
+ },
},
}
@@ -491,6 +558,9 @@ func TestPGDropColumnStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "ALTER TABLE tech_book DROP COLUMN a",
+ },
},
}
@@ -514,6 +584,9 @@ func TestPGDropTableStmt(t *testing.T) {
},
},
},
+ textList: []string{
+ "DROP TABLE tech_book, xschema.user",
+ },
},
}