Skip to content

Commit dbb088e

Browse files
committed
fix(test): update rule_00075 test cases for charset validation
1 parent 8210369 commit dbb088e

File tree

1 file changed

+51
-33
lines changed

1 file changed

+51
-33
lines changed

sqle/driver/mysql/rule_00075_test.go

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,76 +12,94 @@ func TestRuleSQLE00075(t *testing.T) {
1212
ruleName := ai.SQLE00075
1313
rule := rulepkg.AIRuleHandlerMap[ruleName].Rule
1414

15-
//create table, no charset, no collate
16-
runSingleRuleInspectCase(rule, t, "create table, no charset, no collate", DefaultMysqlInspect(), `
15+
//create table, no table charset, no column charset - should pass
16+
runSingleRuleInspectCase(rule, t, "create table, no table charset, no column charset", DefaultMysqlInspect(), `
1717
CREATE TABLE if not exists exist_db.not_exist_tb_1 (
1818
id bigint unsigned DEFAULT 100 AUTO_INCREMENT,
1919
a varchar(10),
2020
PRIMARY KEY (id)
2121
);
2222
`, newTestResult())
2323

24-
//create table, with charset, no collate
25-
runSingleRuleInspectCase(rule, t, "create table, with charset, no collate", DefaultMysqlInspect(), `
24+
//create table, with table charset utf8mb4, no column charset - should pass
25+
runSingleRuleInspectCase(rule, t, "create table, with table charset utf8mb4, no column charset", DefaultMysqlInspect(), `
26+
CREATE TABLE if not exists exist_db.not_exist_tb_1 (
27+
id bigint unsigned DEFAULT 100 AUTO_INCREMENT,
28+
a varchar(10),
29+
PRIMARY KEY (id)
30+
) CHARSET utf8mb4;
31+
`, newTestResult())
32+
33+
//create table, with table charset utf8mb4, column charset utf8mb4 - should pass
34+
runSingleRuleInspectCase(rule, t, "create table, with table charset utf8mb4, column charset utf8mb4", DefaultMysqlInspect(), `
2635
CREATE TABLE if not exists exist_db.not_exist_tb_1 (
2736
id bigint unsigned DEFAULT 100 AUTO_INCREMENT,
2837
a varchar(10) CHARSET utf8mb4,
2938
PRIMARY KEY (id)
30-
);
39+
) CHARSET utf8mb4;
40+
`, newTestResult())
41+
42+
//create table, with table charset utf8mb4, column charset utf8 - should fail
43+
runSingleRuleInspectCase(rule, t, "create table, with table charset utf8mb4, column charset utf8", DefaultMysqlInspect(), `
44+
CREATE TABLE if not exists exist_db.not_exist_tb_1 (
45+
id bigint unsigned DEFAULT 100 AUTO_INCREMENT,
46+
a varchar(10) CHARSET utf8,
47+
PRIMARY KEY (id)
48+
) CHARSET utf8mb4;
3149
`, newTestResult().addResult(ruleName, "a"))
3250

33-
//create table, with charset, with collate
34-
runSingleRuleInspectCase(rule, t, "create table, with charset, with collate", DefaultMysqlInspect(), `
51+
//create table, with table charset utf8, column charset utf8mb4 - should fail
52+
runSingleRuleInspectCase(rule, t, "create table, with table charset utf8, column charset utf8mb4", DefaultMysqlInspect(), `
3553
CREATE TABLE if not exists exist_db.not_exist_tb_1 (
3654
id bigint unsigned DEFAULT 100 AUTO_INCREMENT,
37-
a varchar(10) CHARSET utf8mb4 COLLATE utf8_general_ci,
55+
a varchar(10) CHARSET utf8mb4,
3856
PRIMARY KEY (id)
39-
);
57+
) CHARSET utf8;
4058
`, newTestResult().addResult(ruleName, "a"))
4159

42-
//alter table add column, no charset, no collate
43-
runSingleRuleInspectCase(rule, t, "alter table add column, no charset, no collate", DefaultMysqlInspect(), `
60+
//alter table add column, no table charset change, no column charset - should pass
61+
runSingleRuleInspectCase(rule, t, "alter table add column, no table charset change, no column charset", DefaultMysqlInspect(), `
4462
ALTER TABLE exist_db.exist_tb_1 ADD COLUMN a varchar(10) COMMENT "unit test";
4563
`, newTestResult())
4664

47-
//alter table add column, with charset, no collate
48-
runSingleRuleInspectCase(rule, t, "alter table add column, with charset, no collate", DefaultMysqlInspect(), `
65+
//alter table add column, no table charset change, column charset utf8mb4 - should pass (assuming table charset is utf8mb4)
66+
runSingleRuleInspectCase(rule, t, "alter table add column, no table charset change, column charset utf8mb4", DefaultMysqlInspect(), `
4967
ALTER TABLE exist_db.exist_tb_1 ADD COLUMN a varchar(10) CHARSET utf8mb4 COMMENT "unit test";
50-
`, newTestResult().addResult(ruleName, "a"))
68+
`, newTestResult())
5169

52-
//alter table add column, with charset, with collate
53-
runSingleRuleInspectCase(rule, t, "alter table add column, with charset, with collate", DefaultMysqlInspect(), `
54-
ALTER TABLE exist_db.exist_tb_1 ADD COLUMN a varchar(10) CHARSET utf8mb4 COLLATE utf8_general_ci COMMENT "unit test";
70+
//alter table add column, change table charset to utf8, column charset utf8mb4 - should fail
71+
runSingleRuleInspectCase(rule, t, "alter table add column, change table charset to utf8, column charset utf8mb4", DefaultMysqlInspect(), `
72+
ALTER TABLE exist_db.exist_tb_1 ADD COLUMN a varchar(10) CHARSET utf8mb4 COMMENT "unit test", CONVERT TO CHARACTER SET utf8;
5573
`, newTestResult().addResult(ruleName, "a"))
5674

57-
//alter table modify column, no charset, no collate
58-
runSingleRuleInspectCase(rule, t, "alter table modify column, no charset, no collate", DefaultMysqlInspect(), `
75+
//alter table modify column, no table charset change, no column charset - should pass
76+
runSingleRuleInspectCase(rule, t, "alter table modify column, no table charset change, no column charset", DefaultMysqlInspect(), `
5977
ALTER TABLE exist_db.exist_tb_1 MODIFY v1 varchar(10) COMMENT "unit test";
6078
`, newTestResult())
6179

62-
//alter table modify column, with charset, no collate
63-
runSingleRuleInspectCase(rule, t, "alter table modify column, with charset, no collate", DefaultMysqlInspect(), `
80+
//alter table modify column, no table charset change, column charset utf8mb4 - should pass (assuming table charset is utf8mb4)
81+
runSingleRuleInspectCase(rule, t, "alter table modify column, no table charset change, column charset utf8mb4", DefaultMysqlInspect(), `
6482
ALTER TABLE exist_db.exist_tb_1 MODIFY v1 varchar(10) CHARSET utf8mb4 COMMENT "unit test";
65-
`, newTestResult().addResult(ruleName, "v1"))
83+
`, newTestResult())
6684

67-
//alter table modify column, with charset, with collate
68-
runSingleRuleInspectCase(rule, t, "alter table modify column, with charset, with collate", DefaultMysqlInspect(), `
69-
ALTER TABLE exist_db.exist_tb_1 MODIFY v1 varchar(10) CHARSET utf8mb4 COLLATE utf8_general_ci COMMENT "unit test";
85+
//alter table modify column, change table charset to utf8, column charset utf8mb4 - should fail
86+
runSingleRuleInspectCase(rule, t, "alter table modify column, change table charset to utf8, column charset utf8mb4", DefaultMysqlInspect(), `
87+
ALTER TABLE exist_db.exist_tb_1 MODIFY v1 varchar(10) CHARSET utf8mb4 COMMENT "unit test", CONVERT TO CHARACTER SET utf8;
7088
`, newTestResult().addResult(ruleName, "v1"))
7189

72-
//alter table change column, no charset, no collate
73-
runSingleRuleInspectCase(rule, t, "alter table change column, no charset, no collate", DefaultMysqlInspect(), `
90+
//alter table change column, no table charset change, no column charset - should pass
91+
runSingleRuleInspectCase(rule, t, "alter table change column, no table charset change, no column charset", DefaultMysqlInspect(), `
7492
ALTER TABLE exist_db.exist_tb_1 CHANGE COLUMN v1 a varchar(10) COMMENT "unit test";
7593
`, newTestResult())
7694

77-
//alter table change column, with charset, no collate
78-
runSingleRuleInspectCase(rule, t, "alter table change column, with charset, no collate", DefaultMysqlInspect(), `
95+
//alter table change column, no table charset change, column charset utf8mb4 - should pass (assuming table charset is utf8mb4)
96+
runSingleRuleInspectCase(rule, t, "alter table change column, no table charset change, column charset utf8mb4", DefaultMysqlInspect(), `
7997
ALTER TABLE exist_db.exist_tb_1 CHANGE COLUMN v1 a varchar(10) CHARSET utf8mb4 COMMENT "unit test";
80-
`, newTestResult().addResult(ruleName, "a"))
98+
`, newTestResult())
8199

82-
//alter table change column, with charset, with collate
83-
runSingleRuleInspectCase(rule, t, "alter table change column, with charset, with collate", DefaultMysqlInspect(), `
84-
ALTER TABLE exist_db.exist_tb_1 CHANGE COLUMN v1 a varchar(10) CHARSET utf8mb4 COLLATE utf8_general_ci COMMENT "unit test";
100+
//alter table change column, change table charset to utf8, column charset utf8mb4 - should fail
101+
runSingleRuleInspectCase(rule, t, "alter table change column, change table charset to utf8, column charset utf8mb4", DefaultMysqlInspect(), `
102+
ALTER TABLE exist_db.exist_tb_1 CHANGE COLUMN v1 a varchar(10) CHARSET utf8mb4 COMMENT "unit test", CONVERT TO CHARACTER SET utf8;
85103
`, newTestResult().addResult(ruleName, "a"))
86104
}
87105

0 commit comments

Comments
 (0)