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: delete unused test
d-bytebased26ab43facba
diff --git a/backend/plugin/parser/sql/split_multi_sql_test.go b/backend/plugin/parser/sql/split_multi_sql_test.godeleted file mode 100644index 6bf0e1d0c3..0000000000--- a/backend/plugin/parser/sql/split_multi_sql_test.go+++ /dev/null@@ -1,303 +0,0 @@-package parser--import (- "fmt"- "math/rand"- "strings"- "testing"- "time"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/backend/plugin/parser/base"-)--type testData struct {- statement string- want resData-}--type resData struct {- res []base.SingleSQL- err string-}--func generateOneMBInsert() string {- var rand = rand.New(rand.NewSource(time.Now().UnixNano()))- letterList := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")- b := make([]byte, 1024*1024)- for i := range b {- b[i] = letterList[rand.Intn(len(letterList))]- }- return fmt.Sprintf("INSERT INTO t values('%s')", string(b))-}--func TestMySQLSplitMultiSQL(t *testing.T) {- bigSQL := generateOneMBInsert()- tests := []testData{- {- statement: `-- klsjdfjasldf- -- klsjdflkjaskldfj- `,- want: resData{- res: []base.SingleSQL{- {- Text: "-- klsjdfjasldf\n\t\t\t-- klsjdflkjaskldfj\n;",- LastLine: 3,- },- },- },- },- {- statement: `select * from t;- /* sdfasdf */`,- want: resData{- res: []base.SingleSQL{- {- Text: `select * from t;`,- LastLine: 1,- },- {- Text: "\n\t\t\t/* sdfasdf */\n;",- LastLine: 3,- },- },- },- },- {- statement: `select * from t;- /* sdfasdf */;- select * from t;`,- want: resData{- res: []base.SingleSQL{- {- Text: `select * from t;`,- LastLine: 1,- },- {- Text: "\n\t\t\t/* sdfasdf */;",- LastLine: 2,- },- {- Text: "\n\t\t\tselect * from t\n;",- BaseLine: 1,- LastLine: 4,- },- },- },- },- {- statement: "CREATE DEFINER=`root`@`%` FUNCTION `CalcIncome`( starting_value INT ) RETURNS int\n" +- `BEGIN-- DECLARE income INT;-- SET income = 0;-- label1: WHILE income <= 3000 DO- SET income = income + starting_value;- END WHILE label1;-- RETURN income;-- END ;`,- want: resData{- res: []base.SingleSQL{- {- Text: "CREATE DEFINER=`root`@`%` FUNCTION `CalcIncome`( starting_value INT ) RETURNS int\n" +- `BEGIN-- DECLARE income INT;-- SET income = 0;-- label1: WHILE income <= 3000 DO- SET income = income + starting_value;- END WHILE label1;-- RETURN income;-- END-;`,- LastLine: 15,- },- },- },- },- {- statement: bigSQL,- want: resData{- res: []base.SingleSQL{- {- Text: bigSQL + "\n;",- LastLine: 2,- },- },- },- },- {- statement: " CREATE TABLE t(a int); CREATE TABLE t1(a int)",- want: resData{- res: []base.SingleSQL{- {- Text: " CREATE TABLE t(a int);",- LastLine: 1,- },- {- Text: " CREATE TABLE t1(a int)\n;",- LastLine: 2,- },- },- },- },- {- statement: "CREATE TABLE `tech_Book`(id int, name varchar(255));\n" +- "INSERT INTO `tech_Book` VALUES (0, 'abce_ksdf'), (1, 'lks''kjsafa\\'jdfl;\"ka');",- want: resData{- res: []base.SingleSQL{- {- Text: "CREATE TABLE `tech_Book`(id int, name varchar(255));",- LastLine: 1,- },- {- Text: "\nINSERT INTO `tech_Book` VALUES (0, 'abce_ksdf'), (1, 'lks''kjsafa\\'jdfl;\"ka')\n;",- LastLine: 3,- },- },- },- },- {- statement: `- /* this is the comment. */- CREATE /* inline comment */TABLE tech_Book(id int, name varchar(255));- -- this is the comment.- INSERT INTO tech_Book VALUES (0, 'abce_ksdf'), (1, 'lks''kjsafa\'jdfl;"ka');- # this is the comment.- INSERT INTO tech_Book VALUES (0, 'abce_ksdf'), (1, 'lks''kjsafa\'jdfl;"ka');`,- want: resData{- res: []base.SingleSQL{- {- Text: "\n\t\t\t\t\t\t/* this is the comment. */\n\t\t\t\t\t\tCREATE /* inline comment */TABLE tech_Book(id int, name varchar(255));",- LastLine: 3,- },- {- Text: "\n\t\t\t\t\t\t-- this is the comment.\n\t\t\t\t\t\tINSERT INTO tech_Book VALUES (0, 'abce_ksdf'), (1, 'lks''kjsafa\\'jdfl;\"ka');",- BaseLine: 2,- LastLine: 5,- },- {- Text: "\n\t\t\t\t\t\t# this is the comment.\n\t\t\t\t\t\tINSERT INTO tech_Book VALUES (0, 'abce_ksdf'), (1, 'lks''kjsafa\\'jdfl;\"ka')\n;",- BaseLine: 4,- LastLine: 8,- },- },- },- },- {- statement: `# test for defining stored programs- CREATE PROCEDURE dorepeat(p1 INT)- BEGIN- SET @x = 0;- REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;- END- ;- CALL dorepeat(1000);- SELECT @x;- `,- want: resData{- res: []base.SingleSQL{- {- Text: "# test for defining stored programs\n\t\t\t\t\t\tCREATE PROCEDURE dorepeat(p1 INT)\n\t\t\t\t\t\tBEGIN\n\t\t\t\t\t\t\tSET @x = 0;\n\t\t\t\t\t\t\tREPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;\n\t\t\t\t\t\tEND\n\t\t\t\t\t\t;",- LastLine: 7,- },- {- Text: "\n\t\t\t\t\t\tCALL dorepeat(1000);",- BaseLine: 6,- LastLine: 8,- },- {- Text: "\n\t\t\t\t\t\tSELECT @x\n;",- BaseLine: 7,- LastLine: 10,- },- },- },- },- {- statement: `# test for defining stored programs- CREATE PROCEDURE dorepeat(p1 INT)- /* This is a comment */- BEGIN- SET @x = 0;- REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;- END- ;- CALL dorepeat(1000);- SELECT @x;- `,- want: resData{- res: []base.SingleSQL{- {- Text: "# test for defining stored programs\n\t\t\t\t\t\tCREATE PROCEDURE dorepeat(p1 INT)\n\t\t\t\t\t\t/* This is a comment */\n\t\t\t\t\t\tBEGIN\n\t\t\t\t\t\t\tSET @x = 0;\n\t\t\t\t\t\t\tREPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;\n\t\t\t\t\t\tEND\n\t\t\t\t\t\t;",- LastLine: 8,- },- {- Text: "\n\t\t\t\t\t\tCALL dorepeat(1000);",- BaseLine: 7,- LastLine: 9,- },- {- Text: "\n\t\t\t\t\t\tSELECT @x\n;",- BaseLine: 8,- LastLine: 11,- },- },- },- },- {- // test for Windows- statement: `CREATE TABLE t` + "\r\n" + `(a int);` + "\r\n" + `CREATE TABLE t1(b int);`,- want: resData{- res: []base.SingleSQL{- {- Text: "CREATE TABLE t\r\n(a int);",- LastLine: 2,- },- {- Text: "\r\nCREATE TABLE t1(b int)\n;",- BaseLine: 1,- LastLine: 4,- },- },- },- },- {- statement: `INSERT INTO t VALUES ('klajfas)`,- want: resData{- err: "failed to split multi sql: invalid string: not found delimiter: ', but found EOF",- },- },- {- statement: "INSERT INTO `t VALUES ('klajfas)",- want: resData{- err: "failed to split multi sql: invalid indentifier: not found delimiter: `, but found EOF",- },- },- }-- for _, test := range tests {- res, err := SplitMultiSQL(MySQL, test.statement)- errStr := ""- if err != nil {- errStr = err.Error()- }- require.Equal(t, test.want, resData{res, errStr}, test.statement)-- res, err = SplitMultiSQLStream(MySQL, strings.NewReader(test.statement), nil)- errStr = ""- if err != nil {- errStr = err.Error()- }- require.Equal(t, test.want, resData{res, errStr}, test.statement)- }-}