Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: move pg test
d-bytebase6af83a7272b1
diff --git a/backend/plugin/parser/pg/query_test.go b/backend/plugin/parser/pg/query_test.gonew file mode 100644index 0000000000..22c52cdb1c--- /dev/null+++ b/backend/plugin/parser/pg/query_test.go@@ -0,0 +1,86 @@+package pg++import (+ "testing"++ "github.com/stretchr/testify/require"+)++type testData struct {+ sql string+ ans bool+}++func TestValidateSQLForEditor(t *testing.T) {+ tests := []testData{+ {+ sql: `select* from t`,+ ans: true,+ },+ {+ sql: `explain select * from t;`,+ ans: true,+ },+ {+ sql: `explain analyze select * from t`,+ ans: false,+ },+ {+ sql: `+ With t as (+ select * from t1+ ), tx as (+ delete from t2+ )+ select * from t;+ `,+ ans: false,+ },+ {+ sql: `+ With t as (+ select * from t1+ ), tx as (+ select * from t1+ )+ update t set a = 1;+ `,+ ans: false,+ },+ {+ sql: `+ With t as (+ select * from t1+ ), tx as (+ select * from t1+ )+ insert into t values (1, 2, 3);+ `,+ ans: false,+ },+ {+ sql: "select * from t where a = 'klasjdfkljsa$tag$; -- lkjdlkfajslkdfj'",+ ans: true,+ },+ {+ sql: `+ With t as (+ select * from t1 where a = 'insert'+ ), tx as (+ select * from "delete"+ ) /* UPDATE */+ select "update" from t;+ `,+ ans: true,+ },+ {+ sql: `create table t (a int);`,+ ans: false,+ },+ }++ for _, test := range tests {+ ans := ValidateSQLForEditor(test.sql)+ require.Equal(t, test.ans, ans, test.sql)+ }+}diff --git a/backend/plugin/parser/sql/validate_sql_for_editor_test.go b/backend/plugin/parser/sql/validate_sql_for_editor_test.goindex 5e8161aa86..9513da533b 100644--- a/backend/plugin/parser/sql/validate_sql_for_editor_test.go+++ b/backend/plugin/parser/sql/validate_sql_for_editor_test.go@@ -13,80 +13,6 @@ type testData struct {ans bool}-func TestValidateSQLForPG(t *testing.T) {- tests := []testData{- {- sql: `select* from t`,- ans: true,- },- {- sql: `explain select * from t;`,- ans: true,- },- {- sql: `explain analyze select * from t`,- ans: false,- },- {- sql: `- With t as (- select * from t1- ), tx as (- delete from t2- )- select * from t;- `,- ans: false,- },- {- sql: `- With t as (- select * from t1- ), tx as (- select * from t1- )- update t set a = 1;- `,- ans: false,- },- {- sql: `- With t as (- select * from t1- ), tx as (- select * from t1- )- insert into t values (1, 2, 3);- `,- ans: false,- },- {- sql: "select * from t where a = 'klasjdfkljsa$tag$; -- lkjdlkfajslkdfj'",- ans: true,- },- {- sql: `- With t as (- select * from t1 where a = 'insert'- ), tx as (- select * from "delete"- ) /* UPDATE */- select "update" from t;- `,- ans: true,- },- {- sql: `create table t (a int);`,- ans: false,- },- }-- for _, test := range tests {- ans := parser.ValidateSQLForEditor(parser.Postgres, test.sql)- require.Equal(t, test.ans, ans, test.sql)- }-}-func TestValidateSQLForMySQL(t *testing.T) {tests := []testData{{