From 82148b146735afae554cd229350c5147ebc292b7 Mon Sep 17 00:00:00 2001 From: Aaron Chen <462826@qq.com> Date: Tue, 27 Aug 2019 11:43:03 +0800 Subject: [PATCH] support run with dir suite task result files --- src/action/run.go | 5 ----- src/utils/file/file.go | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/action/run.go b/src/action/run.go index 7efaadae..9ad80535 100644 --- a/src/action/run.go +++ b/src/action/run.go @@ -10,7 +10,6 @@ import ( logUtils "github.com/easysoft/zentaoatf/src/utils/log" "github.com/easysoft/zentaoatf/src/utils/vari" "github.com/fatih/color" - "path" "path/filepath" "strconv" ) @@ -43,10 +42,6 @@ func Run(files []string, suite string, task string, result string) { fileUtils.GetScriptByIdsInDir(files[0], caseIdMap, &cases) } else { // find cases in current dir for _, file := range files { - if !path.IsAbs(file) { - file, _ = filepath.Abs(file) - } - fileUtils.GetAllScriptsInDir(file, &cases) } } diff --git a/src/utils/file/file.go b/src/utils/file/file.go index 73fba183..a7d1224f 100644 --- a/src/utils/file/file.go +++ b/src/utils/file/file.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "os" "path" + "path/filepath" "regexp" "strconv" "strings" @@ -53,6 +54,11 @@ func FileExist(path string) bool { } func GetAllScriptsInDir(dirPth string, files *[]string) error { + dirPth = commonUtils.UpdateDir(dirPth) + if !path.IsAbs(dirPth) { + dirPth, _ = filepath.Abs(dirPth) + } + sep := string(os.PathSeparator) dir, err := ioutil.ReadDir(dirPth) @@ -75,10 +81,15 @@ func GetAllScriptsInDir(dirPth string, files *[]string) error { return nil } -func GetScriptByIdsInDir(dir string, idMap map[int]string, files *[]string) error { +func GetScriptByIdsInDir(dirPth string, idMap map[int]string, files *[]string) error { + dirPth = commonUtils.UpdateDir(dirPth) + if !path.IsAbs(dirPth) { + dirPth, _ = filepath.Abs(dirPth) + } + sep := string(os.PathSeparator) - dir, err := ioutil.ReadDir(dir) + dir, err := ioutil.ReadDir(dirPth) if err != nil { return err } @@ -86,9 +97,9 @@ func GetScriptByIdsInDir(dir string, idMap map[int]string, files *[]string) erro for _, fi := range dir { name := fi.Name() if fi.IsDir() { // 目录, 递归遍历 - GetAllScriptsInDir(dir+name+sep, files) + GetAllScriptsInDir(dirPth+name+sep, files) } else { - path := dir + name + path := dirPth + name if CheckFileIsScript(path) { *files = append(*files, path) } -- GitLab