Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zentaoatf
提交
83816d47
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 搜索 >>
提交
83816d47
编写于
8月 15, 2019
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
success to submit bug
上级
6f14e2fe
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
96 addition
and
40 deletion
+96
-40
src/model/test.go
src/model/test.go
+1
-0
src/service/client/http.go
src/service/client/http.go
+5
-6
src/service/testing/check.go
src/service/testing/check.go
+2
-2
src/service/zentao/bug.go
src/service/zentao/bug.go
+36
-25
src/service/zentao/result.go
src/service/zentao/result.go
+3
-1
src/test/submitResult.go
src/test/submitResult.go
+1
-1
src/utils/print/print.go
src/utils/print/print.go
+12
-0
src/utils/string/string.go
src/utils/string/string.go
+24
-0
src/utils/zentao/zentao.go
src/utils/zentao/zentao.go
+12
-5
未找到文件。
src/model/test.go
浏览文件 @
83816d47
...
...
@@ -68,6 +68,7 @@ type CaseLog struct {
ZentaoResultId
int
Path
string
Status
string
Title
string
Steps
[]
StepLog
}
...
...
src/service/client/http.go
浏览文件 @
83816d47
...
...
@@ -39,7 +39,7 @@ func Get(url string, params map[string]string) (string, bool) {
}
bodyStr
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
print
ln
(
string
(
bodyStr
)
)
print
Utils
.
PrintUnicode
(
bodyStr
)
var
bodyJson
model
.
ZentaoResponse
json
.
Unmarshal
(
bodyStr
,
&
bodyJson
)
...
...
@@ -55,19 +55,18 @@ func Get(url string, params map[string]string) (string, bool) {
}
}
func
Post
Json
(
url
string
,
params
interface
{})
(
string
,
bool
)
{
func
Post
Object
(
url
string
,
params
interface
{})
(
string
,
bool
)
{
client
:=
&
http
.
Client
{}
reqStr
,
_
:=
json
.
Marshal
(
params
)
printUtils
.
PrintToCmd
(
string
(
reqStr
))
val
,
_
:=
form
.
EncodeToValues
(
params
)
fmt
.
Printf
(
"%s
\n
"
,
val
.
Encode
())
//str := "case=1&reals[12]=N%2FA&reals[9]=N%2FA&steps[12]=pass&steps[9]=pass&version=0"
re3
,
_
:=
regexp
.
Compile
(
"
\\
.(.*?)="
)
data
:=
re3
.
ReplaceAllStringFunc
(
val
.
Encode
(),
replacePostData
)
fmt
.
Printf
(
"%s
\n
"
,
data
)
req
,
err
:=
http
.
NewRequest
(
"POST"
,
url
,
strings
.
NewReader
(
data
))
if
err
!=
nil
{
...
...
@@ -83,7 +82,7 @@ func PostJson(url string, params interface{}) (string, bool) {
}
bodyStr
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
print
ln
(
string
(
bodyStr
)
)
print
Utils
.
PrintUnicode
(
bodyStr
)
var
bodyJson
model
.
ZentaoResponse
json
.
Unmarshal
(
bodyStr
,
&
bodyJson
)
...
...
@@ -126,7 +125,7 @@ func PostStr(url string, params map[string]string) (string, bool) {
}
bodyStr
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
print
ln
(
string
(
bodyStr
)
)
print
Utils
.
PrintUnicode
(
bodyStr
)
var
bodyJson
model
.
ZentaoResponse
json
.
Unmarshal
(
bodyStr
,
&
bodyJson
)
...
...
src/service/testing/check.go
浏览文件 @
83816d47
...
...
@@ -31,7 +31,7 @@ func CheckResults(files []string, dir string, langType string, report *model.Tes
func
ValidateTestCase
(
scriptFile
string
,
langType
string
,
checkpointStepArr
[]
string
,
expectArr
[][]
string
,
skip
bool
,
actualArr
[][]
string
,
report
*
model
.
TestReport
)
{
caseId
,
caseIdInTask
,
taskId
:=
zentaoUtils
.
GetCaseIds
(
scriptFile
)
caseId
,
caseIdInTask
,
taskId
,
title
:=
zentaoUtils
.
GetCaseIds
(
scriptFile
)
stepLogs
:=
make
([]
model
.
StepLog
,
0
)
caseResult
:=
constant
.
PASS
.
String
()
...
...
@@ -78,7 +78,7 @@ func ValidateTestCase(scriptFile string, langType string,
}
report
.
Total
=
report
.
Total
+
1
cs
:=
model
.
CaseLog
{
Id
:
caseId
,
IdInTask
:
caseIdInTask
,
TaskId
:
taskId
,
cs
:=
model
.
CaseLog
{
Id
:
caseId
,
IdInTask
:
caseIdInTask
,
TaskId
:
taskId
,
Title
:
title
,
Path
:
scriptFile
,
Status
:
caseResult
,
Steps
:
stepLogs
}
report
.
Cases
=
append
(
report
.
Cases
,
cs
)
}
...
...
src/service/zentao/bug.go
浏览文件 @
83816d47
...
...
@@ -6,9 +6,11 @@ import (
"github.com/easysoft/zentaoatf/src/service/client"
testingService
"github.com/easysoft/zentaoatf/src/service/testing"
configUtils
"github.com/easysoft/zentaoatf/src/utils/config"
constant
"github.com/easysoft/zentaoatf/src/utils/const"
printUtils
"github.com/easysoft/zentaoatf/src/utils/print"
stringUtils
"github.com/easysoft/zentaoatf/src/utils/string"
uuid
"github.com/satori/go.uuid"
"strconv"
"strings"
)
func
SubmitBug
(
assert
string
,
date
string
,
caseId
int
,
caseIdInTask
int
)
{
...
...
@@ -17,11 +19,12 @@ func SubmitBug(assert string, date string, caseId int, caseIdInTask int) {
projectId
:=
conf
.
ProjectId
report
:=
testingService
.
GetTestTestReportForSubmit
(
assert
,
date
)
for
idx
,
cs
:=
range
report
.
Cases
{
for
_
,
cs
:=
range
report
.
Cases
{
id
:=
cs
.
Id
idInTask
:=
cs
.
IdInTask
taskId
:=
cs
.
TaskId
zentaoResultId
:=
cs
.
ZentaoResultId
title
:=
cs
.
Title
if
caseId
!=
id
||
caseIdInTask
!=
idInTask
{
continue
...
...
@@ -29,32 +32,45 @@ func SubmitBug(assert string, date string, caseId int, caseIdInTask int) {
// bug-create-1-0-caseID=1,version=3,resultID=93,runID=0,stepIdList=9_12_.html
// bug-create-1-0-caseID=1,version=3,resultID=84,runID=6,stepIdList=9_12_,testtask=2,projectID=1,buildID=1.html
stepList
:=
""
requestObj
:=
map
[
string
]
string
{
"case"
:
strconv
.
Itoa
(
id
),
"version"
:
"0"
}
stepIds
:=
""
requestObj
:=
map
[
string
]
interface
{}{
"module"
:
"0"
,
"uid"
:
uuid
.
NewV4
()
.
String
(),
"caseVersion"
:
"0"
,
"oldTaskID"
:
"0"
,
"product"
:
productId
,
"project"
:
projectId
,
"case"
:
cs
.
Id
,
"result"
:
cs
.
ZentaoResultId
,
"testtask"
:
taskId
,
"title"
:
title
,
}
version
:=
map
[
string
]
interface
{}{
"0"
:
"trunk"
}
requestObj
[
"openedBuild"
]
=
version
for
_
,
step
:=
range
cs
.
Steps
{
if
!
step
.
Status
{
step
List
+=
strconv
.
Itoa
(
step
.
Id
)
+
"_"
step
Ids
+=
strconv
.
Itoa
(
step
.
Id
)
+
"_"
}
var
stepStatus
string
if
step
.
Status
{
stepStatus
=
constant
.
PASS
.
String
()
}
else
{
stepStatus
=
constant
.
FAIL
.
String
()
}
stepStatus
:=
stringUtils
.
BoolToPass
(
step
.
Status
)
stepResults
:=
""
stepTxt
:=
fmt
.
Sprintf
(
"<p><b>%s: %s</b></p>"
,
step
.
Name
,
stepStatus
)
stepResults
:=
make
([]
string
,
0
)
for
_
,
checkpoint
:=
range
step
.
CheckPoints
{
stepResults
+=
checkpoint
.
Actual
// strconv.FormatBool(checkpoint.Status) + ": " + checkpoint.Actual
}
checkpointStatus
:=
stringUtils
.
BoolToPass
(
checkpoint
.
Status
)
requestObj
[
"steps["
+
strconv
.
Itoa
(
step
.
Id
)
+
"]"
]
=
stepStatus
requestObj
[
"reals["
+
strconv
.
Itoa
(
step
.
Id
)
+
"]"
]
=
stepResults
text
:=
fmt
.
Sprintf
(
"<p> Checkpoint: %s</p>"
+
"<p> Expect</p>"
+
" %s"
+
"<p> Actual<p/>"
+
" %s"
,
checkpointStatus
,
checkpoint
.
Expect
,
checkpoint
.
Actual
)
stepResults
=
append
(
stepResults
,
text
)
}
requestObj
[
"steps"
]
=
stepTxt
+
strings
.
Join
(
stepResults
,
"<br/>"
)
}
params
:=
fmt
.
Sprintf
(
"caseID=%d,version=0,resultID=%d,runID=%d,stepIdList=%s"
,
id
,
zentaoResultId
,
idInTask
,
step
List
)
id
,
zentaoResultId
,
idInTask
,
step
Ids
)
if
taskId
!=
0
{
temp
:=
fmt
.
Sprintf
(
"testtask=%d,projectID=%d,buildID=1"
,
taskId
,
projectId
)
...
...
@@ -62,21 +78,16 @@ func SubmitBug(assert string, date string, caseId int, caseIdInTask int) {
}
uri
:=
fmt
.
Sprintf
(
"bug-create-%d-0-%s.json"
,
productId
,
params
)
println
(
uri
)
reqStr
,
_
:=
json
.
Marshal
(
requestObj
)
printUtils
.
PrintToCmd
(
string
(
reqStr
))
url
:=
conf
.
Url
+
uri
_
,
ok
:=
client
.
Post
Str
(
url
,
requestObj
)
_
,
ok
:=
client
.
Post
Object
(
url
,
requestObj
)
if
ok
{
resultId
:=
GetLastResult
(
conf
.
Url
,
idInTask
,
id
)
report
.
Cases
[
idx
]
.
ZentaoResultId
=
resultId
json
,
_
:=
json
.
Marshal
(
report
)
testingService
.
SaveTestTestReportAfterSubmit
(
assert
,
date
,
string
(
json
))
printUtils
.
PrintToCmd
(
fmt
.
Sprintf
(
"success to submit
the results for case %d, resultId is %d"
,
id
,
resultId
))
fmt
.
Sprintf
(
"success to submit
a bug for case %d-%d"
,
id
,
idInTask
))
}
}
}
src/service/zentao/result.go
浏览文件 @
83816d47
...
...
@@ -49,7 +49,7 @@ func SubmitResult(assert string, date string) {
}
url
:=
conf
.
Url
+
uri
_
,
ok
:=
client
.
Post
Json
(
url
,
requestObj
)
_
,
ok
:=
client
.
Post
Object
(
url
,
requestObj
)
if
ok
{
resultId
:=
GetLastResult
(
conf
.
Url
,
idInTask
,
id
)
report
.
Cases
[
idx
]
.
ZentaoResultId
=
resultId
...
...
@@ -59,6 +59,8 @@ func SubmitResult(assert string, date string) {
printUtils
.
PrintToCmd
(
fmt
.
Sprintf
(
"success to submit the results for case %d, resultId is %d"
,
id
,
resultId
))
SubmitBug
(
assert
,
date
,
id
,
idInTask
)
}
}
}
...
...
src/test/submitResult.go
浏览文件 @
83816d47
...
...
@@ -6,5 +6,5 @@ import (
func
main
()
{
zentaoService
.
Login
(
"http://ztpmp.ngtesting.org/"
,
"admin"
,
"P2ssw0rd"
)
zentaoService
.
SubmitResult
(
"scripts/all.suite"
,
"2019-08-15T1
0473
5"
)
zentaoService
.
SubmitResult
(
"scripts/all.suite"
,
"2019-08-15T1
7042
5"
)
}
src/utils/print/print.go
浏览文件 @
83816d47
package
printUtils
import
(
"encoding/json"
"flag"
"fmt"
logUtils
"github.com/easysoft/zentaoatf/src/utils/log"
...
...
@@ -79,3 +80,14 @@ func PrintMap(obj map[string]interface{}) {
fmt
.
Printf
(
" %s: %v
\n
"
,
key
,
val
)
}
}
func
PrintUnicode
(
str
[]
byte
)
{
var
a
interface
{}
err
:=
json
.
Unmarshal
(
str
,
&
a
)
if
err
==
nil
{
fmt
.
Println
(
a
)
}
else
{
fmt
.
Println
(
string
(
str
))
}
}
src/utils/string/string.go
浏览文件 @
83816d47
package
stringUtils
import
(
"bytes"
"encoding/binary"
"encoding/hex"
constant
"github.com/easysoft/zentaoatf/src/utils/const"
"os"
"strings"
"unicode"
...
...
@@ -32,3 +36,23 @@ func PathSimple(str string) string {
return
""
}
func
U2s
(
form
string
)
(
to
string
,
err
error
)
{
bs
,
err
:=
hex
.
DecodeString
(
strings
.
Replace
(
form
,
`\u`
,
``
,
-
1
))
if
err
!=
nil
{
return
}
for
i
,
bl
,
br
,
r
:=
0
,
len
(
bs
),
bytes
.
NewReader
(
bs
),
uint16
(
0
);
i
<
bl
;
i
+=
2
{
binary
.
Read
(
br
,
binary
.
BigEndian
,
&
r
)
to
+=
string
(
r
)
}
return
}
func
BoolToPass
(
b
bool
)
string
{
if
b
{
return
constant
.
PASS
.
String
()
}
else
{
return
constant
.
FAIL
.
String
()
}
}
src/utils/zentao/zentao.go
浏览文件 @
83816d47
...
...
@@ -121,32 +121,39 @@ func PathToRunName(filePath string) string {
return
runName
}
func
GetCaseIds
(
file
string
)
(
int
,
int
,
int
)
{
func
GetCaseIds
(
file
string
)
(
int
,
int
,
int
,
string
)
{
content
:=
fileUtils
.
ReadFile
(
file
)
var
caseId
int
var
caseIdInTask
int
var
taskId
int
var
title
string
myExp
:=
regexp
.
MustCompile
(
`[\S\s]*caseId:
([^\n]?)*\n+
`
)
myExp
:=
regexp
.
MustCompile
(
`[\S\s]*caseId:
\s*([^\n]*?)\s*\n
`
)
arr
:=
myExp
.
FindStringSubmatch
(
content
)
if
len
(
arr
)
>
1
{
caseId
,
_
=
strconv
.
Atoi
(
arr
[
1
])
}
myExp
=
regexp
.
MustCompile
(
`[\S\s]*caseIdInTask:
([^\n]?)*\n+
`
)
myExp
=
regexp
.
MustCompile
(
`[\S\s]*caseIdInTask:
\s*([^\n]*?)\s*\n
`
)
arr
=
myExp
.
FindStringSubmatch
(
content
)
if
len
(
arr
)
>
1
{
caseIdInTask
,
_
=
strconv
.
Atoi
(
arr
[
1
])
}
myExp
=
regexp
.
MustCompile
(
`[\S\s]*taskId:
([^\n]?)*\n+
`
)
myExp
=
regexp
.
MustCompile
(
`[\S\s]*taskId:
\s*([^\n]*?)\s*\n
`
)
arr
=
myExp
.
FindStringSubmatch
(
content
)
if
len
(
arr
)
>
1
{
taskId
,
_
=
strconv
.
Atoi
(
arr
[
1
])
}
return
caseId
,
caseIdInTask
,
taskId
myExp
=
regexp
.
MustCompile
(
`[\S\s]*title:\s*([^\n]*?)\s*\n`
)
arr
=
myExp
.
FindStringSubmatch
(
content
)
if
len
(
arr
)
>
1
{
title
=
arr
[
1
]
}
return
caseId
,
caseIdInTask
,
taskId
,
title
}
func
ReadExpect
(
file
string
)
[][]
string
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录