Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zentaoatf
提交
cdd917b5
Z
zentaoatf
项目概览
易企天创
/
zentaoatf
9 个月 前同步成功
通知
11
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zentaoatf
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
cdd917b5
编写于
8月 17, 2022
作者:
Z
zhaoke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
* Add exec timeout
上级
0591a5da
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
49 addition
and
22 deletion
+49
-22
internal/command/action/list.go
internal/command/action/list.go
+5
-4
internal/pkg/helper/exec/file.go
internal/pkg/helper/exec/file.go
+17
-5
internal/pkg/helper/exec/result.go
internal/pkg/helper/exec/result.go
+1
-1
internal/pkg/helper/script/extract.go
internal/pkg/helper/script/extract.go
+1
-1
internal/pkg/helper/script/parser.go
internal/pkg/helper/script/parser.go
+16
-9
internal/pkg/helper/zentao/sync.go
internal/pkg/helper/zentao/sync.go
+1
-1
res/server/en/messages.json
res/server/en/messages.json
+4
-1
res/server/zh/messages.json
res/server/zh/messages.json
+4
-0
未找到文件。
internal/command/action/list.go
浏览文件 @
cdd917b5
...
...
@@ -2,15 +2,16 @@ package action
import
(
"fmt"
"strconv"
"strings"
"time"
commConsts
"github.com/easysoft/zentaoatf/internal/pkg/consts"
commDomain
"github.com/easysoft/zentaoatf/internal/pkg/domain"
scriptHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/script"
i118Utils
"github.com/easysoft/zentaoatf/pkg/lib/i118"
logUtils
"github.com/easysoft/zentaoatf/pkg/lib/log"
"github.com/mattn/go-runewidth"
"strconv"
"strings"
"time"
)
func
List
(
files
[]
string
,
keywords
string
)
{
...
...
@@ -63,7 +64,7 @@ func List(files []string, keywords string) {
}
func
SummaryObj
(
file
string
,
keywords
string
)
(
bool
,
commDomain
.
FuncResult
)
{
pass
,
caseId
,
_
,
title
:=
scriptHelper
.
GetCaseInfo
(
file
)
pass
,
caseId
,
_
,
title
,
_
:=
scriptHelper
.
GetCaseInfo
(
file
)
if
pass
{
_
,
err
:=
strconv
.
Atoi
(
keywords
)
...
...
internal/pkg/helper/exec/file.go
浏览文件 @
cdd917b5
...
...
@@ -2,16 +2,19 @@ package execHelper
import
(
"bufio"
"context"
"fmt"
"io"
"os"
"os/exec"
"strings"
"time"
commConsts
"github.com/easysoft/zentaoatf/internal/pkg/consts"
commDomain
"github.com/easysoft/zentaoatf/internal/pkg/domain"
configHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/config"
langHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/lang"
scriptHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/script"
websocketHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/websocket"
commonUtils
"github.com/easysoft/zentaoatf/pkg/lib/common"
i118Utils
"github.com/easysoft/zentaoatf/pkg/lib/i118"
...
...
@@ -31,6 +34,13 @@ func RunFile(filePath, workspacePath string, conf commDomain.WorkspaceConf,
lang
:=
langHelper
.
GetLangByFile
(
filePath
)
var
cmd
*
exec
.
Cmd
_
,
_
,
_
,
_
,
timeout
:=
scriptHelper
.
GetCaseInfo
(
filePath
)
if
timeout
==
0
{
timeout
=
86400
*
7
}
ctxt
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
time
.
Duration
(
timeout
))
defer
cancel
()
if
commonUtils
.
IsWin
()
{
scriptInterpreter
:=
""
if
strings
.
ToLower
(
lang
)
!=
"bat"
{
...
...
@@ -75,14 +85,12 @@ func RunFile(filePath, workspacePath string, conf commDomain.WorkspaceConf,
}
//logUtils.ExecFilef(msg)
cmd
=
exec
.
Command
(
scriptInterpreter
,
filePath
)
cmd
=
exec
.
Command
Context
(
ctxt
,
scriptInterpreter
,
filePath
)
}
else
{
cmd
=
exec
.
Command
(
"/bin/bash"
,
"-c"
,
filePath
)
cmd
=
exec
.
Command
Context
(
ctxt
,
"/bin/bash"
,
"-c"
,
filePath
)
}
}
cmd
.
Dir
=
workspacePath
if
cmd
==
nil
{
msgStr
:=
i118Utils
.
Sprintf
(
"cmd_empty"
)
if
commConsts
.
ExecFrom
!=
commConsts
.
FromCmd
{
...
...
@@ -95,6 +103,8 @@ func RunFile(filePath, workspacePath string, conf commDomain.WorkspaceConf,
return
""
,
msgStr
}
cmd
.
Dir
=
workspacePath
stdout
,
err1
:=
cmd
.
StdoutPipe
()
stderr
,
err2
:=
cmd
.
StderrPipe
()
...
...
@@ -176,10 +186,12 @@ ExitCurrCase:
errOutputArr
=
append
(
errOutputArr
,
line
)
}
}
if
ctxt
.
Err
()
!=
nil
{
errOutputArr
=
append
(
errOutputArr
,
i118Utils
.
Sprintf
(
"exec_cmd_timeout"
))
}
stdOutput
=
strings
.
Join
(
stdOutputArr
,
""
)
errOutput
=
strings
.
Join
(
errOutputArr
,
""
)
cmd
.
Wait
()
return
}
internal/pkg/helper/exec/result.go
浏览文件 @
cdd917b5
...
...
@@ -48,7 +48,7 @@ func ValidateCaseResult(scriptFile string, langType string,
key
:=
stringUtils
.
Md5
(
scriptFile
)
_
,
caseId
,
productId
,
title
:=
scriptHelper
.
GetCaseInfo
(
scriptFile
)
_
,
caseId
,
productId
,
title
,
_
:=
scriptHelper
.
GetCaseInfo
(
scriptFile
)
stepLogs
:=
make
([]
commDomain
.
StepLog
,
0
)
caseResult
:=
commConsts
.
PASS
...
...
internal/pkg/helper/script/extract.go
浏览文件 @
cdd917b5
...
...
@@ -167,7 +167,7 @@ func extractFromComments(file string) (stepObjs []*commDomain.ZtfStep) {
}
func
prepareDesc
(
steps
[]
string
,
file
string
)
(
desc
string
)
{
pass
,
caseId
,
productId
,
title
:=
GetCaseInfo
(
file
)
pass
,
caseId
,
productId
,
title
,
_
:=
GetCaseInfo
(
file
)
if
!
pass
{
return
}
...
...
internal/pkg/helper/script/parser.go
浏览文件 @
cdd917b5
...
...
@@ -2,12 +2,6 @@ package scriptHelper
import
(
"fmt"
commConsts
"github.com/easysoft/zentaoatf/internal/pkg/consts"
commDomain
"github.com/easysoft/zentaoatf/internal/pkg/domain"
langHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/lang"
"github.com/easysoft/zentaoatf/pkg/consts"
commonUtils
"github.com/easysoft/zentaoatf/pkg/lib/common"
fileUtils
"github.com/easysoft/zentaoatf/pkg/lib/file"
"html"
"io/ioutil"
"path"
...
...
@@ -15,6 +9,13 @@ import (
"regexp"
"strconv"
"strings"
commConsts
"github.com/easysoft/zentaoatf/internal/pkg/consts"
commDomain
"github.com/easysoft/zentaoatf/internal/pkg/domain"
langHelper
"github.com/easysoft/zentaoatf/internal/pkg/helper/lang"
"github.com/easysoft/zentaoatf/pkg/consts"
commonUtils
"github.com/easysoft/zentaoatf/pkg/lib/common"
fileUtils
"github.com/easysoft/zentaoatf/pkg/lib/file"
)
func
ReplaceCaseDesc
(
desc
,
file
string
)
{
...
...
@@ -504,12 +505,12 @@ func ScriptToExpectName(file string) string {
// return runName
//}
func
GetCaseInfo
(
file
string
)
(
pass
bool
,
caseId
,
productId
int
,
title
string
)
{
func
GetCaseInfo
(
file
string
)
(
pass
bool
,
caseId
,
productId
int
,
title
string
,
timeout
int64
)
{
content
:=
fileUtils
.
ReadFile
(
file
)
isOldFormat
:=
strings
.
Index
(
content
,
"[esac]"
)
>
-
1
pass
=
CheckFileContentIsScript
(
content
)
if
!
pass
{
return
false
,
caseId
,
productId
,
title
return
false
,
caseId
,
productId
,
title
,
timeout
}
caseInfo
:=
""
...
...
@@ -535,6 +536,12 @@ func GetCaseInfo(file string) (pass bool, caseId, productId int, title string) {
caseId
,
_
=
strconv
.
Atoi
(
arr
[
1
])
}
myExp
=
regexp
.
MustCompile
(
`[\S\s]*timeout=\s*([^\n]*?)\s*\n`
)
arr
=
myExp
.
FindStringSubmatch
(
caseInfo
)
if
len
(
arr
)
>
1
{
timeout
,
_
=
strconv
.
ParseInt
(
arr
[
1
],
10
,
64
)
}
myExp
=
regexp
.
MustCompile
(
`[\S\s]*pid=\s*([^\n]*?)\s*\n`
)
arr
=
myExp
.
FindStringSubmatch
(
caseInfo
)
if
len
(
arr
)
>
1
{
...
...
@@ -739,7 +746,7 @@ func GetScriptByIdsInDir(dirPth string, idMap *map[int]string) error {
}
path
:=
dirPth
+
name
pass
,
id
,
_
,
_
:=
GetCaseInfo
(
path
)
pass
,
id
,
_
,
_
,
_
:=
GetCaseInfo
(
path
)
if
pass
{
(
*
idMap
)[
id
]
=
path
}
...
...
internal/pkg/helper/zentao/sync.go
浏览文件 @
cdd917b5
...
...
@@ -71,7 +71,7 @@ func SyncFromZentao(settings commDomain.SyncSettings, config commDomain.Workspac
func
SyncToZentao
(
cases
[]
string
,
config
commDomain
.
WorkspaceConf
)
(
count
int
,
err
error
)
{
for
_
,
cs
:=
range
cases
{
pass
,
id
,
_
,
title
:=
scriptHelper
.
GetCaseInfo
(
cs
)
pass
,
id
,
_
,
title
,
_
:=
scriptHelper
.
GetCaseInfo
(
cs
)
if
!
pass
{
continue
}
...
...
res/server/en/messages.json
浏览文件 @
cdd917b5
...
...
@@ -329,7 +329,10 @@
"id"
:
"exec_cmd_fail"
,
"translation"
:
"Fail to exec cmd %s, error is %s."
},
{
"id"
:
"exec_cmd_timeout"
,
"translation"
:
"Exec cmd timeout."
},
{
"id"
:
"success_to_conn"
,
"translation"
:
"Success to connect."
...
...
res/server/zh/messages.json
浏览文件 @
cdd917b5
...
...
@@ -318,6 +318,10 @@
"id"
:
"exec_cmd_fail"
,
"translation"
:
"执行命令%s失败,错误%s。"
},
{
"id"
:
"exec_cmd_timeout"
,
"translation"
:
"执行命令超时。"
},
{
"id"
:
"cmd_empty"
,
"translation"
:
"命令为空。"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录