Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zentaoatf
提交
0c8ba34f
Z
zentaoatf
项目概览
易企天创
/
zentaoatf
接近 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
0c8ba34f
编写于
7月 11, 2019
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use struct to save the logs
上级
67d5c5d7
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
79 addition
and
67 deletion
+79
-67
src/biz/check.go
src/biz/check.go
+39
-57
src/biz/run.go
src/biz/run.go
+6
-4
src/model/test-model.go
src/model/test-model.go
+24
-0
src/run.go
src/run.go
+10
-6
未找到文件。
src/biz/check.go
浏览文件 @
0c8ba34f
...
@@ -2,22 +2,16 @@ package biz
...
@@ -2,22 +2,16 @@ package biz
import
(
import
(
"fmt"
"fmt"
"model"
"regexp"
"regexp"
"sort"
"strconv"
"strings"
"strings"
"time"
"time"
"utils"
"utils"
)
)
func
CheckResults
(
dir
string
,
langType
string
,
func
CheckResults
(
dir
string
,
langType
string
,
report
*
model
.
TestReport
)
{
summaryMap
*
map
[
string
]
interface
{},
resultMap
*
map
[
string
]
bool
,
checkpointMap
*
map
[
string
][]
string
)
{
fmt
.
Printf
(
"
\n
=== Begin to analyse test result ===
\n\n
"
)
fmt
.
Printf
(
"
\n
=== Begin to analyse test result ===
\n\n
"
)
(
*
summaryMap
)[
"pass"
]
=
0
(
*
summaryMap
)[
"fail"
]
=
0
(
*
summaryMap
)[
"total"
]
=
0
scriptFiles
,
_
:=
utils
.
GetAllFiles
(
dir
,
langType
)
scriptFiles
,
_
:=
utils
.
GetAllFiles
(
dir
,
langType
)
for
_
,
scriptFile
:=
range
scriptFiles
{
for
_
,
scriptFile
:=
range
scriptFiles
{
...
@@ -29,16 +23,15 @@ func CheckResults(dir string, langType string,
...
@@ -29,16 +23,15 @@ func CheckResults(dir string, langType string,
expectContent
=
strings
.
Trim
(
expectContent
,
"
\n
"
)
expectContent
=
strings
.
Trim
(
expectContent
,
"
\n
"
)
logContent
=
strings
.
Trim
(
logContent
,
"
\n
"
)
logContent
=
strings
.
Trim
(
logContent
,
"
\n
"
)
Compare
(
scriptFile
,
expectContent
,
logContent
,
summaryMap
,
resultMap
,
checkpointMap
)
Compare
(
scriptFile
,
expectContent
,
logContent
,
report
)
}
}
}
}
func
Compare
(
scriptFile
string
,
expectContent
string
,
logContent
string
,
func
Compare
(
scriptFile
string
,
expectContent
string
,
logContent
string
,
report
*
model
.
TestReport
)
{
summaryMap
*
map
[
string
]
interface
{},
resultMap
*
map
[
string
]
bool
,
checkpointMap
*
map
[
string
][]
string
)
{
expectArr
:=
strings
.
Split
(
expectContent
,
"
\n
"
)
expectArr
:=
strings
.
Split
(
expectContent
,
"
\n
"
)
logArr
:=
strings
.
Split
(
logContent
,
"
\n
"
)
logArr
:=
strings
.
Split
(
logContent
,
"
\n
"
)
checkpoints
:=
make
([]
strin
g
,
0
)
checkpoints
:=
make
([]
model
.
CheckPointLo
g
,
0
)
result
:=
true
result
:=
true
...
@@ -60,69 +53,58 @@ func Compare(scriptFile string, expectContent string, logContent string,
...
@@ -60,69 +53,58 @@ func Compare(scriptFile string, expectContent string, logContent string,
result
=
false
result
=
false
}
}
checkpoints
=
append
(
checkpoints
,
"Line "
+
strconv
.
Itoa
(
numb
+
1
)
+
": "
+
strconv
.
FormatBool
(
result
))
cp
:=
model
.
CheckPointLog
{
Numb
:
numb
+
1
,
Status
:
result
,
Expect
:
line
,
Actual
:
log
}
checkpoints
=
append
(
checkpoints
,
cp
)
checkpoints
=
append
(
checkpoints
,
"Expect "
+
line
)
checkpoints
=
append
(
checkpoints
,
"Actual "
+
log
)
}
}
if
!
result
{
if
!
result
{
(
*
summaryMap
)[
"fail"
]
=
(
*
summaryMap
)[
"fail"
]
.
(
int
)
+
1
report
.
Fail
=
report
.
Fail
+
1
}
else
{
}
else
{
(
*
summaryMap
)[
"pass"
]
=
(
*
summaryMap
)[
"pass"
]
.
(
int
)
+
1
report
.
Pass
=
report
.
Pass
+
1
}
}
(
*
summaryMap
)[
"total"
]
=
(
*
summaryMap
)[
"total"
]
.
(
int
)
+
1
report
.
Total
=
report
.
Total
+
1
(
*
resultMap
)[
scriptFile
]
=
result
cs
:=
model
.
CaseLog
{
Path
:
scriptFile
,
Status
:
result
,
CheckPoints
:
checkpoints
}
(
*
checkpointMap
)[
scriptFile
]
=
checkpoints
report
.
Cases
=
append
(
report
.
Cases
,
cs
)
}
}
func
Print
(
summaryMap
map
[
string
]
interface
{},
resultMap
map
[
string
]
bool
,
checkpointMap
map
[
string
][]
string
,
workDir
string
)
{
func
Print
(
report
model
.
TestReport
,
workDir
string
)
{
startSec
:=
time
.
Unix
(
summaryMap
[
"startTime"
]
.
(
int64
)
,
0
)
startSec
:=
time
.
Unix
(
report
.
StartTime
,
0
)
endSec
:=
time
.
Unix
(
summaryMap
[
"endTime"
]
.
(
int64
)
,
0
)
endSec
:=
time
.
Unix
(
report
.
EndTime
,
0
)
var
log
string
logs
:=
make
([]
string
,
0
)
logs
:=
make
([]
string
,
0
)
log
=
fmt
.
Sprintf
(
"From %s to %s, duration %d sec"
,
PrintAndLog
(
&
logs
,
fmt
.
Sprintf
(
"From %s to %s, duration %d sec"
,
startSec
.
Format
(
"2006-01-02 15:04:05"
),
startSec
.
Format
(
"2006-01-02 15:04:05"
),
endSec
.
Format
(
"2006-01-02 15:04:05"
),
report
.
Duration
))
endSec
.
Format
(
"2006-01-02 15:04:05"
),
summaryMap
[
"duration"
])
logs
=
append
(
logs
,
log
)
fmt
.
Println
(
log
)
log
=
fmt
.
Sprintf
(
"Total: %d, Fail: %d, Pass: %d"
,
summaryMap
[
"total"
],
summaryMap
[
"pass"
],
summaryMap
[
"fail"
])
logs
=
append
(
logs
,
log
)
fmt
.
Println
(
log
)
var
sslice
[]
string
for
key
,
_
:=
range
resultMap
{
sslice
=
append
(
sslice
,
key
)
}
sort
.
Strings
(
sslice
)
for
_
,
script
:=
range
sslice
{
PrintAndLog
(
&
logs
,
fmt
.
Sprintf
(
"Total: %d, Fail: %d, Pass: %d"
,
count
:=
0
report
.
Total
,
report
.
Pass
,
report
.
Fail
))
log
=
fmt
.
Sprintf
(
"
\n
%s: %t"
,
script
,
resultMap
[
script
])
logs
=
append
(
logs
,
log
)
fmt
.
Println
(
log
)
checkpoints
:=
checkpointMap
[
script
]
for
_
,
cs
:=
range
report
.
Cases
{
PrintAndLog
(
&
logs
,
fmt
.
Sprintf
(
"
\n
%s: %t"
,
cs
.
Path
,
cs
.
Status
))
for
_
,
line
:=
range
checkpoints
{
if
len
(
cs
.
CheckPoints
)
>
0
{
if
count
>
0
&&
strings
.
Index
(
line
,
"Line "
)
>
-
1
{
count
:=
0
logs
=
append
(
logs
,
""
)
for
_
,
cp
:=
range
cs
.
CheckPoints
{
fmt
.
Println
(
""
)
if
count
>
0
{
PrintAndLog
(
&
logs
,
""
)
}
}
log
=
fmt
.
Sprintf
(
" %s"
,
line
)
PrintAndLog
(
&
logs
,
fmt
.
Sprintf
(
" Line %d: %t"
,
cp
.
Numb
,
cp
.
Status
)
)
logs
=
append
(
logs
,
log
)
PrintAndLog
(
&
logs
,
fmt
.
Sprintf
(
" Expect %s"
,
cp
.
Expect
)
)
fmt
.
Println
(
log
)
PrintAndLog
(
&
logs
,
fmt
.
Sprintf
(
" Actual %s"
,
cp
.
Actual
)
)
count
++
count
++
}
}
}
else
{
PrintAndLog
(
&
logs
,
" No checkpoints"
)
}
}
}
utils
.
WriteFile
(
workDir
+
"/logs/report.log"
,
strings
.
Join
(
logs
,
"
\n
"
))
utils
.
WriteFile
(
workDir
+
"/logs/report.log"
,
strings
.
Join
(
logs
,
"
\n
"
))
}
}
func
PrintAndLog
(
logs
*
[]
string
,
str
string
)
{
*
logs
=
append
(
*
logs
,
str
)
fmt
.
Println
(
str
)
}
src/biz/run.go
浏览文件 @
0c8ba34f
...
@@ -2,17 +2,18 @@ package biz
...
@@ -2,17 +2,18 @@ package biz
import
(
import
(
"fmt"
"fmt"
"model"
"runtime"
"runtime"
"strings"
"strings"
"time"
"time"
"utils"
"utils"
)
)
func
RunScripts
(
files
[]
string
,
dir
string
,
langType
string
,
summaryMap
*
map
[
string
]
interface
{}
)
{
func
RunScripts
(
files
[]
string
,
dir
string
,
langType
string
,
report
*
model
.
TestReport
)
{
fmt
.
Println
(
"=== Begin to run test scripts ==="
)
fmt
.
Println
(
"=== Begin to run test scripts ==="
)
startTime
:=
time
.
Now
()
.
Unix
()
startTime
:=
time
.
Now
()
.
Unix
()
(
*
summaryMap
)[
"startTime"
]
=
startTime
report
.
StartTime
=
startTime
for
_
,
file
:=
range
files
{
for
_
,
file
:=
range
files
{
RunScript
(
file
,
langType
,
dir
)
RunScript
(
file
,
langType
,
dir
)
...
@@ -20,8 +21,9 @@ func RunScripts(files []string, dir string, langType string, summaryMap *map[str
...
@@ -20,8 +21,9 @@ func RunScripts(files []string, dir string, langType string, summaryMap *map[str
endTime
:=
time
.
Now
()
.
Unix
()
endTime
:=
time
.
Now
()
.
Unix
()
secs
:=
endTime
-
startTime
secs
:=
endTime
-
startTime
(
*
summaryMap
)[
"endTime"
]
=
startTime
(
*
summaryMap
)[
"duration"
]
=
secs
report
.
EndTime
=
startTime
report
.
Duration
=
secs
}
}
func
RunScript
(
file
string
,
langType
string
,
dir
string
)
{
func
RunScript
(
file
string
,
langType
string
,
dir
string
)
{
...
...
src/model/test-model.go
浏览文件 @
0c8ba34f
...
@@ -18,3 +18,27 @@ type TestStep struct {
...
@@ -18,3 +18,27 @@ type TestStep struct {
IsGroup
bool
IsGroup
bool
IsCheckPoint
bool
IsCheckPoint
bool
}
}
type
TestReport
struct
{
Pass
int
Fail
int
Total
int
StartTime
int64
EndTime
int64
Duration
int64
Cases
[]
CaseLog
}
type
CaseLog
struct
{
Numb
int
Path
string
Status
bool
CheckPoints
[]
CheckPointLog
}
type
CheckPointLog
struct
{
Numb
int
Expect
string
Actual
string
Status
bool
}
src/run.go
浏览文件 @
0c8ba34f
...
@@ -3,6 +3,7 @@ package main
...
@@ -3,6 +3,7 @@ package main
import
(
import
(
"biz"
"biz"
"flag"
"flag"
"model"
"os"
"os"
"utils"
"utils"
)
)
...
@@ -20,11 +21,14 @@ func main() {
...
@@ -20,11 +21,14 @@ func main() {
files
,
_
:=
utils
.
GetAllFiles
(
*
workDir
,
*
langType
)
files
,
_
:=
utils
.
GetAllFiles
(
*
workDir
,
*
langType
)
summaryMap
:=
make
(
map
[
string
]
interface
{})
var
report
model
.
TestReport
biz
.
RunScripts
(
files
,
*
workDir
,
*
langType
,
&
summaryMap
)
report
.
Pass
=
0
report
.
Fail
=
0
report
.
Total
=
0
report
.
Cases
=
make
([]
model
.
CaseLog
,
0
)
resultMap
:=
make
(
map
[
string
]
bool
)
biz
.
RunScripts
(
files
,
*
workDir
,
*
langType
,
&
report
)
checkpointMap
:=
make
(
map
[
string
][]
string
)
biz
.
CheckResults
(
*
workDir
,
*
langType
,
&
summaryMap
,
&
resultMap
,
&
checkpointMap
)
biz
.
CheckResults
(
*
workDir
,
*
langType
,
&
report
)
biz
.
Print
(
summaryMap
,
resultMap
,
checkpointMap
,
*
workDir
)
biz
.
Print
(
report
,
*
workDir
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录