Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zentaoatf
提交
52ff43ff
Z
zentaoatf
项目概览
易企天创
/
zentaoatf
10 个月 前同步成功
通知
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 搜索 >>
提交
52ff43ff
编写于
2月 16, 2022
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update http methed to return an err object
上级
f209f008
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
143 addition
and
120 deletion
+143
-120
internal/comm/helper/exec/ztf.go
internal/comm/helper/exec/ztf.go
+9
-3
internal/comm/helper/zentao/bug.go
internal/comm/helper/zentao/bug.go
+8
-8
internal/comm/helper/zentao/case.go
internal/comm/helper/zentao/case.go
+30
-25
internal/comm/helper/zentao/result.go
internal/comm/helper/zentao/result.go
+4
-2
internal/comm/helper/zentao/zentao.go
internal/comm/helper/zentao/zentao.go
+49
-36
internal/pkg/lib/http/http.go
internal/pkg/lib/http/http.go
+41
-44
internal/server/modules/v1/service/test-case.go
internal/server/modules/v1/service/test-case.go
+2
-2
未找到文件。
internal/comm/helper/exec/ztf.go
浏览文件 @
52ff43ff
...
...
@@ -37,7 +37,10 @@ func ExecCase(ch chan int, sendOutputMsg, sendExecMsg func(info, isRunning strin
func
ExecModule
(
ch
chan
int
,
sendOutputMsg
,
sendExecMsg
func
(
info
,
isRunning
string
,
wsMsg
websocket
.
Message
),
req
serverDomain
.
WsReq
,
msg
websocket
.
Message
)
(
report
commDomain
.
ZtfReport
,
pathMaxWidth
int
,
err
error
)
{
cases
:=
zentaoUtils
.
GetCasesByModule
(
stringUtils
.
ParseInt
(
req
.
ProductId
),
stringUtils
.
ParseInt
(
req
.
ModuleId
),
req
.
ProjectPath
)
cases
,
err
:=
zentaoUtils
.
GetCasesByModule
(
stringUtils
.
ParseInt
(
req
.
ProductId
),
stringUtils
.
ParseInt
(
req
.
ModuleId
),
req
.
ProjectPath
)
if
err
!=
nil
{
return
}
if
req
.
Seq
!=
""
{
cases
=
analysisUtils
.
FilterCaseByResult
(
cases
,
req
)
...
...
@@ -49,7 +52,7 @@ func ExecModule(ch chan int, sendOutputMsg, sendExecMsg func(info, isRunning str
func
ExecSuite
(
ch
chan
int
,
sendOutputMsg
,
sendExecMsg
func
(
info
,
isRunning
string
,
wsMsg
websocket
.
Message
),
req
serverDomain
.
WsReq
,
msg
websocket
.
Message
)
(
report
commDomain
.
ZtfReport
,
pathMaxWidth
int
,
err
error
)
{
cases
:=
zentaoUtils
.
GetCasesBySuite
(
stringUtils
.
ParseInt
(
req
.
ProductId
),
stringUtils
.
ParseInt
(
req
.
SuiteId
),
req
.
ProjectPath
)
cases
,
err
:=
zentaoUtils
.
GetCasesBySuite
(
stringUtils
.
ParseInt
(
req
.
ProductId
),
stringUtils
.
ParseInt
(
req
.
SuiteId
),
req
.
ProjectPath
)
if
req
.
Seq
!=
""
{
cases
=
analysisUtils
.
FilterCaseByResult
(
cases
,
req
)
...
...
@@ -61,7 +64,10 @@ func ExecSuite(ch chan int, sendOutputMsg, sendExecMsg func(info, isRunning stri
func
ExecTask
(
ch
chan
int
,
sendOutputMsg
,
sendExecMsg
func
(
info
,
isRunning
string
,
wsMsg
websocket
.
Message
),
req
serverDomain
.
WsReq
,
msg
websocket
.
Message
)
(
report
commDomain
.
ZtfReport
,
pathMaxWidth
int
,
err
error
)
{
cases
:=
zentaoUtils
.
GetCasesByTask
(
stringUtils
.
ParseInt
(
req
.
ProductId
),
stringUtils
.
ParseInt
(
req
.
TaskId
),
req
.
ProjectPath
)
cases
,
err
:=
zentaoUtils
.
GetCasesByTask
(
stringUtils
.
ParseInt
(
req
.
ProductId
),
stringUtils
.
ParseInt
(
req
.
TaskId
),
req
.
ProjectPath
)
if
err
!=
nil
{
return
}
if
req
.
Seq
!=
""
{
cases
=
analysisUtils
.
FilterCaseByResult
(
cases
,
req
)
...
...
internal/comm/helper/zentao/bug.go
浏览文件 @
52ff43ff
...
...
@@ -42,20 +42,20 @@ func CommitBug(ztfBug commDomain.ZtfBug, projectPath string) (err error) {
bug
:=
commDomain
.
ZentaoBug
{}
copier
.
Copy
(
&
bug
,
ztfBug
)
ret
,
ok
:
=
httpUtils
.
Post
(
url
,
bug
,
true
)
_
,
err
=
httpUtils
.
Post
(
url
,
bug
,
true
)
msg
:=
""
if
ok
{
if
err
==
nil
{
msg
=
i118Utils
.
Sprintf
(
"success_to_report_bug"
,
ztfBug
.
Case
)
}
else
{
msg
=
color
.
RedString
(
string
(
ret
))
msg
=
color
.
RedString
(
err
.
Error
(
))
}
if
commConsts
.
ComeFrom
==
"cmd"
{
msgView
,
_
:=
commConsts
.
Cui
.
View
(
"reportBugMsg"
)
msgView
.
Clear
()
if
ok
{
if
err
==
nil
{
color
.
New
(
color
.
FgGreen
)
.
Fprintf
(
msgView
,
msg
)
commConsts
.
Cui
.
DeleteView
(
"submitInput"
)
...
...
@@ -140,8 +140,8 @@ func GetBugFiledOptions(req commDomain.FuncResult, projectPath string) (
// field options
config
:=
configUtils
.
LoadByProjectPath
(
projectPath
)
ok
:
=
Login
(
config
)
if
!
ok
{
err
=
Login
(
config
)
if
err
!=
nil
{
return
}
...
...
@@ -154,8 +154,8 @@ func GetBugFiledOptions(req commDomain.FuncResult, projectPath string) (
}
url
:=
config
.
Url
+
GenApiUri
(
"bug"
,
"ajaxGetBugFieldOptions"
,
params
)
bytes
,
ok
:=
httpUtils
.
Get
(
url
)
if
ok
{
bytes
,
err
:=
httpUtils
.
Get
(
url
)
if
err
==
nil
{
jsonData
:=
&
simplejson
.
Json
{}
jsonData
,
err
=
simplejson
.
NewJson
(
bytes
)
...
...
internal/comm/helper/zentao/case.go
浏览文件 @
52ff43ff
...
...
@@ -18,10 +18,10 @@ import (
"strings"
)
func
GetCasesByModule
(
productId
int
,
moduleId
int
,
projectPath
string
)
(
cases
[]
string
)
{
func
GetCasesByModule
(
productId
int
,
moduleId
int
,
projectPath
string
)
(
cases
[]
string
,
err
error
)
{
config
:=
configUtils
.
LoadByProjectPath
(
projectPath
)
ok
:
=
Login
(
config
)
if
!
ok
{
err
=
Login
(
config
)
if
err
!=
nil
{
return
}
...
...
@@ -39,10 +39,10 @@ func GetCasesByModule(productId int, moduleId int, projectPath string) (cases []
return
}
func
GetCasesBySuite
(
productId
int
,
suiteId
int
,
projectPath
string
)
(
cases
[]
string
)
{
func
GetCasesBySuite
(
productId
int
,
suiteId
int
,
projectPath
string
)
(
cases
[]
string
,
err
error
)
{
config
:=
configUtils
.
LoadByProjectPath
(
projectPath
)
ok
:
=
Login
(
config
)
if
!
ok
{
err
=
Login
(
config
)
if
err
!=
nil
{
return
}
...
...
@@ -60,10 +60,10 @@ func GetCasesBySuite(productId int, suiteId int, projectPath string) (cases []st
return
}
func
GetCasesByTask
(
productId
int
,
taskId
int
,
projectPath
string
)
(
cases
[]
string
)
{
func
GetCasesByTask
(
productId
int
,
taskId
int
,
projectPath
string
)
(
cases
[]
string
,
err
error
)
{
config
:=
configUtils
.
LoadByProjectPath
(
projectPath
)
ok
:
=
Login
(
config
)
if
!
ok
{
err
=
Login
(
config
)
if
err
!=
nil
{
return
}
...
...
@@ -93,9 +93,9 @@ func ListCaseByProduct(baseUrl string, productId int) []commDomain.ZtfCase {
}
url
:=
baseUrl
+
GenApiUri
(
"testcase"
,
"browse"
,
params
)
dataStr
,
ok
:=
httpUtils
.
Get
(
url
)
dataStr
,
err
:=
httpUtils
.
Get
(
url
)
if
ok
{
if
err
==
nil
{
var
product
commDomain
.
ZtfProduct
json
.
Unmarshal
(
dataStr
,
&
product
)
...
...
@@ -127,9 +127,9 @@ func ListCaseByModule(baseUrl string, productId, moduleId int) []commDomain.ZtfC
}
url
:=
baseUrl
+
GenApiUri
(
"testcase"
,
"browse"
,
params
)
bytes
,
ok
:=
httpUtils
.
Get
(
url
)
bytes
,
err
:=
httpUtils
.
Get
(
url
)
if
ok
{
if
err
==
nil
{
var
module
commDomain
.
ZtfModule
json
.
Unmarshal
(
bytes
,
&
module
)
...
...
@@ -161,9 +161,9 @@ func ListCaseBySuite(baseUrl string, productId, suiteId int) []commDomain.ZtfCas
}
url
:=
baseUrl
+
GenApiUri
(
"testsuite"
,
"view"
,
params
)
bytes
,
ok
:=
httpUtils
.
Get
(
url
)
bytes
,
err
:=
httpUtils
.
Get
(
url
)
if
ok
{
if
err
==
nil
{
var
suite
commDomain
.
ZtfSuite
json
.
Unmarshal
(
bytes
,
&
suite
)
...
...
@@ -196,9 +196,9 @@ func ListCaseByTask(baseUrl string, productId, taskId int) []commDomain.ZtfCase
}
url
:=
baseUrl
+
GenApiUri
(
"testtask"
,
"cases"
,
params
)
bytes
,
ok
:=
httpUtils
.
Get
(
url
)
bytes
,
err
:=
httpUtils
.
Get
(
url
)
if
ok
{
if
err
==
nil
{
var
task
commDomain
.
ZtfTask
json
.
Unmarshal
(
bytes
,
&
task
)
...
...
@@ -246,9 +246,9 @@ func GetCaseById(baseUrl string, caseId string) commDomain.ZtfCase {
}
url
:=
baseUrl
+
GenApiUri
(
"testcase"
,
"view"
,
params
)
bytes
,
ok
:=
httpUtils
.
Get
(
url
)
bytes
,
err
:=
httpUtils
.
Get
(
url
)
if
ok
{
if
err
==
nil
{
var
csw
commDomain
.
ZtfCaseWrapper
json
.
Unmarshal
(
bytes
,
&
csw
)
...
...
@@ -260,11 +260,11 @@ func GetCaseById(baseUrl string, caseId string) commDomain.ZtfCase {
}
func
CommitCase
(
caseId
int
,
title
string
,
stepMap
maps
.
Map
,
stepTypeMap
maps
.
Map
,
expectMap
maps
.
Map
,
projectPath
string
)
{
stepMap
maps
.
Map
,
stepTypeMap
maps
.
Map
,
expectMap
maps
.
Map
,
projectPath
string
)
(
err
error
)
{
config
:=
configUtils
.
LoadByProjectPath
(
projectPath
)
ok
:
=
Login
(
config
)
if
!
ok
{
err
=
Login
(
config
)
if
err
!=
nil
{
return
}
...
...
@@ -283,7 +283,10 @@ func CommitCase(caseId int, title string,
"stepType"
:
commonUtils
.
LinkedMapToMap
(
stepTypeMap
),
"expects"
:
commonUtils
.
LinkedMapToMap
(
expectMap
)}
json
,
_
:=
json
.
Marshal
(
requestObj
)
json
,
err
:=
json
.
Marshal
(
requestObj
)
if
err
!=
nil
{
return
}
if
commConsts
.
Verbose
{
logUtils
.
Infof
(
string
(
json
))
...
...
@@ -296,11 +299,13 @@ func CommitCase(caseId int, title string,
}
if
yes
{
_
,
ok
=
httpUtils
.
Post
(
url
,
requestObj
,
true
)
if
ok
{
_
,
err
=
httpUtils
.
Post
(
url
,
requestObj
,
true
)
if
err
==
nil
{
logUtils
.
Infof
(
i118Utils
.
Sprintf
(
"success_to_commit_case"
,
caseId
)
+
"
\n
"
)
}
}
return
}
func
fieldMapToListOrderByInt
(
mp
map
[
string
]
interface
{})
[]
commDomain
.
BugOption
{
...
...
internal/comm/helper/zentao/result.go
浏览文件 @
52ff43ff
package
zentaoUtils
import
(
"errors"
commConsts
"github.com/aaronchen2k/deeptest/internal/comm/consts"
commDomain
"github.com/aaronchen2k/deeptest/internal/comm/domain"
configUtils
"github.com/aaronchen2k/deeptest/internal/comm/helper/config"
...
...
@@ -29,13 +30,14 @@ func CommitResult(report commDomain.ZtfReport, productId, taskId string, project
Login
(
config
)
url
:=
config
.
Url
+
GenApiUri
(
"ci"
,
"commitResult"
,
""
)
ret
,
ok
:=
httpUtils
.
Post
(
url
,
report
,
false
)
ret
,
err
:=
httpUtils
.
Post
(
url
,
report
,
false
)
msg
:=
""
if
ok
{
if
err
==
nil
{
msg
=
color
.
GreenString
(
i118Utils
.
Sprintf
(
"success_to_submit_test_result"
))
}
else
{
msg
=
color
.
RedString
(
string
(
ret
))
err
=
errors
.
New
(
string
(
ret
))
}
logUtils
.
Info
(
msg
)
...
...
internal/comm/helper/zentao/zentao.go
浏览文件 @
52ff43ff
...
...
@@ -16,11 +16,11 @@ import (
"strings"
)
func
Login
(
config
commDomain
.
ProjectConf
)
bool
{
ok
:
=
GetConfig
(
config
.
Url
)
if
!
ok
{
func
Login
(
config
commDomain
.
ProjectConf
)
(
err
error
)
{
err
=
GetConfig
(
config
.
Url
)
if
err
!=
nil
{
logUtils
.
Infof
(
i118Utils
.
Sprintf
(
"fail_to_login"
))
return
false
return
}
uri
:=
""
...
...
@@ -36,12 +36,12 @@ func Login(config commDomain.ProjectConf) bool {
params
[
"password"
]
=
config
.
Password
var
bodyBytes
[]
byte
bodyBytes
,
ok
=
httpUtils
.
PostStr
(
url
,
params
)
if
!
ok
||
(
ok
&&
strings
.
Index
(
string
(
bodyBytes
),
"title"
)
>
0
)
{
// use PostObject to login again for new system
_
,
ok
=
httpUtils
.
Post
(
url
,
params
,
true
)
bodyBytes
,
err
=
httpUtils
.
PostStr
(
url
,
params
)
if
err
!=
nil
||
(
err
==
nil
&&
strings
.
Index
(
string
(
bodyBytes
),
"title"
)
>
0
)
{
// use PostObject to login again for new system
_
,
err
=
httpUtils
.
Post
(
url
,
params
,
true
)
}
if
ok
{
if
err
==
nil
{
if
commConsts
.
Verbose
{
logUtils
.
Info
(
i118Utils
.
Sprintf
(
"success_to_login"
))
}
...
...
@@ -49,18 +49,18 @@ func Login(config commDomain.ProjectConf) bool {
logUtils
.
Errorf
(
i118Utils
.
Sprintf
(
"fail_to_login"
))
}
return
ok
return
}
func
GetConfig
(
baseUrl
string
)
bool
{
func
GetConfig
(
baseUrl
string
)
(
err
error
)
{
//if commConsts.RequestType != "" {
// return true
//}
url
:=
baseUrl
+
"?mode=getconfig"
bytes
,
ok
:=
httpUtils
.
Get
(
url
)
if
!
ok
{
return
false
bytes
,
err
:=
httpUtils
.
Get
(
url
)
if
err
!=
nil
{
return
}
json
,
_
:=
simplejson
.
NewJson
(
bytes
)
...
...
@@ -79,12 +79,12 @@ func GetConfig(baseUrl string) bool {
uri
=
"index.php?m=user&f=login&t=json"
}
url
=
baseUrl
+
uri
bytes
,
ok
=
httpUtils
.
Get
(
url
)
if
!
ok
{
return
false
bytes
,
err
=
httpUtils
.
Get
(
url
)
if
err
!=
nil
{
return
}
return
true
return
}
func
ListLang
()
(
langs
[]
serverDomain
.
ZentaoLang
,
err
error
)
{
...
...
@@ -102,7 +102,10 @@ func ListProduct(projectPath string) (products []serverDomain.ZentaoProduct, err
return
}
Login
(
config
)
err
=
Login
(
config
)
if
err
!=
nil
{
return
}
// $productID = 0, $branch = 0, $browseType = '', $param = 0, $storyType = 'story',
// $orderBy = '', $recTotal = 0, $recPerPage = 20, $pageID = 1, $projectID = 0)
...
...
@@ -114,15 +117,15 @@ func ListProduct(projectPath string) (products []serverDomain.ZentaoProduct, err
}
url
:=
config
.
Url
+
GenApiUri
(
"product"
,
"browse"
,
params
)
bytes
,
ok
:=
httpUtils
.
Get
(
url
)
bytes
,
err
:=
httpUtils
.
Get
(
url
)
if
!
ok
{
if
err
!=
nil
{
err
=
errors
.
New
(
"请检查项目配置"
)
return
}
jsn
,
_
:=
simplejson
.
NewJson
(
bytes
)
productMap
,
_
:=
jsn
.
Get
(
"products"
)
.
Map
()
productMap
,
err
:=
jsn
.
Get
(
"products"
)
.
Map
()
for
key
,
val
:=
range
productMap
{
id
,
_
:=
strconv
.
Atoi
(
key
)
...
...
@@ -134,9 +137,12 @@ func ListProduct(projectPath string) (products []serverDomain.ZentaoProduct, err
func
ListModuleByProduct
(
productId
int
,
projectPath
string
)
(
modules
[]
serverDomain
.
ZentaoModule
,
err
error
)
{
config
:=
configUtils
.
LoadByProjectPath
(
projectPath
)
Login
(
config
)
// tree-browse-1-story.html#app=product
err
=
Login
(
config
)
if
err
!=
nil
{
return
}
// tree-browse-1-story.html#app=product
params
:=
""
if
commConsts
.
RequestType
==
commConsts
.
PathInfo
{
params
=
fmt
.
Sprintf
(
"%d-story"
,
productId
)
...
...
@@ -147,9 +153,8 @@ func ListModuleByProduct(productId int, projectPath string) (modules []serverDom
url
:=
config
.
Url
+
GenApiUri
(
"tree"
,
"browse"
,
params
)
url
+=
"#app=product"
bytes
,
ok
:=
httpUtils
.
Get
(
url
)
if
!
ok
{
err
=
errors
.
New
(
"tree-browse-story fail"
)
bytes
,
err
:=
httpUtils
.
Get
(
url
)
if
err
!=
nil
{
return
}
...
...
@@ -166,7 +171,10 @@ func ListModuleByProduct(productId int, projectPath string) (modules []serverDom
func
ListModuleForCase
(
productId
int
,
projectPath
string
)
(
modules
[]
serverDomain
.
ZentaoModule
,
err
error
)
{
config
:=
configUtils
.
LoadByProjectPath
(
projectPath
)
Login
(
config
)
err
=
Login
(
config
)
if
err
!=
nil
{
return
}
// tree-browse-1-case-0-0-qa.html
params
:=
""
...
...
@@ -179,9 +187,8 @@ func ListModuleForCase(productId int, projectPath string) (modules []serverDomai
url
:=
config
.
Url
+
GenApiUri
(
"tree"
,
"browse"
,
params
)
url
+=
"#app=product"
bytes
,
ok
:=
httpUtils
.
Get
(
url
)
if
!
ok
{
err
=
errors
.
New
(
"tree-browse-story fail"
)
bytes
,
err
:=
httpUtils
.
Get
(
url
)
if
err
!=
nil
{
return
}
...
...
@@ -218,7 +225,10 @@ func GenModuleData(mp map[string]interface{}, modules *[]serverDomain.ZentaoModu
func
ListSuiteByProduct
(
productId
int
,
projectPath
string
)
(
suites
[]
serverDomain
.
ZentaoSuite
,
err
error
)
{
config
:=
configUtils
.
LoadByProjectPath
(
projectPath
)
Login
(
config
)
err
=
Login
(
config
)
if
err
!=
nil
{
return
}
// $productID = 0, $orderBy = 'id_asc', $recTotal = 0, $recPerPage = 20, $pageID = 1
params
:=
""
...
...
@@ -230,8 +240,8 @@ func ListSuiteByProduct(productId int, projectPath string) (suites []serverDomai
url
:=
config
.
Url
+
GenApiUri
(
"testsuite"
,
"browse"
,
params
)
bytes
,
ok
:=
httpUtils
.
Get
(
url
)
if
!
ok
{
bytes
,
err
:=
httpUtils
.
Get
(
url
)
if
err
!=
nil
{
err
=
errors
.
New
(
"testsuite-browse fail"
)
return
}
...
...
@@ -253,7 +263,10 @@ func ListSuiteByProduct(productId int, projectPath string) (suites []serverDomai
func
ListTaskByProduct
(
productId
int
,
projectPath
string
)
(
tasks
[]
serverDomain
.
ZentaoTask
,
err
error
)
{
config
:=
configUtils
.
LoadByProjectPath
(
projectPath
)
Login
(
config
)
err
=
Login
(
config
)
if
err
!=
nil
{
return
}
// $productID = 0, $branch = '', $type = 'local,totalStatus', $orderBy = 'id_asc', $recTotal = 0, $recPerPage = 20, $pageID = 1, $beginTime = 0, $endTime = 0)
params
:=
""
...
...
@@ -264,9 +277,9 @@ func ListTaskByProduct(productId int, projectPath string) (tasks []serverDomain.
}
url
:=
config
.
Url
+
GenApiUri
(
"testtask"
,
"browse"
,
params
)
bytes
,
ok
:=
httpUtils
.
Get
(
url
)
bytes
,
err
:=
httpUtils
.
Get
(
url
)
if
!
ok
{
if
err
!=
nil
{
err
=
errors
.
New
(
"testsuite-browse fail"
)
return
}
...
...
internal/pkg/lib/http/http.go
浏览文件 @
52ff43ff
...
...
@@ -2,6 +2,7 @@ package httpUtils
import
(
"encoding/json"
"errors"
"fmt"
commConsts
"github.com/aaronchen2k/deeptest/internal/comm/consts"
i118Utils
"github.com/aaronchen2k/deeptest/internal/pkg/lib/i118"
...
...
@@ -15,7 +16,7 @@ import (
"strings"
)
func
Get
(
url
string
)
(
ret
[]
byte
,
ok
bool
)
{
func
Get
(
url
string
)
(
ret
[]
byte
,
err
error
)
{
if
strings
.
Index
(
url
,
"mode=getconfig"
)
<
0
{
url
=
AddToken
(
url
)
}
...
...
@@ -25,17 +26,15 @@ func Get(url string) (ret []byte, ok bool) {
client
:=
&
http
.
Client
{}
req
,
reqErr
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
if
reqErr
!=
nil
{
logUtils
.
Error
(
reqErr
.
Error
())
ok
=
false
req
,
err
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
if
err
!=
nil
{
logUtils
.
Error
(
err
.
Error
())
return
}
resp
,
respErr
:=
client
.
Do
(
req
)
if
respErr
!=
nil
{
logUtils
.
Error
(
respErr
.
Error
())
ok
=
false
resp
,
err
:=
client
.
Do
(
req
)
if
err
!=
nil
{
logUtils
.
Error
(
err
.
Error
())
return
}
...
...
@@ -47,8 +46,8 @@ func Get(url string) (ret []byte, ok bool) {
defer
resp
.
Body
.
Close
()
var
zentaoResp
serverDomain
.
ZentaoResp
jsonErr
:
=
json
.
Unmarshal
(
bodyBytes
,
&
zentaoResp
)
if
jsonE
rr
!=
nil
{
err
=
json
.
Unmarshal
(
bodyBytes
,
&
zentaoResp
)
if
e
rr
!=
nil
{
if
strings
.
Index
(
string
(
bodyBytes
),
"<html>"
)
>
-
1
{
if
commConsts
.
Verbose
{
logUtils
.
Errorf
(
i118Utils
.
Sprintf
(
"request_response"
)
+
" HTML - "
+
gohtml
.
FormatWithLineNo
(
string
(
bodyBytes
)))
...
...
@@ -56,7 +55,7 @@ func Get(url string) (ret []byte, ok bool) {
return
}
else
{
if
commConsts
.
Verbose
{
logUtils
.
Infof
(
jsonE
rr
.
Error
())
logUtils
.
Infof
(
e
rr
.
Error
())
}
return
}
...
...
@@ -67,16 +66,17 @@ func Get(url string) (ret []byte, ok bool) {
status
:=
zentaoResp
.
Status
if
status
==
""
{
// 非嵌套结构
ret
=
bodyBytes
ok
=
true
}
else
{
// 嵌套结构
ret
=
[]
byte
(
zentaoResp
.
Data
)
ok
=
status
==
"success"
if
status
!=
"success"
{
err
=
errors
.
New
(
zentaoResp
.
Data
)
}
}
return
}
func
Post
(
url
string
,
data
interface
{},
useFormFormat
bool
)
(
ret
[]
byte
,
ok
bool
)
{
func
Post
(
url
string
,
data
interface
{},
useFormFormat
bool
)
(
ret
[]
byte
,
err
error
)
{
url
=
AddToken
(
url
)
if
commConsts
.
Verbose
{
...
...
@@ -103,24 +103,24 @@ func Post(url string, data interface{}, useFormFormat bool) (ret []byte, ok bool
logUtils
.
Infof
(
dataStr
)
}
req
,
reqE
rr
:=
http
.
NewRequest
(
"POST"
,
url
,
strings
.
NewReader
(
dataStr
))
if
reqE
rr
!=
nil
{
logUtils
.
Error
(
reqE
rr
.
Error
())
req
,
e
rr
:=
http
.
NewRequest
(
"POST"
,
url
,
strings
.
NewReader
(
dataStr
))
if
e
rr
!=
nil
{
logUtils
.
Error
(
e
rr
.
Error
())
return
}
//req.Header.Set("Content-Type", "application/json")
req
.
Header
.
Set
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
resp
,
respE
rr
:=
client
.
Do
(
req
)
if
respE
rr
!=
nil
{
logUtils
.
Error
(
respE
rr
.
Error
())
resp
,
e
rr
:=
client
.
Do
(
req
)
if
e
rr
!=
nil
{
logUtils
.
Error
(
e
rr
.
Error
())
return
}
bodyBytes
,
ioE
rr
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
ioE
rr
!=
nil
{
logUtils
.
Error
(
ioE
rr
.
Error
())
bodyBytes
,
e
rr
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
e
rr
!=
nil
{
logUtils
.
Error
(
e
rr
.
Error
())
return
}
...
...
@@ -131,12 +131,12 @@ func Post(url string, data interface{}, useFormFormat bool) (ret []byte, ok bool
defer
resp
.
Body
.
Close
()
ret
,
ok
=
GetRespErr
(
bodyBytes
,
url
)
ret
,
err
=
GetRespErr
(
bodyBytes
,
url
)
return
}
func
PostStr
(
url
string
,
params
map
[
string
]
string
)
(
ret
[]
byte
,
ok
bool
)
{
func
PostStr
(
url
string
,
params
map
[
string
]
string
)
(
ret
[]
byte
,
err
error
)
{
url
=
AddToken
(
url
)
if
commConsts
.
Verbose
{
...
...
@@ -159,24 +159,22 @@ func PostStr(url string, params map[string]string) (ret []byte, ok bool) {
logUtils
.
Infof
(
paramStr
)
}
req
,
reqE
rr
:=
http
.
NewRequest
(
"POST"
,
url
,
strings
.
NewReader
(
paramStr
))
if
reqE
rr
!=
nil
{
req
,
e
rr
:=
http
.
NewRequest
(
"POST"
,
url
,
strings
.
NewReader
(
paramStr
))
if
e
rr
!=
nil
{
if
commConsts
.
Verbose
{
logUtils
.
Infof
(
reqE
rr
.
Error
())
logUtils
.
Infof
(
e
rr
.
Error
())
}
ok
=
false
return
}
req
.
Header
.
Set
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
req
.
Header
.
Set
(
"cookie"
,
commConsts
.
SessionVar
+
"="
+
commConsts
.
SessionId
)
resp
,
respE
rr
:=
client
.
Do
(
req
)
if
respE
rr
!=
nil
{
resp
,
e
rr
:=
client
.
Do
(
req
)
if
e
rr
!=
nil
{
if
commConsts
.
Verbose
{
logUtils
.
Infof
(
respE
rr
.
Error
())
logUtils
.
Infof
(
e
rr
.
Error
())
}
ok
=
false
return
}
...
...
@@ -235,7 +233,7 @@ func AddToken(url string) (ret string) {
return
}
func
GetRespErr
(
bytes
[]
byte
,
url
string
)
(
ret
[]
byte
,
ok
bool
)
{
func
GetRespErr
(
bytes
[]
byte
,
url
string
)
(
ret
[]
byte
,
err
error
)
{
ret
=
bytes
if
len
(
bytes
)
==
0
{
...
...
@@ -243,14 +241,13 @@ func GetRespErr(bytes []byte, url string) (ret []byte, ok bool) {
}
var
zentaoResp
serverDomain
.
ZentaoResp
jsonErr
:
=
json
.
Unmarshal
(
bytes
,
&
zentaoResp
)
if
jsonE
rr
!=
nil
{
err
=
json
.
Unmarshal
(
bytes
,
&
zentaoResp
)
if
e
rr
!=
nil
{
if
commConsts
.
Verbose
{
if
strings
.
Index
(
url
,
"login"
)
<
0
{
// jsonErr caused by login request return a html
logUtils
.
Infof
(
jsonE
rr
.
Error
())
logUtils
.
Infof
(
e
rr
.
Error
())
}
}
ok
=
false
return
}
...
...
@@ -258,18 +255,18 @@ func GetRespErr(bytes []byte, url string) (ret []byte, ok bool) {
status
:=
zentaoResp
.
Status
if
status
!=
""
{
ret
=
[]
byte
(
zentaoResp
.
Data
)
ok
=
status
==
"success"
if
status
==
"success"
{
err
=
errors
.
New
(
zentaoResp
.
Data
)
}
return
}
// 非嵌套结构,map[result:success]
var
respData
=
serverDomain
.
ZentaoRespData
{}
err
:
=
json
.
Unmarshal
(
bytes
,
&
respData
)
err
=
json
.
Unmarshal
(
bytes
,
&
respData
)
if
err
==
nil
&&
(
respData
.
Result
!=
""
&&
respData
.
Result
!=
"success"
)
{
ok
=
false
}
else
{
ok
=
true
err
=
errors
.
New
(
string
(
bytes
))
}
return
...
...
internal/server/modules/v1/service/test-case.go
浏览文件 @
52ff43ff
...
...
@@ -18,8 +18,8 @@ func (s *TestCaseService) LoadTestCases(productId, moduleId, suiteId, taskId int
config
:=
configUtils
.
LoadByProjectPath
(
projectPath
)
ok
:=
zentaoUtils
.
Login
(
config
)
if
!
ok
{
err
:=
zentaoUtils
.
Login
(
config
)
if
err
!=
nil
{
loginFail
=
true
return
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录