提交 1fa1dab4 编写于 作者: martianzhang's avatar martianzhang

update test case golden file

  go test ./... -update
上级 dda41ec5
......@@ -64,6 +64,12 @@ test:
go test ./...
@echo "test Success!"
# Rule golang test cases with `-update` flag
test-update:
@echo "\033[92mRun all test cases with -update flag ...\033[0m"
go test ./... -update
@echo "test-update Success!"
# Code Coverage
# colorful coverage numerical >=90% GREEN, <80% RED, Other YELLOW
.PHONY: cover
......
......@@ -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.MaxFpPrettySqlLength 长度的指纹不会进行pretty
// 超出 Config.MaxPrettySQLLength 长度的指纹不会进行pretty
if len(fingerprint) > common.Config.MaxPrettySQLLength {
return sql
}
......
......@@ -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) {
......
......@@ -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)
......
......@@ -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.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}
......
online-dsn:
addr: ""
schema: information_schema
user: ""
password: ""
addr: 127.0.0.1:3306
schema: sakila
user: root
password: '********'
charset: utf8mb4
disable: true
disable: false
test-dsn:
addr: ""
schema: information_schema
user: ""
password: ""
addr: 127.0.0.1:3306
schema: sakila
user: root
password: '********'
charset: utf8mb4
disable: true
allow-online-as-test: false
disable: false
allow-online-as-test: true
drop-test-temporary: true
cleanup-test-database: false
only-syntax-check: false
sampling-statistic-target: 100
sampling: false
sampling: true
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: true
verbose: false
dry-run: true
max-pretty-sql-length: 1024
......@@ -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) {
......
......@@ -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) {
......
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.
先完成此消息的编辑!
想要评论请 注册