Skip to content

Commit

Permalink
test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
martianzhang committed Dec 28, 2018
1 parent 425106e commit 407db8a
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 38 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmd/soar/soar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions common/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
80 changes: 51 additions & 29 deletions common/testdata/TestParseDSN.golden
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@hostname:3307/database
Expand All @@ -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
Expand All @@ -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
Expand All @@ -83,7 +83,7 @@ user:password@hostname:3307
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@hostname:/database
Expand All @@ -105,7 +105,7 @@ user:password@hostname:/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@:3307/database
Expand All @@ -127,7 +127,7 @@ user:password@:3307/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user@hostname/database
Expand All @@ -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
Expand All @@ -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@
Expand All @@ -193,7 +193,7 @@ user:password@
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
hostname:3307/database
Expand All @@ -215,7 +215,7 @@ hostname:3307/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
@hostname:3307/database
Expand All @@ -237,7 +237,7 @@ hostname:3307/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
@hostname
Expand All @@ -259,7 +259,7 @@ hostname:3307/database
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
hostname
Expand All @@ -281,7 +281,7 @@ hostname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
@/database
Expand All @@ -303,7 +303,7 @@ hostname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
@hostname:3307
Expand All @@ -325,7 +325,7 @@ hostname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
@:3307/database
Expand All @@ -347,7 +347,7 @@ hostname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
:3307/database
Expand All @@ -369,7 +369,7 @@ hostname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
/database
Expand All @@ -391,7 +391,7 @@ hostname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user@unix(/path/to/socket)/dbname
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -611,7 +611,7 @@ user:password@/dbname
WriteTimeout: 0,
AllowNativePasswords: true,
AllowOldPasswords: false,
Disable: true,
Disable: false,
Version: 99999,
}
user:password@/
Expand All @@ -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,
}
5 changes: 3 additions & 2 deletions database/testdata/TestTrace.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[]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"}
15 changes: 9 additions & 6 deletions database/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;",
Expand Down
2 changes: 2 additions & 0 deletions env/testdata/TestNewVirtualEnv.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
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
Expand Down

0 comments on commit 407db8a

Please sign in to comment.