提交 10d09544 编写于 作者: m0_58228130's avatar m0_58228130

ztfTest

上级 0ddd45ee
......@@ -168,7 +168,7 @@ func run(args []string) {
if vari.Interpreter != "" {
logUtils.PrintToWithColor(i118Utils.Sprintf("run_with_specific_interpreter", vari.Interpreter), color.FgCyan)
}
//action.RunZTFTest(files, suiteId, taskId)
action.RunZTFTest(files, suiteId, taskId)
} else {
resUtils.PrintUsage()
}
......
......@@ -3,7 +3,7 @@ package agentViper
import (
"bytes"
"fmt"
"github.com/aaronchen2k/deeptest/internal/agent/consts"
agentConfig "github.com/aaronchen2k/deeptest/internal/agent/config"
"github.com/aaronchen2k/deeptest/internal/pkg/consts"
myZap "github.com/aaronchen2k/deeptest/internal/pkg/core/zap"
"github.com/fsnotify/fsnotify"
......@@ -19,8 +19,8 @@ func Init() {
fmt.Printf("配置文件路径为%s\n", config)
v := viper.New()
agentConsts.VIPER = v
agentConsts.VIPER.SetConfigType("yaml")
agentConfig.VIPER = v
agentConfig.VIPER.SetConfigType("yaml")
if !dir.IsExist(config) { //没有配置文件,写入默认配置
var yamlDefault = []byte(`
......@@ -39,38 +39,38 @@ zap:
stacktrace-key: stacktrace
log-in-console: true`)
if err := agentConsts.VIPER.ReadConfig(bytes.NewBuffer(yamlDefault)); err != nil {
if err := agentConfig.VIPER.ReadConfig(bytes.NewBuffer(yamlDefault)); err != nil {
panic(fmt.Errorf("读取默认配置文件错误: %w ", err))
}
if err := agentConsts.VIPER.Unmarshal(&agentConsts.CONFIG); err != nil {
if err := agentConfig.VIPER.Unmarshal(&agentConfig.CONFIG); err != nil {
panic(fmt.Errorf("同步配置文件错误: %w ", err))
}
if err := agentConsts.VIPER.WriteConfigAs(config); err != nil {
if err := agentConfig.VIPER.WriteConfigAs(config); err != nil {
panic(fmt.Errorf("写入配置文件错误: %w ", err))
}
return
}
// 存在配置文件,读取配置文件内容
agentConsts.VIPER.SetConfigFile(config)
err := agentConsts.VIPER.ReadInConfig()
agentConfig.VIPER.SetConfigFile(config)
err := agentConfig.VIPER.ReadInConfig()
if err != nil {
panic(fmt.Errorf("读取配置错误: %w ", err))
}
// 监控配置文件变化
agentConsts.VIPER.WatchConfig()
agentConsts.VIPER.OnConfigChange(func(e fsnotify.Event) {
agentConfig.VIPER.WatchConfig()
agentConfig.VIPER.OnConfigChange(func(e fsnotify.Event) {
fmt.Println("配置发生变化:", e.Name)
if err := agentConsts.VIPER.Unmarshal(&agentConsts.CONFIG); err != nil {
if err := agentConfig.VIPER.Unmarshal(&agentConfig.CONFIG); err != nil {
fmt.Println(err)
}
})
if err := v.Unmarshal(&agentConsts.CONFIG); err != nil {
if err := v.Unmarshal(&agentConfig.CONFIG); err != nil {
fmt.Println(err)
}
myZap.ZapInst = agentConsts.CONFIG.Zap
myZap.ZapInst = agentConfig.CONFIG.Zap
}
......@@ -13,4 +13,5 @@ var (
SessionId string
SessionVar string
RequestFix string
ComeFrom = "cmd"
)
package vari
import commDomain "github.com/aaronchen2k/deeptest/internal/comm/domain"
var (
IsDebug bool
//Config = model.Config{}
Config = commDomain.ProjectConf{}
//Cui *gocui.Gui
MainViewHeight int
......
package action
import (
commConsts "github.com/aaronchen2k/deeptest/internal/comm/consts"
"github.com/aaronchen2k/deeptest/internal/comm/vari"
"github.com/aaronchen2k/deeptest/internal/pkg/consts"
fileUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/file"
i118Utils "github.com/aaronchen2k/deeptest/internal/pkg/lib/i118"
logUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/log"
serverLog "github.com/aaronchen2k/deeptest/internal/server/core/log"
_scriptUtils "github.com/aaronchen2k/deeptest/internal/server/modules/utils/exec"
scriptUtils "github.com/aaronchen2k/deeptest/internal/server/modules/utils/script"
serverDomain "github.com/aaronchen2k/deeptest/internal/server/modules/v1/domain"
"github.com/kataras/iris/v12/websocket"
"path"
"strconv"
)
func RunZTFTest(files []string, suiteIdStr, taskIdStr string) error {
serverLog.Init()
cases := make([]string, 0)
if suiteIdStr != "" { // run with suite id
dir := fileUtils.AbsolutePath(".")
if vari.ServerProjectDir != "" {
dir = vari.ServerProjectDir
} else if len(files) > 0 {
dir = files[0]
}
cases = getCaseBySuiteId(suiteIdStr, dir)
} else if taskIdStr != "" { // run with task id,
dir := fileUtils.AbsolutePath(".")
if vari.ServerProjectDir != "" {
dir = vari.ServerProjectDir
} else if len(files) > 0 {
dir = files[0]
}
cases = getCaseByTaskId(taskIdStr, dir)
} else {
suite, dir := isRunWithSuiteFile(files)
result := isRunWithResultFile(files)
if suite != "" { // run from suite file
if dir == "" { // not found dir in files param
dir = fileUtils.AbsolutePath(".")
if vari.ServerProjectDir != "" {
dir = vari.ServerProjectDir
}
}
cases = getCaseBySuiteFile(suite, dir)
} else if result != "" { // run from failed result file
//cases = assertUtils.GetFailedCasesDirectlyFromTestResult(result)
scriptTree, _ := scriptUtils.LoadScriptTree(commConsts.WorkDir)
cases = GetCasesFromChildren(scriptTree.Children)
} else { // run files
//cases = assertUtils.GetCaseByDirAndFile(files)
scriptTree, _ := scriptUtils.LoadScriptTree(commConsts.WorkDir)
cases = GetCasesFromChildren(scriptTree.Children)
}
}
if len(cases) < 1 {
logUtils.PrintTo("\n" + i118Utils.Sprintf("no_cases"))
return nil
}
//runCases(cases)
req := serverDomain.WsReq{
Cases: cases,
Act: commConsts.ExecCase,
}
msg := websocket.Message{}
_scriptUtils.Exec(nil, nil, nil, req, msg)
return nil
}
func getCaseBySuiteId(id string, dir string) []string { // todo
//caseIdMap := map[int]string{}
cases := make([]string, 0)
//suiteId, err := strconv.Atoi(id)
return cases
}
func getCaseBySuiteFile(file string, dir string) []string {
//caseIdMap := map[int]string{}
cases := make([]string, 0)
//assertUtils.GetCaseIdsInSuiteFile(file, &caseIdMap)
//assertUtils.GetScriptByIdsInDir(dir, caseIdMap, &cases)
return cases
}
func getCaseByTaskId(id string, dir string) []string {
//caseIdMap := map[int]string{}
cases := make([]string, 0)
taskId, err := strconv.Atoi(id)
if err == nil && taskId > 0 {
//configUtils.CheckRequestConfig()
//zentaoService.GetCaseIdsByTask(id, &caseIdMap)
}
//assertUtils.GetScriptByIdsInDir(dir, caseIdMap, &cases)
return cases
}
func isRunWithSuiteFile(files []string) (suiteFile, dir string) {
for _, file := range files {
if path.Ext(file) == "."+consts.ExtNameSuite {
suiteFile = file
} else {
if dir == "" { // only select the first dir
dir = file
}
}
if suiteFile != "" && dir != "" {
break
}
}
return
}
func isRunWithResultFile(files []string) string {
var resultFile string
for _, file := range files {
if path.Ext(file) == "."+consts.ExtNameResult || path.Ext(file) == "."+consts.ExtNameJson {
resultFile = file
return resultFile
}
}
return ""
}
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)
}
}
return
}
......@@ -10,8 +10,8 @@ import (
i118Utils "github.com/aaronchen2k/deeptest/internal/pkg/lib/i118"
logUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/log"
stdinUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/stdin"
configUtils "github.com/aaronchen2k/deeptest/internal/server/modules/utils/config"
"github.com/aaronchen2k/deeptest/internal/server/modules/v1/repo"
configUtils "github.com/aaronchen2k/deeptest/internal/server/modules/v1/utils/config"
"github.com/fatih/color"
"os"
"reflect"
......
......@@ -91,7 +91,11 @@ func GenUnitTestReport(req serverDomain.WsReq, startTime, endTime int64,
}
temp := i118Utils.Sprintf("found_scripts", strconv.Itoa(len(cases))) + postFix
sendExecMsg(temp, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(temp, "", wsMsg)
}
logUtils.ExecConsolef(color.FgCyan, temp)
logUtils.ExecResult(temp)
......@@ -101,7 +105,11 @@ func GenUnitTestReport(req serverDomain.WsReq, startTime, endTime int64,
format := "(%" + width + "d/%d) %s [%s] [%" + width + "d. %s] (%.3fs)"
msg := fmt.Sprintf(format, idx+1, report.Total, cs.Status, testSuite, cs.Id, cs.Title, cs.Duration)
sendExecMsg(msg, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(msg, "", wsMsg)
}
logUtils.ExecConsolef(color.FgCyan, temp)
logUtils.ExecResult(msg)
}
......@@ -111,7 +119,10 @@ func GenUnitTestReport(req serverDomain.WsReq, startTime, endTime int64,
msg += strings.Join(failedCaseLines, "\n")
msg += strings.Join(failedCaseLinesDesc, "\n")
sendExecMsg(msg, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(msg, "", wsMsg)
}
logUtils.ExecConsolef(color.FgCyan, temp)
logUtils.ExecResult(msg)
}
......@@ -142,14 +153,20 @@ func GenUnitTestReport(req serverDomain.WsReq, startTime, endTime int64,
report.Total, report.Duration, secTag,
passStr, failStr, skipStr,
)
sendExecMsg(msg, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(msg, "", wsMsg)
}
logUtils.ExecConsole(color.FgCyan, msg)
logUtils.ExecResult(msg)
resultPath := filepath.Join(commConsts.ExecLogDir, commConsts.ResultText)
msg = " " + i118Utils.Sprintf("run_report", resultPath) + "\n"
sendExecMsg(msg, "false", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(msg, "false", wsMsg)
}
logUtils.ExecConsole(color.FgCyan, msg)
logUtils.ExecResult(msg)
......
......@@ -80,7 +80,10 @@ func GenZTFTestReport(report commDomain.ZtfReport, pathMaxWidth int,
msg += strings.Join(failedCaseLines, "\n")
msg += strings.Join(failedCaseLinesWithCheckpoint, "\n")
sendExecMsg(msg, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(msg, "", wsMsg)
}
logUtils.ExecConsolef(color.FgRed, msg)
logUtils.ExecFile(msg)
}
......@@ -111,14 +114,21 @@ func GenZTFTestReport(report commDomain.ZtfReport, pathMaxWidth int,
report.Total, report.Duration, secTag,
passStr, failStr, skipStr,
)
sendExecMsg(msg, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(msg, "", wsMsg)
}
logUtils.ExecConsole(color.FgCyan, msg)
logUtils.ExecResult(msg)
resultPath := filepath.Join(commConsts.ExecLogDir, commConsts.ResultText)
msg = " " + i118Utils.Sprintf("run_report", resultPath) + "\n"
sendExecMsg(msg, "false", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(msg, "false", wsMsg)
}
logUtils.ExecConsole(color.FgCyan, msg)
logUtils.ExecResult(msg)
......
......@@ -126,7 +126,10 @@ func ValidateCaseResult(scriptFile string, langType string,
status := i118Utils.Sprintf(cs.Status.String())
msg := fmt.Sprintf(format, idx+1, total, status, path, cs.Id, cs.Title, secs)
sendExecMsg(msg, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(msg, "", wsMsg)
}
logUtils.ExecConsole(color.FgCyan, msg)
logUtils.ExecResult(msg)
}
......
......@@ -3,6 +3,7 @@ package scriptUtils
import (
"bufio"
"errors"
commConsts "github.com/aaronchen2k/deeptest/internal/comm/consts"
dateUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/date"
i118Utils "github.com/aaronchen2k/deeptest/internal/pkg/lib/i118"
logUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/log"
......@@ -21,7 +22,11 @@ func ExecUnit(ch chan int, sendOutputMsg,
startTime := time.Now()
startMsg := i118Utils.Sprintf("start_execution", req.Cmd, dateUtils.DateTimeStr(startTime))
sendExecMsg(startMsg, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(startMsg, "", wsMsg)
}
logUtils.ExecConsolef(-1, startMsg)
logUtils.ExecFilef(startMsg)
......@@ -29,7 +34,11 @@ func ExecUnit(ch chan int, sendOutputMsg,
entTime := time.Now()
endMsg := i118Utils.Sprintf("end_execution", req.Cmd, dateUtils.DateTimeStr(entTime))
sendExecMsg(endMsg, "false", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(endMsg, "false", wsMsg)
}
logUtils.ExecConsolef(-1, endMsg)
logUtils.ExecFilef(endMsg)
......@@ -95,7 +104,11 @@ func RunUnitTest(ch chan int, sendOutputMsg, sendExecMsg func(info, isRunning st
select {
case <-ch:
msg := i118Utils.Sprintf("exit_exec_curr")
sendExecMsg(msg, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(msg, "", wsMsg)
}
logUtils.ExecConsolef(color.FgCyan, msg)
logUtils.ExecFilef(msg)
......
......@@ -103,13 +103,19 @@ func ExeScripts(casesToRun []string, casesToIgnore []string, projectPath string,
}
temp := i118Utils.Sprintf("found_scripts", strconv.Itoa(len(casesToRun))) + postFix
sendExecMsg(temp, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(temp, "", wsMsg)
}
logUtils.ExecConsolef(color.FgCyan, temp)
logUtils.ExecResult(temp)
if len(casesToIgnore) > 0 {
temp := i118Utils.Sprintf("ignore_scripts", strconv.Itoa(len(casesToIgnore))) + postFix
sendExecMsg(temp, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(temp, "", wsMsg)
}
logUtils.ExecConsolef(color.FgCyan, temp)
logUtils.ExecResult(temp)
}
......@@ -120,6 +126,9 @@ func ExeScripts(casesToRun []string, casesToIgnore []string, projectPath string,
select {
case <-ch:
msg := i118Utils.Sprintf("exit_exec_all")
if commConsts.ComeFrom != "cmd" {
}
sendExecMsg(msg, "", wsMsg)
logUtils.ExecConsolef(color.FgCyan, msg)
logUtils.ExecFilef(msg)
......@@ -142,7 +151,10 @@ func ExeScript(scriptFile, projectPath string, conf commDomain.ProjectConf, repo
startTime := time.Now()
startMsg := i118Utils.Sprintf("start_execution", scriptFile, dateUtils.DateTimeStr(startTime))
sendExecMsg(startMsg, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(startMsg, "", wsMsg)
}
logUtils.ExecConsolef(-1, startMsg)
logUtils.ExecFilef(startMsg)
......@@ -163,7 +175,10 @@ func ExeScript(scriptFile, projectPath string, conf commDomain.ProjectConf, repo
secs := fmt.Sprintf("%.2f", float32(entTime.Sub(startTime)/time.Second))
endMsg := i118Utils.Sprintf("end_execution", scriptFile, dateUtils.DateTimeStr(entTime))
sendExecMsg(endMsg, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendExecMsg(endMsg, "", wsMsg)
}
logUtils.ExecConsolef(-1, endMsg)
logUtils.ExecFilef(endMsg)
......@@ -251,7 +266,9 @@ func RunScript(filePath, projectPath string, conf commDomain.ProjectConf,
for {
line, err2 := reader1.ReadString('\n')
if line != "" {
sendOutputMsg(line, "", wsMsg)
if commConsts.ComeFrom != "cmd" {
sendOutputMsg(line, "", wsMsg)
}
logUtils.ExecConsole(1, line)
logUtils.ExecFile(line)
......@@ -266,6 +283,9 @@ func RunScript(filePath, projectPath string, conf commDomain.ProjectConf,
select {
case <-ch:
msg := i118Utils.Sprintf("exit_exec_curr")
if commConsts.ComeFrom != "cmd" {
}
sendExecMsg(msg, "", wsMsg)
logUtils.ExecConsolef(color.FgCyan, msg)
logUtils.ExecFilef(msg)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册