提交 a18d1c2a 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

Merge remote-tracking branch 'origin/main'

......@@ -125,6 +125,22 @@ func main() {
action.CommitBug(files, actionModule)
}
case "list", "ls", "-l":
files := fileUtils.GetFilesFromParams(os.Args[2:])
if err := flagSet.Parse(os.Args[len(files)+2:]); err == nil {
if len(files) == 0 {
files = append(files, ".")
}
action.List(files, keywords)
}
case "view", "-v":
files := fileUtils.GetFilesFromParams(os.Args[2:])
if err := flagSet.Parse(os.Args[len(files)+2:]); err == nil {
action.View(files, keywords)
}
case "help", "-h", "-help", "--help":
resUtils.PrintUsage()
......
package action
import (
"fmt"
commDomain "github.com/aaronchen2k/deeptest/internal/comm/domain"
scriptUtils "github.com/aaronchen2k/deeptest/internal/comm/helper/script"
i118Utils "github.com/aaronchen2k/deeptest/internal/pkg/lib/i118"
logUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/log"
"github.com/fatih/color"
"github.com/mattn/go-runewidth"
"strconv"
"strings"
"time"
)
func List(files []string, keywords string) {
var cases []string
for _, v1 := range files {
group := scriptUtils.LoadScriptByProject(v1)
for _, v2 := range group {
cases = append(cases, v2)
}
}
keywords = strings.TrimSpace(keywords)
scriptArr := make([]commDomain.FuncResult, 0)
pathMaxWidth := 0
numbMaxWidth := 0
for _, tc := range cases {
pass, cs := SummaryObj(tc, keywords)
if pass {
scriptArr = append(scriptArr, cs)
}
if len(cs.Path) > pathMaxWidth {
pathMaxWidth = len(cs.Path)
}
if len(tc) > numbMaxWidth {
numbMaxWidth = len(strconv.Itoa(cs.Id))
}
}
numbWidth := strconv.Itoa(numbMaxWidth)
total := len(scriptArr)
width := strconv.Itoa(len(strconv.Itoa(total)))
logUtils.Info(time.Now().Format("2006-01-02 15:04:05") + " " +
i118Utils.Sprintf("found_scripts", color.CyanString(strconv.Itoa(total))) + "\n")
for idx, cs := range scriptArr {
//format := "(%" + width + "d/%d) [%s] %d.%s"
//logUtils.Screen(fmt.Sprintf(format, idx+1, total, cs.Path, cs.Id, cs.Title))
path := cs.Path
lent := runewidth.StringWidth(path)
if pathMaxWidth > lent {
postFix := strings.Repeat(" ", pathMaxWidth-lent)
path += postFix
}
format := "(%" + width + "d/%d) [%s] [%" + numbWidth + "d. %s]"
logUtils.Info(fmt.Sprintf(format, idx+1, total, path, cs.Id, cs.Title))
}
}
func SummaryObj(file string, keywords string) (bool, commDomain.FuncResult) {
pass, caseId, _, title := scriptUtils.GetCaseInfo(file)
if pass {
_, err := strconv.Atoi(keywords)
var pass bool
if err == nil && keywords == strconv.Itoa(caseId) { // int
pass = true
} else if strings.Index(title, keywords) > -1 {
pass = true
}
if pass {
return true, commDomain.FuncResult{Id: caseId, Title: title, Path: file}
} else {
return false, commDomain.FuncResult{}
}
}
return false, commDomain.FuncResult{}
}
package action
import (
"fmt"
scriptUtils "github.com/aaronchen2k/deeptest/internal/comm/helper/script"
commonUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/common"
fileUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/file"
i118Utils "github.com/aaronchen2k/deeptest/internal/pkg/lib/i118"
langUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/lang"
logUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/log"
"github.com/fatih/color"
"regexp"
"strconv"
"strings"
"time"
)
func View(files []string, keywords string) {
var cases []string
for _, v1 := range files {
group := scriptUtils.LoadScriptByProject(v1)
for _, v2 := range group {
cases = append(cases, v2)
}
}
view(cases, keywords)
}
func view(cases []string, keywords string) {
keywords = strings.TrimSpace(keywords)
count := 0
arrs := make([][]string, 0)
for _, file := range cases {
pass, arr := brief(file, keywords)
if pass {
arrs = append(arrs, arr)
count++
}
}
total := len(arrs)
logUtils.Info(time.Now().Format("2006-01-02 15:04:05") + " " + i118Utils.Sprintf("found_scripts",
color.CyanString(strconv.Itoa(total))))
width := len(strconv.Itoa(len(arrs)))
for idx, arr := range arrs {
numb := fmt.Sprintf("#%0"+strconv.Itoa(width)+"d", idx+1)
logUtils.Infof(logUtils.GetWholeLine(numb+" "+arr[3], "="))
logUtils.ExecConsole(color.FgCyan, fmt.Sprintf("%s. %s", arr[0], arr[1]))
fmt.Printf("Steps: \n%s \n", arr[2])
logUtils.Info("")
}
}
func brief(file string, keywords string) (bool, []string) {
content := fileUtils.ReadFile(file)
lang := langUtils.GetLangByFile(file)
isOldFormat := strings.Index(content, "[esac]") > -1
regStr := ""
if isOldFormat {
regStr = `\[case\][\S\s]*` +
`title=([^\n]*)\n+` +
`cid=([^\n]*)\n+` +
`pid=([^\n]*)\n+` +
`([\S\s]*)\n*` +
`\[esac\]`
} else {
regStr = fmt.Sprintf(`(?sm)%s[\S\s]*`+
`title=([^\n]*)\n+`+
`cid=([^\n]*)\n+`+
`pid=([^\n]*)\n+`+
`([\S\s]*)\n*%s`,
langUtils.LangCommentsRegxMap[lang][0], langUtils.LangCommentsRegxMap[lang][1])
}
myExp := regexp.MustCompile(regStr)
arr := myExp.FindStringSubmatch(content)
if len(arr) > 2 {
title := commonUtils.RemoveBlankLine(arr[1])
caseId := commonUtils.RemoveBlankLine(arr[2])
//productId := commonUtils.RemoveBlankLine(arr[3])
steps := commonUtils.RemoveBlankLine(arr[4])
_, err := strconv.Atoi(keywords)
var pass bool
if err == nil && keywords == caseId { // int
pass = true
} else if strings.Index(title, keywords) > -1 {
pass = true
}
if pass {
return true, []string{caseId, title, steps, file}
} else {
return false, nil
}
}
return false, nil
}
......@@ -31,7 +31,7 @@ func RunZTFTest(file []string, suiteIdStr, taskIdStr string, actionModule *comma
cases = append(cases, file[0])
} else {
_, _, _, scriptTree, _ := actionModule.ProjectService.GetByUser(commConsts.WorkDir)
cases = GetCasesFromChildren(scriptTree.Children)
cases = getCasesFromChildren(scriptTree.Children)
}
req.Cases = cases
......@@ -42,13 +42,13 @@ func RunZTFTest(file []string, suiteIdStr, taskIdStr string, actionModule *comma
}
// 扁平化
func GetCasesFromChildren(scripts []*serverDomain.TestAsset) (cases []string) {
func getCasesFromChildren(scripts []*serverDomain.TestAsset) (cases []string) {
for _, v := range scripts {
if v.Path != "" {
cases = append(cases, v.Path)
}
if v.Children != nil {
GetCasesFromChildren(v.Children)
getCasesFromChildren(v.Children)
}
}
return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册