Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
soar
提交
1fa1dab4
S
soar
项目概览
Xiaomi
/
soar
大约 1 年 前同步成功
通知
384
Star
8512
Fork
1328
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
soar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1fa1dab4
编写于
12月 04, 2018
作者:
martianzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update test case golden file
go test ./... -update
上级
dda41ec5
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
53 addition
and
36 deletion
+53
-36
Makefile
Makefile
+6
-0
ast/pretty.go
ast/pretty.go
+1
-1
cmd/soar/soar_test.go
cmd/soar/soar_test.go
+4
-0
common/config.go
common/config.go
+3
-6
common/config_test.go
common/config_test.go
+16
-5
common/testdata/TestParseDSN.golden
common/testdata/TestParseDSN.golden
+1
-1
common/testdata/TestPrintConfiguration.golden
common/testdata/TestPrintConfiguration.golden
+16
-15
database/trace_test.go
database/trace_test.go
+2
-5
env/env_test.go
env/env_test.go
+4
-2
env/testdata/TestNewVirtualEnv.golden
env/testdata/TestNewVirtualEnv.golden
+0
-1
未找到文件。
Makefile
浏览文件 @
1fa1dab4
...
...
@@ -64,6 +64,12 @@ test:
go
test
./...
@
echo
"test Success!"
# Rule golang test cases with `-update` flag
test-update
:
@
echo
"
\0
33[92mRun all test cases with -update flag ...
\0
33[0m"
go
test
./...
-update
@
echo
"test-update Success!"
# Code Coverage
# colorful coverage numerical >=90% GREEN, <80% RED, Other YELLOW
.PHONY
:
cover
...
...
ast/pretty.go
浏览文件 @
1fa1dab4
...
...
@@ -32,7 +32,7 @@ func Pretty(sql string, method string) (output string) {
// 超出 Config.MaxPrettySQLLength 长度的 SQL 会对其指纹进行 pretty
if
len
(
sql
)
>
common
.
Config
.
MaxPrettySQLLength
{
fingerprint
:=
query
.
Fingerprint
(
sql
)
// 超出 Config.Max
FpPrettySql
Length 长度的指纹不会进行pretty
// 超出 Config.Max
PrettySQL
Length 长度的指纹不会进行pretty
if
len
(
fingerprint
)
>
common
.
Config
.
MaxPrettySQLLength
{
return
sql
}
...
...
cmd/soar/soar_test.go
浏览文件 @
1fa1dab4
...
...
@@ -17,13 +17,17 @@
package
main
import
(
"flag"
"testing"
"github.com/XiaoMi/soar/common"
)
var
update
=
flag
.
Bool
(
"update"
,
false
,
"update .golden files"
)
func
init
()
{
common
.
Config
.
OnlineDSN
.
Schema
=
"sakila"
_
=
update
}
func
Test_Main
(
_
*
testing
.
T
)
{
...
...
common/config.go
浏览文件 @
1fa1dab4
...
...
@@ -25,6 +25,7 @@ import (
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
...
...
@@ -587,17 +588,13 @@ func readCmdFlags() error {
Config
.
QueryTimeOut
=
*
queryTimeOut
Config
.
LogLevel
=
*
logLevel
if
strings
.
HasPrefix
(
*
logOutput
,
"/"
)
{
if
filepath
.
IsAbs
(
*
logOutput
)
{
Config
.
LogOutput
=
*
logOutput
}
else
{
if
BaseDir
==
""
{
Config
.
LogOutput
=
*
logOutput
}
else
{
if
runtime
.
GOOS
==
"windows"
{
Config
.
LogOutput
=
*
logOutput
}
else
{
Config
.
LogOutput
=
BaseDir
+
"/"
+
*
logOutput
}
Config
.
LogOutput
=
filepath
.
Join
(
BaseDir
,
*
logOutput
)
}
}
Config
.
ReportType
=
strings
.
ToLower
(
*
reportType
)
...
...
common/config_test.go
浏览文件 @
1fa1dab4
...
...
@@ -19,6 +19,7 @@ package common
import
(
"flag"
"os"
"path/filepath"
"testing"
"github.com/kr/pretty"
...
...
@@ -37,7 +38,7 @@ func TestReadConfigFile(t *testing.T) {
if
Config
==
nil
{
Config
=
new
(
Configuration
)
}
Config
.
readConfigFile
(
"../soar.yaml"
)
Config
.
readConfigFile
(
filepath
.
Join
(
DevPath
,
"etc/soar.yaml"
)
)
}
func
TestParseDSN
(
t
*
testing
.
T
)
{
...
...
@@ -59,11 +60,14 @@ func TestParseDSN(t *testing.T) {
"/database"
,
}
GoldenDiff
(
func
()
{
err
:=
GoldenDiff
(
func
()
{
for
_
,
dsn
:=
range
dsns
{
pretty
.
Println
(
parseDSN
(
dsn
,
nil
))
}
},
t
.
Name
(),
update
)
if
nil
!=
err
{
t
.
Fatal
(
err
)
}
}
func
TestListReportTypes
(
t
*
testing
.
T
)
{
...
...
@@ -100,7 +104,14 @@ func TestArgConfig(t *testing.T) {
}
func
TestPrintConfiguration
(
t
*
testing
.
T
)
{
Config
.
Verbose
=
true
PrintConfiguration
()
Config
.
readConfigFile
(
filepath
.
Join
(
DevPath
,
"etc/soar.yaml"
))
oldLogOutput
:=
Config
.
LogOutput
Config
.
LogOutput
=
"soar.log"
err
:=
GoldenDiff
(
func
()
{
PrintConfiguration
()
},
t
.
Name
(),
update
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
Config
.
LogOutput
=
oldLogOutput
}
common/testdata/TestParseDSN.golden
浏览文件 @
1fa1dab4
&common.dsn{Addr:"", Schema:"", User:"", Password:"", Charset:"", Disable:true, Version:0}
(*common.dsn)(nil)
&common.dsn{Addr:"hostname:3307", Schema:"database", User:"user", Password:"password", Charset:"utf8mb4", Disable:false, Version:999}
&common.dsn{Addr:"hostname:3307", Schema:"information_schema", User:"user", Password:"password", Charset:"utf8mb4", Disable:false, Version:999}
&common.dsn{Addr:"hostname:3306", Schema:"database", User:"user", Password:"password", Charset:"utf8mb4", Disable:false, Version:999}
...
...
common/testdata/TestPrintConfiguration.golden
浏览文件 @
1fa1dab4
online-dsn:
addr:
""
schema:
information_schem
a
user:
""
password:
""
addr:
127.0.0.1:3306
schema:
sakil
a
user:
root
password:
'********'
charset: utf8mb4
disable:
tru
e
disable:
fals
e
test-dsn:
addr:
""
schema:
information_schem
a
user:
""
password:
""
addr:
127.0.0.1:3306
schema:
sakil
a
user:
root
password:
'********'
charset: utf8mb4
disable:
tru
e
allow-online-as-test:
fals
e
disable:
fals
e
allow-online-as-test:
tru
e
drop-test-temporary: true
cleanup-test-database: false
only-syntax-check: false
sampling-statistic-target: 100
sampling:
fals
e
sampling:
tru
e
profiling: false
trace: false
explain: true
conn-time-out: 3
query-time-out: 30
delimiter: ;
log-level:
3
log-output:
/dev/stderr
log-level:
7
log-output:
soar.log
report-type: markdown
report-css: ""
report-javascript: ""
...
...
@@ -62,6 +62,7 @@ table-allow-engines:
- innodb
max-index-count: 10
max-column-count: 40
max-value-count: 100
index-prefix: idx_
unique-key-prefix: uk_
max-subquery-depth: 5
...
...
@@ -89,6 +90,6 @@ list-heuristic-rules: false
list-rewrite-rules: false
list-test-sqls: false
list-report-types: false
verbose:
tru
e
verbose:
fals
e
dry-run: true
max-pretty-sql-length: 1024
database/trace_test.go
浏览文件 @
1fa1dab4
...
...
@@ -30,13 +30,10 @@ var update = flag.Bool("update", false, "update .golden files")
func
TestTrace
(
t
*
testing
.
T
)
{
common
.
Config
.
QueryTimeOut
=
1
res
,
err
:=
connTest
.
Trace
(
"select 1"
)
if
err
==
nil
{
common
.
GoldenDiff
(
func
()
{
pretty
.
Println
(
res
)
},
t
.
Name
(),
update
)
}
else
{
if
err
!=
nil
{
t
.
Error
(
err
)
}
pretty
.
Println
(
res
)
}
func
TestFormatTrace
(
t
*
testing
.
T
)
{
...
...
env/env_test.go
浏览文件 @
1fa1dab4
...
...
@@ -46,7 +46,6 @@ func TestNewVirtualEnv(t *testing.T) {
testSQL
:=
[]
string
{
"create table t(id int,c1 varchar(20),PRIMARY KEY (id));"
,
"alter table t add index `idx_c1`(c1);"
,
"alter table t add index `idx_c1`(c1);"
,
"select * from city where country_id = 44;"
,
"select * from address where address2 is not null;"
,
"select * from address where address2 is null;"
,
...
...
@@ -92,7 +91,7 @@ func TestNewVirtualEnv(t *testing.T) {
env
:=
NewVirtualEnv
(
connTest
)
defer
env
.
CleanUp
()
common
.
GoldenDiff
(
func
()
{
err
:=
common
.
GoldenDiff
(
func
()
{
for
_
,
sql
:=
range
testSQL
{
env
.
BuildVirtualEnv
(
rEnv
,
sql
)
switch
err
:=
env
.
Error
.
(
type
)
{
...
...
@@ -111,6 +110,9 @@ func TestNewVirtualEnv(t *testing.T) {
}
}
},
t
.
Name
(),
update
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
}
func
TestCleanupTestDatabase
(
t
*
testing
.
T
)
{
...
...
env/testdata/TestNewVirtualEnv.golden
浏览文件 @
1fa1dab4
create table t(id int,c1 varchar(20),PRIMARY KEY (id)); OK
alter table t add index `idx_c1`(c1); OK
alter table t add index `idx_c1`(c1); OK
select * from city where country_id = 44; OK
select * from address where address2 is not null; OK
select * from address where address2 is null; OK
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录