提交 407db8a0 编写于 作者: martianzhang's avatar martianzhang

test cases

上级 425106ed
......@@ -8,12 +8,14 @@
- command line dsn args support '@', '/', ':' in password
- add new heuristic rule RES.009, "SELECT * FROM tbl WHERE col = col = 'abc'"
- add new heuristic rule RuleColumnNotAllowType COL.018
- add string escape function for security
- fix #122 single table select * don't auto-complete table name
- fix #171 support socket access type
- fix #58 sampling not deal with NULL able string
- fix #172 compatible with mysql 5.1, which explain has no Index_Comment column
- fix #163 column.Tp may be nil, which may raise panic
- fix #151 bit type not config as int, when two columns compare will give ARG.003 suggestion.
-
## 2018-11
- add all third-party lib into vendor
......
......@@ -47,6 +47,8 @@ func Test_Main(_ *testing.T) {
common.Log.Debug("Entering function: %s", common.GetFunctionName())
common.Config.OnlineDSN.Disable = true
common.Config.LogLevel = 0
common.Config.Query = "select * syntaxError"
main()
common.Config.Query = "select * from film;alter table city add index idx_country_id(country_id);"
main()
common.Log.Debug("Exiting function: %s", common.GetFunctionName())
......
......@@ -426,6 +426,7 @@ func parseDSN(odbc string, d *Dsn) *Dsn {
func ParseDSN(odbc string, d *Dsn) *Dsn {
cfg, err := mysql.ParseDSN(odbc)
if err != nil {
Log.Warn("go-sql-driver/mysql.ParseDSN Error: %s, DSN: %s, try to use old version parseDSN", err.Error(), odbc)
return parseDSN(odbc, d)
}
return newDSN(cfg)
......
......@@ -94,6 +94,7 @@ func TestParseDSN(t *testing.T) {
"user:password@tcp/dbname?charset=utf8mb4,utf8&sys_var=esc%40ped",
"user:password@/dbname",
"user:password@/",
"user:password@tcp(localhost:3307)/database?charset=utf8&timeout=5s",
}
err := GoldenDiff(func() {
......
......@@ -17,7 +17,7 @@
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@hostname:3307/database
......@@ -39,7 +39,7 @@ user:password@hostname:3307/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@hostname:3307/database?charset=utf8
......@@ -61,7 +61,7 @@ user:password@hostname:3307/database?charset=utf8
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@hostname:3307
......@@ -83,7 +83,7 @@ user:password@hostname:3307
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@hostname:/database
......@@ -105,7 +105,7 @@ user:password@hostname:/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@:3307/database
......@@ -127,7 +127,7 @@ user:password@:3307/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user@hostname/database
......@@ -149,7 +149,7 @@ user@hostname/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:pwd:pwd@pwd/pwd@hostname/database
......@@ -171,7 +171,7 @@ user:pwd:pwd@pwd/pwd@hostname/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@
......@@ -193,7 +193,7 @@ user:password@
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
hostname:3307/database
......@@ -215,7 +215,7 @@ hostname:3307/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
@hostname:3307/database
......@@ -237,7 +237,7 @@ hostname:3307/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
@hostname
......@@ -259,7 +259,7 @@ hostname:3307/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
hostname
......@@ -281,7 +281,7 @@ hostname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
@/database
......@@ -303,7 +303,7 @@ hostname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
@hostname:3307
......@@ -325,7 +325,7 @@ hostname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
@:3307/database
......@@ -347,7 +347,7 @@ hostname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
:3307/database
......@@ -369,7 +369,7 @@ hostname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
/database
......@@ -391,7 +391,7 @@ hostname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user@unix(/path/to/socket)/dbname
......@@ -413,7 +413,7 @@ user@unix(/path/to/socket)/dbname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
root:pw@unix(/tmp/mysql.sock)/myDatabase?loc=Local
......@@ -435,7 +435,7 @@ root:pw@unix(/tmp/mysql.sock)/myDatabase?loc=Local
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@tcp(localhost:5555)/dbname?tls=skip-verify&autocommit=true
......@@ -457,7 +457,7 @@ user:password@tcp(localhost:5555)/dbname?tls=skip-verify&autocommit=true
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@/dbname?sql_mode=TRADITIONAL
......@@ -479,7 +479,7 @@ user:password@/dbname?sql_mode=TRADITIONAL
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@tcp([de:ad:be:ef::ca:fe]:80)/dbname?timeout=90s&collation=utf8mb4_unicode_ci
......@@ -501,7 +501,7 @@ user:password@tcp([de:ad:be:ef::ca:fe]:80)/dbname?timeout=90s&collation=utf8mb4_
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
id:password@tcp(your-amazonaws-uri.com:3306)/dbname
......@@ -523,7 +523,7 @@ id:password@tcp(your-amazonaws-uri.com:3306)/dbname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user@cloudsql(project-id:instance-name)/dbname
......@@ -545,7 +545,7 @@ user@cloudsql(project-id:instance-name)/dbname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user@cloudsql(project-id:regionname:instance-name)/dbname
......@@ -567,7 +567,7 @@ user@cloudsql(project-id:regionname:instance-name)/dbname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@tcp/dbname?charset=utf8mb4,utf8&sys_var=esc%40ped
......@@ -589,7 +589,7 @@ user:password@tcp/dbname?charset=utf8mb4,utf8&sys_var=esc%40ped
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@/dbname
......@@ -611,7 +611,7 @@ user:password@/dbname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@/
......@@ -633,6 +633,28 @@ user:password@/
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@tcp(localhost:3307)/database?charset=utf8&timeout=5s
&common.Dsn{
User: "user",
Password: "password",
Net: "tcp",
Addr: "localhost:3307",
Schema: "database",
Charset: "utf8",
Collation: "utf8_general_ci",
Loc: "UTC",
TLS: "",
ServerPubKey: "",
MaxAllowedPacket: 4194304,
Params: {"charset":"utf8"},
Timeout: 5,
ReadTimeout: 0,
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: false,
Version: 99999,
}
[]database.TraceRow{
select 1 []database.TraceRow{
{Query:"explain select 1", Trace:"{\n \"steps\": [\n {\n \"join_preparation\": {\n \"select#\": 1,\n \"steps\": [\n {\n \"expanded_query\": \"/* select#1 */ select 1 AS `1`\"\n }\n ]\n }\n },\n {\n \"join_optimization\": {\n \"select#\": 1,\n \"steps\": [\n ]\n }\n },\n {\n \"join_explain\": {\n \"select#\": 1,\n \"steps\": [\n ]\n }\n }\n ]\n}", MissingBytesBeyondMaxMemSize:0, InsufficientPrivileges:0},
}
} nil
explain select 1 []database.TraceRow(nil) &errors.errorString{s:"no need trace"}
......@@ -26,13 +26,16 @@ import (
func TestTrace(t *testing.T) {
common.Log.Debug("Entering function: %s", common.GetFunctionName())
res, err := connTest.Trace("select 1")
if err != nil {
t.Error(err)
sqls := []string{
"select 1",
"explain select 1",
"show create table film",
}
err = common.GoldenDiff(func() {
pretty.Println(res)
err := common.GoldenDiff(func() {
for _, sql := range sqls {
res, err := connTest.Trace(sql)
pretty.Println(sql, res, err)
}
}, t.Name(), update)
if err != nil {
t.Error(err)
......
......@@ -61,6 +61,8 @@ func TestMain(m *testing.M) {
func TestNewVirtualEnv(t *testing.T) {
common.Log.Debug("Entering function: %s", common.GetFunctionName())
testSQL := []string{
"use sakila",
"select frm syntaxError",
"create table t(id int,c1 varchar(20),PRIMARY KEY (id));",
"alter table t add index `idx_c1`(c1);",
"select * from city where country_id = 44;",
......
use sakila OK
select frm syntaxError OK
create table t(id int,c1 varchar(20),PRIMARY KEY (id)); OK
alter table t add index `idx_c1`(c1); OK
select * from city where country_id = 44; OK
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册