-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
97 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
package mysql | ||
|
||
import ( | ||
"testing" | ||
|
||
rulepkg "github.com/actiontech/sqle/sqle/driver/mysql/rule" | ||
"github.com/actiontech/sqle/sqle/driver/mysql/rule/ai" | ||
) | ||
|
||
// ==== Rule test code start ==== | ||
func TestRuleSQLE00023(t *testing.T) { | ||
ruleName := ai.SQLE00023 | ||
rule := rulepkg.AIRuleHandlerMap[ruleName].Rule | ||
ruleParams := []interface{}{2} | ||
//create table, no primary key | ||
runSingleRuleInspectCase(rule, t, "create table, no primary key", DefaultMysqlInspect(), ` | ||
CREATE TABLE if not exists exist_db.not_exist_tb_1 ( | ||
id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "unit test" | ||
); | ||
`, newTestResult()) | ||
|
||
//create table, with primary key, fewer than expected number of columns | ||
runSingleRuleInspectCase(rule, t, "create table, with primary key, fewer than expected number of columns", DefaultMysqlInspect(), ` | ||
CREATE TABLE if not exists exist_db.not_exist_tb_1 ( | ||
id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "unit test", | ||
id2 bigint, | ||
PRIMARY KEY (id, id2) | ||
); | ||
`, newTestResult()) | ||
|
||
//create table, with primary key, more than expected number of columns | ||
runSingleRuleInspectCase(rule, t, "create table, with primary key, fewer than expected number of columns", DefaultMysqlInspect(), ` | ||
CREATE TABLE if not exists exist_db.not_exist_tb_1 ( | ||
id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "unit test", | ||
a int, | ||
b int, | ||
PRIMARY KEY (id, a, b) | ||
); | ||
`, newTestResult().addResult(ruleName, ruleParams...)) | ||
|
||
//alter table, no primary key | ||
runSingleRuleInspectCase(rule, t, "alter table, no primary key", DefaultMysqlInspect(), ` | ||
ALTER TABLE exist_db.exist_tb_3 ADD COLUMN a int NOT NULL COMMENT "unit test"; | ||
`, newTestResult()) | ||
|
||
//alter table, with primary key, fewer than expected number of columns | ||
runSingleRuleInspectCase(rule, t, "alter table, with primary key, fewer than expected number of columns", DefaultMysqlInspect(), ` | ||
ALTER TABLE exist_db.exist_tb_3 ADD CONSTRAINT PK_c PRIMARY KEY (id, v1); | ||
`, newTestResult()) | ||
|
||
//alter table, with primary key, more than expected number of columns | ||
runSingleRuleInspectCase(rule, t, "alter table, with primary key, more than expected number of columns", DefaultMysqlInspect(), ` | ||
ALTER TABLE exist_db.exist_tb_3 ADD CONSTRAINT PK_c PRIMARY KEY (id, v1, v2); | ||
`, newTestResult().addResult(ruleName, ruleParams...)) | ||
} | ||
|
||
// ==== Rule test code end ==== | ||
//import ( | ||
// "testing" | ||
// | ||
// rulepkg "github.com/actiontech/sqle/sqle/driver/mysql/rule" | ||
// "github.com/actiontech/sqle/sqle/driver/mysql/rule/ai" | ||
//) | ||
// | ||
//// ==== Rule test code start ==== | ||
//func TestRuleSQLE00023(t *testing.T) { | ||
// ruleName := ai.SQLE00023 | ||
// rule := rulepkg.AIRuleHandlerMap[ruleName].Rule | ||
// ruleParams := []interface{}{2} | ||
// //create table, no primary key | ||
// runSingleRuleInspectCase(rule, t, "create table, no primary key", DefaultMysqlInspect(), ` | ||
// CREATE TABLE if not exists exist_db.not_exist_tb_1 ( | ||
// id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "unit test" | ||
// ); | ||
// `, newTestResult()) | ||
// | ||
// //create table, with primary key, fewer than expected number of columns | ||
// runSingleRuleInspectCase(rule, t, "create table, with primary key, fewer than expected number of columns", DefaultMysqlInspect(), ` | ||
// CREATE TABLE if not exists exist_db.not_exist_tb_1 ( | ||
// id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "unit test", | ||
// id2 bigint, | ||
// PRIMARY KEY (id, id2) | ||
// ); | ||
// `, newTestResult()) | ||
// | ||
// //create table, with primary key, more than expected number of columns | ||
// runSingleRuleInspectCase(rule, t, "create table, with primary key, fewer than expected number of columns", DefaultMysqlInspect(), ` | ||
// CREATE TABLE if not exists exist_db.not_exist_tb_1 ( | ||
// id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "unit test", | ||
// a int, | ||
// b int, | ||
// PRIMARY KEY (id, a, b) | ||
// ); | ||
// `, newTestResult().addResult(ruleName, ruleParams...)) | ||
// | ||
// //alter table, no primary key | ||
// runSingleRuleInspectCase(rule, t, "alter table, no primary key", DefaultMysqlInspect(), ` | ||
// ALTER TABLE exist_db.exist_tb_3 ADD COLUMN a int NOT NULL COMMENT "unit test"; | ||
// `, newTestResult()) | ||
// | ||
// //alter table, with primary key, fewer than expected number of columns | ||
// runSingleRuleInspectCase(rule, t, "alter table, with primary key, fewer than expected number of columns", DefaultMysqlInspect(), ` | ||
// ALTER TABLE exist_db.exist_tb_3 ADD CONSTRAINT PK_c PRIMARY KEY (id, v1); | ||
// `, newTestResult()) | ||
// | ||
// //alter table, with primary key, more than expected number of columns | ||
// runSingleRuleInspectCase(rule, t, "alter table, with primary key, more than expected number of columns", DefaultMysqlInspect(), ` | ||
// ALTER TABLE exist_db.exist_tb_3 ADD CONSTRAINT PK_c PRIMARY KEY (id, v1, v2); | ||
// `, newTestResult().addResult(ruleName, ruleParams...)) | ||
//} | ||
// | ||
//// ==== Rule test code end ==== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
package mysql | ||
|
||
import ( | ||
"testing" | ||
|
||
rulepkg "github.com/actiontech/sqle/sqle/driver/mysql/rule" | ||
"github.com/actiontech/sqle/sqle/driver/mysql/rule/ai" | ||
) | ||
|
||
// ==== Rule test code start ==== | ||
func TestRuleSQLE00171(t *testing.T) { | ||
ruleName := ai.SQLE00171 | ||
rule := rulepkg.AIRuleHandlerMap[ruleName].Rule | ||
|
||
ruleParams := []interface{}{"CREATE_TIME"} | ||
|
||
//create table, has create_time column | ||
runSingleRuleInspectCase(rule, t, "create table, has create_time column", DefaultMysqlInspect(), ` | ||
CREATE TABLE if not exists exist_db.not_exist_tb_1 ( | ||
id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "unit test", | ||
CREATE_TIME datetime DEFAULT CURRENT_TIMESTAMP COMMENT "unit test", | ||
PRIMARY KEY (id) | ||
); | ||
`, newTestResult()) | ||
|
||
//create table, has create_time column, with wrong DEFAULT value | ||
runSingleRuleInspectCase(rule, t, "create table, has create_time column", DefaultMysqlInspect(), ` | ||
CREATE TABLE if not exists exist_db.not_exist_tb_1 ( | ||
id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "unit test", | ||
CREATE_TIME datetime DEFAULT NULL COMMENT "unit test", | ||
PRIMARY KEY (id) | ||
); | ||
`, newTestResult().addResult(ruleName, ruleParams...)) | ||
|
||
//create table, has no create_time column | ||
runSingleRuleInspectCase(rule, t, "create table, has no create_time column", DefaultMysqlInspect(), ` | ||
CREATE TABLE if not exists exist_db.not_exist_tb_1 ( | ||
id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "unit test", | ||
PRIMARY KEY (id) | ||
); | ||
`, newTestResult().addResult(ruleName, ruleParams...)) | ||
} | ||
|
||
// ==== Rule test code end ==== | ||
//import ( | ||
// "testing" | ||
// | ||
// rulepkg "github.com/actiontech/sqle/sqle/driver/mysql/rule" | ||
// "github.com/actiontech/sqle/sqle/driver/mysql/rule/ai" | ||
//) | ||
// | ||
//// ==== Rule test code start ==== | ||
//func TestRuleSQLE00171(t *testing.T) { | ||
// ruleName := ai.SQLE00171 | ||
// rule := rulepkg.AIRuleHandlerMap[ruleName].Rule | ||
// | ||
// ruleParams := []interface{}{"CREATE_TIME"} | ||
// | ||
// //create table, has create_time column | ||
// runSingleRuleInspectCase(rule, t, "create table, has create_time column", DefaultMysqlInspect(), ` | ||
// CREATE TABLE if not exists exist_db.not_exist_tb_1 ( | ||
// id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "unit test", | ||
// CREATE_TIME datetime DEFAULT CURRENT_TIMESTAMP COMMENT "unit test", | ||
// PRIMARY KEY (id) | ||
// ); | ||
// `, newTestResult()) | ||
// | ||
// //create table, has create_time column, with wrong DEFAULT value | ||
// runSingleRuleInspectCase(rule, t, "create table, has create_time column", DefaultMysqlInspect(), ` | ||
// CREATE TABLE if not exists exist_db.not_exist_tb_1 ( | ||
// id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "unit test", | ||
// CREATE_TIME datetime DEFAULT NULL COMMENT "unit test", | ||
// PRIMARY KEY (id) | ||
// ); | ||
// `, newTestResult().addResult(ruleName, ruleParams...)) | ||
// | ||
// //create table, has no create_time column | ||
// runSingleRuleInspectCase(rule, t, "create table, has no create_time column", DefaultMysqlInspect(), ` | ||
// CREATE TABLE if not exists exist_db.not_exist_tb_1 ( | ||
// id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "unit test", | ||
// PRIMARY KEY (id) | ||
// ); | ||
// `, newTestResult().addResult(ruleName, ruleParams...)) | ||
//} | ||
// | ||
//// ==== Rule test code end ==== |