From f818c326cf43116572011b936ac0efe2f9d00945 Mon Sep 17 00:00:00 2001 From: Leon Zhang Date: Wed, 25 Sep 2019 12:44:51 +0800 Subject: [PATCH] update DevPath test cases --- advisor/index_test.go | 6 ++++++ ast/meta_test.go | 6 ++++++ cmd/soar/soar_test.go | 6 ++++++ common/config_test.go | 5 +++++ database/mysql_test.go | 6 ++++++ env/env_test.go | 6 ++++++ 6 files changed, 35 insertions(+) diff --git a/advisor/index_test.go b/advisor/index_test.go index 677fff6..6e755d8 100644 --- a/advisor/index_test.go +++ b/advisor/index_test.go @@ -20,6 +20,8 @@ import ( "flag" "fmt" "os" + "path/filepath" + "runtime" "strings" "testing" @@ -37,6 +39,10 @@ var rEnv *database.Connector func TestMain(m *testing.M) { // 初始化 init + if common.DevPath == "" { + _, file, _, _ := runtime.Caller(0) + common.DevPath, _ = filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator)))) + } common.BaseDir = common.DevPath err := common.ParseConfig("") common.LogIfError(err, "init ParseConfig") diff --git a/ast/meta_test.go b/ast/meta_test.go index 9808dcd..cc685b2 100644 --- a/ast/meta_test.go +++ b/ast/meta_test.go @@ -19,6 +19,8 @@ package ast import ( "flag" "fmt" + "path/filepath" + "runtime" "testing" "github.com/XiaoMi/soar/common" @@ -31,6 +33,10 @@ var update = flag.Bool("update", false, "update .golden files") func TestMain(m *testing.M) { // 初始化 init + if common.DevPath == "" { + _, file, _, _ := runtime.Caller(0) + common.DevPath, _ = filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator)))) + } common.BaseDir = common.DevPath err := common.ParseConfig("") common.LogIfError(err, "init ParseConfig") diff --git a/cmd/soar/soar_test.go b/cmd/soar/soar_test.go index c538e5a..b0d545d 100644 --- a/cmd/soar/soar_test.go +++ b/cmd/soar/soar_test.go @@ -20,6 +20,8 @@ import ( "flag" "fmt" "os" + "path/filepath" + "runtime" "testing" "github.com/XiaoMi/soar/common" @@ -29,6 +31,10 @@ var update = flag.Bool("update", false, "update .golden files") func TestMain(m *testing.M) { // 初始化 init + if common.DevPath == "" { + _, file, _, _ := runtime.Caller(0) + common.DevPath, _ = filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator)))) + } common.BaseDir = common.DevPath err := common.ParseConfig("") common.LogIfError(err, "init ParseConfig") diff --git a/common/config_test.go b/common/config_test.go index 3f2cb49..ac86791 100644 --- a/common/config_test.go +++ b/common/config_test.go @@ -20,6 +20,7 @@ import ( "flag" "os" "path/filepath" + "runtime" "testing" "github.com/kr/pretty" @@ -29,6 +30,10 @@ var update = flag.Bool("update", false, "update .golden files") func TestMain(m *testing.M) { // 初始化 init + if DevPath == "" { + _, file, _, _ := runtime.Caller(0) + DevPath, _ = filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator)))) + } BaseDir = DevPath err := ParseConfig("") LogIfError(err, "init ParseConfig") diff --git a/database/mysql_test.go b/database/mysql_test.go index 18f20fc..eb18426 100644 --- a/database/mysql_test.go +++ b/database/mysql_test.go @@ -20,6 +20,8 @@ import ( "flag" "fmt" "os" + "path/filepath" + "runtime" "testing" "github.com/XiaoMi/soar/common" @@ -32,6 +34,10 @@ var update = flag.Bool("update", false, "update .golden files") func TestMain(m *testing.M) { // 初始化 init + if common.DevPath == "" { + _, file, _, _ := runtime.Caller(0) + common.DevPath, _ = filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator)))) + } common.BaseDir = common.DevPath err := common.ParseConfig("") common.LogIfError(err, "init ParseConfig") diff --git a/env/env_test.go b/env/env_test.go index e7e5ece..2dc9390 100644 --- a/env/env_test.go +++ b/env/env_test.go @@ -20,6 +20,8 @@ import ( "flag" "fmt" "os" + "path/filepath" + "runtime" "testing" "github.com/XiaoMi/soar/common" @@ -35,6 +37,10 @@ var rEnv *database.Connector func TestMain(m *testing.M) { // 初始化 init + if common.DevPath == "" { + _, file, _, _ := runtime.Caller(0) + common.DevPath, _ = filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator)))) + } common.BaseDir = common.DevPath err := common.ParseConfig("") common.LogIfError(err, "init ParseConfig") -- GitLab