diff --git a/advisor/index_test.go b/advisor/index_test.go index 677fff687dadaae3dfca9c73116fc8ceabc3cec7..6e755d843530f52c77b1fd8685806991dd3c3c19 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 9808dcd9edc05ddf02315e8f678fe0374027d205..cc685b2202555564a0fdef32f015d635dc50eafa 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 c538e5ac670602ea94f0de9b5813863fa4a355cc..b0d545d6796cd262715f6471cecf43b93c2f1ecf 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 3f2cb4933fab375c8b75b42becdee11c16566e31..ac8679198fcca9d5ecba72ef99a9f45bfed660e5 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 18f20fc103adb267812d655cae941e3e8dda8302..eb184263b559b0bb007e7176a6ac79025f5b76ea 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 e7e5ece1cbf40443709cabc2ebf11f2e394f126a..2dc939075c23425748fce253a36ff23465fe4ce5 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")