Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zentaoatf
提交
80c2762a
Z
zentaoatf
项目概览
易企天创
/
zentaoatf
11 个月 前同步成功
通知
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 搜索 >>
提交
80c2762a
编写于
7月 25, 2019
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
generate test scripts using json that returned by mock server
上级
6387a04a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
43 deletion
+33
-43
src/action/gen.go
src/action/gen.go
+8
-13
src/cui.go
src/cui.go
+7
-8
src/http/http.go
src/http/http.go
+16
-22
src/utils/constant.go
src/utils/constant.go
+2
-0
未找到文件。
src/action/gen.go
浏览文件 @
80c2762a
package
action
import
(
"encoding/json"
"errors"
"fmt"
httpClient
"github.com/easysoft/zentaoatf/src/http"
...
...
@@ -25,23 +24,19 @@ func Gen(url string, entityType string, entityVal string, langType string, singl
params
[
"taskId"
]
=
entityVal
}
json
Buf
,
err
:=
httpClient
.
GetBuf
(
url
,
params
)
json
,
err
:=
httpClient
.
Get
(
url
,
params
)
if
err
!=
nil
{
Generate
(
json
Buf
,
langType
,
singleFile
)
Generate
(
json
,
langType
,
singleFile
)
}
}
func
Generate
(
jsonBuf
[]
byte
,
langType
string
,
singleFile
bool
)
error
{
var
resp
model
.
Response
json
.
Unmarshal
(
jsonBuf
,
&
resp
)
if
resp
.
Code
!=
1
{
fmt
.
Println
(
string
(
jsonBuf
))
return
errors
.
New
(
"request fail"
)
func
Generate
(
json
model
.
Response
,
langType
string
,
singleFile
bool
)
error
{
if
json
.
Code
!=
1
{
return
errors
.
New
(
"response code = %s"
)
}
for
_
,
testCase
:=
range
resp
.
Cases
{
for
_
,
testCase
:=
range
json
.
Cases
{
DealwithTestCase
(
testCase
,
langType
,
singleFile
)
}
...
...
@@ -68,7 +63,7 @@ func DealwithTestCase(tc model.TestCase, langType string, singleFile bool) {
caseId
:=
tc
.
Id
caseTitle
:=
tc
.
Title
scriptFile
:=
fmt
.
Sprintf
(
"xdoc/scripts/
tc-%s.%s"
,
strconv
.
Itoa
(
caseId
),
LangMap
[
langType
][
"extName"
])
scriptFile
:=
fmt
.
Sprintf
(
utils
.
GenDir
+
"
tc-%s.%s"
,
strconv
.
Itoa
(
caseId
),
LangMap
[
langType
][
"extName"
])
steps
:=
make
([]
string
,
0
)
expects
:=
make
([]
string
,
0
)
...
...
@@ -94,7 +89,7 @@ func DealwithTestCase(tc model.TestCase, langType string, singleFile bool) {
}
else
{
expectFile
:=
utils
.
ScriptToExpectName
(
scriptFile
)
expectsTxt
=
"@file"
expectsTxt
=
"@file
\n
"
utils
.
WriteFile
(
expectFile
,
strings
.
Join
(
expects
,
"
\n
"
))
}
...
...
src/cui.go
浏览文件 @
80c2762a
...
...
@@ -17,7 +17,7 @@ import (
const
(
leftWidth
=
32
labelWidth
=
15
inputFullLineWidth
=
6
4
inputFullLineWidth
=
6
9
inputNumbWidth
=
25
buttonWidth
=
10
space
=
2
...
...
@@ -295,19 +295,18 @@ func importProjectRequest(g *gocui.Gui, v *gocui.View) error {
_
,
_
=
fmt
.
Fprintln
(
cmdView
,
fmt
.
Sprintf
(
"#atf gen -u %s -t %s -v %s -l %s -s %t"
,
url
,
params
[
"entityType"
],
params
[
"entityVal"
],
language
,
singleFile
))
json
Buf
,
e
:=
httpClient
.
GetBuf
(
url
,
params
)
json
,
e
:=
httpClient
.
Get
(
url
,
params
)
if
e
!=
nil
{
fmt
.
Fprint
(
cmdView
,
e
.
Error
())
fmt
.
Fprint
ln
(
cmdView
,
e
.
Error
())
return
nil
}
err
:=
action
.
Generate
(
json
Buf
,
language
,
singleFile
)
err
:=
action
.
Generate
(
json
,
language
,
singleFile
)
if
err
==
nil
{
fmt
.
Fprintln
(
cmdView
,
fmt
.
Sprintf
(
"success to generate test scripts in 'xdoc/scripts' at %s"
,
utils
.
DateTimeStr
(
time
.
Now
())))
fmt
.
Fprintln
(
cmdView
,
fmt
.
Sprintf
(
"success to generate test scripts in '%s' at %s"
,
utils
.
GenDir
,
utils
.
DateTimeStr
(
time
.
Now
())))
}
else
{
fmt
.
Fprint
(
cmdView
,
err
.
Error
())
fmt
.
Fprint
ln
(
cmdView
,
err
.
Error
())
}
return
nil
...
...
src/http/http.go
浏览文件 @
80c2762a
package
httpClient
import
(
"encoding/json"
"errors"
"fmt"
"github.com/easysoft/zentaoatf/src/model"
"io/ioutil"
"net/http"
)
func
GetBuf
(
url
string
,
params
map
[
string
]
string
)
([]
byte
,
error
)
{
func
Get
(
url
string
,
params
map
[
string
]
string
)
(
model
.
Response
,
error
)
{
var
ret
model
.
Response
req
,
err
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
if
err
!=
nil
{
return
[]
byte
(
""
)
,
err
return
ret
,
err
}
q
:=
req
.
URL
.
Query
()
...
...
@@ -20,32 +26,20 @@ func GetBuf(url string, params map[string]string) ([]byte, error) {
var
resp
*
http
.
Response
resp
,
err
=
http
.
DefaultClient
.
Do
(
req
)
if
err
!=
nil
{
return
[]
byte
(
""
)
,
err
return
ret
,
err
}
bytes
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
defer
resp
.
Body
.
Close
()
return
bytes
,
nil
}
func
Get
(
url
string
,
params
map
[
string
]
string
)
(
string
,
error
)
{
bts
,
err
:=
GetBuf
(
url
,
params
)
bytes
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
""
,
err
return
ret
,
err
}
return
string
(
bts
),
nil
}
func
GetMock
(
url
string
,
params
map
[
string
]
string
)
string
{
resp
,
err
:=
http
.
Get
(
url
)
if
err
!=
nil
{
return
err
.
Error
()
var
respModel
model
.
Response
json
.
Unmarshal
(
bytes
,
&
respModel
)
if
respModel
.
Code
!=
1
{
return
ret
,
errors
.
New
(
fmt
.
Sprintf
(
"request fail, code %d"
,
respModel
.
Code
))
}
bytes
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
defer
resp
.
Body
.
Close
()
return
string
(
bytes
)
return
respModel
,
nil
}
src/utils/constant.go
浏览文件 @
80c2762a
...
...
@@ -11,4 +11,6 @@ const (
EnRes
=
"res/messages_en.json"
ZhRes
=
"res/messages_zh.json"
GenDir
=
"scripts/"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录