提交 8f8e39d3 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

init

上级 2d1358bd
github.com/awesome-gocui/gocui v0.6.0 h1:hhDJiQC12tEsJNJ+iZBBVaSSLFYo9llFuYpQlL5JZVI=
github.com/awesome-gocui/gocui v0.6.0/go.mod h1:1QikxFaPhe2frKeKvEwZEIGia3haiOxOUXKinrv17mA=
github.com/awesome-gocui/termbox-go v0.0.0-20190427202837-c0aef3d18bcc h1:wGNpKcHU8Aadr9yOzsT3GEsFLS7HQu8HxQIomnekqf0=
github.com/awesome-gocui/termbox-go v0.0.0-20190427202837-c0aef3d18bcc/go.mod h1:tOy3o5Nf1bA17mnK4W41gD7PS3u4Cv0P0pqFcoWMy8s=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo=
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.55.0 h1:E8yzL5unfpW3M6fz/eB7Cb5MQAYSZ7GKo4Qth+N2sgQ=
gopkg.in/ini.v1 v1.55.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
$>ztf.exe run demo\lang\bat\1_string_match.bat 执行演示测试用例。
$>ztf.exe set 根据系统提示,设置语言、禅道系统地址、账号和密码参数,Windows系统下会提示输入各种脚本语言的解释程序。
$>ztf.exe co 交互式导出禅道测试用例,将提示用户输入导出类型和编号。
$>ztf.exe co -product 1 -language python 导出编号为1的产品测试用例,使用python语言,缩写-p -l。
$>ztf.exe co -p 1 -m 15 -l python 导出产品编号为1、模块编号为15的测试用例。
$>ztf.exe co -s 1 -l python -i true 导出编号为1的套件所含测试用例,期待结果保存在独立文件中。
$>ztf.exe co -t 1 -l python 导出编号为1的测试单所含用例。
$>ztf.exe up -t 1 -l python 更新编号为1的测试单所含用例的信息。
$>ztf.exe run demo\lang\bat 执行目录bat下的脚本,支持多个目录和文件参数项。
$>ztf.exe run product01 product01\all.cs 执行all.cs测试套件的用例,脚本在product01目录中。
$>ztf.exe run log\001\result.txt 执行result.txt结果文件中的失败用例。
$>ztf.exe run product01 -suite 1 执行禅道系统中编号为1的套件,脚本在product01目录,缩写-s。
$>ztf.exe run -task 1 执行禅道系统中编号为1的任务,脚本在当期目录, 缩写-t。
$>ztf.exe ci product01\tc-1.py 将脚本里修改的用例信息,同步到禅道系统。
$>ztf.exe cr log\001 提交测试结果到禅道系统。
$>ztf.exe cr -r log\001 提交测试结果到禅道系统,不需要逐个确认。
$>ztf.exe cb log\001 提交测试结果中失败用例为缺陷。
$>ztf.exe list demo\lang\bat 列出目录bat下的所有脚本文件,支持多个目录和文件参数项。
$>ztf.exe ls demo\lang\bat -k 0 列出指定路径下,ID为0的脚本。
$>ztf.exe -l demo\lang\bat -k pattern 列出指定路径下,标题包含'pattern'的脚本。
$>ztf.exe view demo\lang\bat\1_string_match.bat 查看指定路径的测试脚本,支持多个参数项。
$>ztf.exe -v demo\lang\bat -k 0 查看指定路径下,ID为0的脚本。
$>ztf.exe -v demo\lang\bat -k word 查看指定路径下,标题包含'pattern'的脚本。
$>ztf.exe sort demo\sample\2_with_group.php 将脚本的步骤重新排序,支持多个目录和文件参数项,缩写-s。
$>ztf.exe clean 清除所有测试执行日志,缩写-c。
\ No newline at end of file
help -h 查看帮助信息。
set -s 设置语言、禅道系统同步参数。用户对当前目录需要有写权限。
co checkout 导出禅道系统中的用例,已存在的将更新标题和步骤描述。可指定产品、套件、测试单编号。
up update 从禅道系统更新已存在的用例。可指定产品、模块、套件、测试单编号。
run -r 执行用例。可指定目录、套件、脚本、结果文件路径,以及套件和任务编号,多个文件间用空格隔开。
ci 将脚本中修改的用例信息,同步到禅道系统。
cr 将用例执行结果提交到禅道系统中。
cb 将执行结果中的失败用例,作为缺陷提交到禅道系统。
list ls -l 查看测试用例列表。可指定目录和文件的列表,之间用空格隔开。
view -v 查看测试用例详情。可指定目录和文件的列表,之间用空格隔开。
sort -sort 将脚本文件中的步骤重新排序。
clean -c 清除脚本执行日志。
--verbose 增加此参数,用于显示详细日志,如Http请求、响应、错误等信息。
为了方便在任意目录中执行%s命令,建议将其加入环境变量中,具体方法参照以下地址。
https://github.com/easysoft/zentaoatf/blob/master/HOWTO.md
\ No newline at end of file
{
"code": 1,
"name": "禅道自动化测试框架产品",
"cases": [
{
"id": 100,
"title": "测试用例01",
"steps": [
{
"id": 1000,
"title": "步骤01"
}
]
},
{
"id": 200,
"title": "登录失败账号锁定策略",
"steps": [
{
"id": 2000,
"title": "连续输入3次错误的密码"
},
{
"id": 2010,
"title": "第4次尝试登录",
"expect": "系统提示账号被锁定",
"isCheckPoint": true
},
{
"id": 2100,
"title": "不连续输入3次错误的密码",
"isGroup": true,
"steps": [
{
"id": 2101,
"title": "输入2次错误的密码",
"isGroup": false
},
{
"id": 2102,
"title": "输入1次正确的密码",
"isGroup": false
},
{
"id": 2103,
"title": "再输入1次错误的密码",
"isGroup": false
},
{
"id": 2104,
"title": "再输入1次正确的密码",
"expect": "登录成功,账号未被锁定",
"isCheckPoint": true
}
]
}
]
}
]
}
\ No newline at end of file
{
"code": 1
}
\ No newline at end of file
{
"code": 1,
"zentaoSettings": {
"modules": [
{
"Id": 100,
"Code": "admin",
"Name": "Admin",
"IsDefault": false
},
{
"Id": 200,
"Code": "client",
"Name": "Client",
"IsDefault": false
},
{
"Id": 300,
"Code": "interface",
"Name": "Interface",
"IsDefault": false
},
{
"Id": 400,
"Code": "site",
"Name": "Site",
"IsDefault": false
},
{
"Id": 500,
"Code": "api",
"Name": "API",
"IsDefault": true
},
{
"Id": 600,
"Code": "testing",
"Name": "Testing",
"IsDefault": false
}
],
"categories": [
{
"Id": 100,
"Code": "admin",
"Name": "Admin",
"IsDefault": false
},
{
"Id": 200,
"Code": "client",
"Name": "Client",
"IsDefault": false
},
{
"Id": 300,
"Code": "interface",
"Name": "Interface",
"IsDefault": false
},
{
"Id": 400,
"Code": "site",
"Name": "Site",
"IsDefault": false
},
{
"Id": 500,
"Code": "api",
"Name": "API",
"IsDefault": false
},
{
"Id": 600,
"Code": "testing",
"Name": "Testing",
"IsDefault": false
}
],
"versions": [
{
"Id": 100,
"Code": "admin",
"Name": "Admin",
"IsDefault": false
},
{
"Id": 200,
"Code": "client",
"Name": "Client",
"IsDefault": false
},
{
"Id": 300,
"Code": "interface",
"Name": "Interface",
"IsDefault": false
},
{
"Id": 400,
"Code": "site",
"Name": "Site",
"IsDefault": false
},
{
"Id": 500,
"Code": "api",
"Name": "API",
"IsDefault": false
},
{
"Id": 600,
"Code": "testing",
"Name": "Testing",
"IsDefault": false
}
],
"priorities": [
{
"Id": 100,
"Code": "admin",
"Name": "Admin",
"IsDefault": false
},
{
"Id": 200,
"Code": "client",
"Name": "Client",
"IsDefault": false
},
{
"Id": 300,
"Code": "interface",
"Name": "Interface",
"IsDefault": false
},
{
"Id": 400,
"Code": "site",
"Name": "Site",
"IsDefault": false
},
{
"Id": 500,
"Code": "api",
"Name": "API",
"IsDefault": false
},
{
"Id": 600,
"Code": "testing",
"Name": "Testing",
"IsDefault": false
}
]
}
}
\ No newline at end of file
{
"language": "en-US",
"messages": [
{
"id": "for_example",
"translation": "e.g. %s"
},
{
"id": "total",
"translation": "Total"
}
]
}
\ No newline at end of file
{
"language": "zh",
"messages": [
{
"id": "for_example",
"translation": "例如 %s"
}
]
}
\ No newline at end of file
此差异已折叠。
@echo off
setlocal enabledelayedexpansion
goto start
[case]
%s
[esac]
:start
%s
#!/usr/bin/env lua
--[[
[case]
%s
[esac]
]]
%s
\ No newline at end of file
#!/usr/bin/env perl
=pod
[case]
%s
[esac]
=cut
%s
\ No newline at end of file
#!/usr/bin/env php
<?php
/*
[case]
%s
[esac]
*/
%s
?>
#!/usr/bin/env python
'''
[case]
%s
[esac]
'''
%s
#!/usr/bin/env ruby
=begin
[case]
%s
[esac]
=end
%s
#!/usr/bin/env bash
:<<!
[case]
%s
[esac]
!
%s
#!/usr/bin/env tclsh
set case {
[case]
%s
[esac]
}
%s
package action
func Generate(file string, count int, fields string, out string, table string) {
}
package assertUtils
import (
"encoding/json"
"github.com/easysoft/zentaoatf/src/model"
commonUtils "github.com/easysoft/zentaoatf/src/utils/common"
constant "github.com/easysoft/zentaoatf/src/utils/const"
"github.com/easysoft/zentaoatf/src/utils/file"
langUtils "github.com/easysoft/zentaoatf/src/utils/lang"
stringUtils "github.com/easysoft/zentaoatf/src/utils/string"
"github.com/easysoft/zentaoatf/src/utils/vari"
zentaoUtils "github.com/easysoft/zentaoatf/src/utils/zentao"
"io/ioutil"
"os"
"path"
"regexp"
"strconv"
"strings"
)
func GetCaseByDirAndFile(files []string) []string {
cases := make([]string, 0)
for _, file := range files {
GetAllScriptsInDir(file, &cases)
}
return cases
}
func GetAllScriptsInDir(filePthParam string, files *[]string) error {
sep := string(os.PathSeparator)
if !fileUtils.IsDir(filePthParam) { // first call, param is file
regx := langUtils.GetSupportLanguageExtRegx()
pass, _ := regexp.MatchString(`.*\.`+regx+`$`, filePthParam)
if pass {
pass := zentaoUtils.CheckFileIsScript(filePthParam)
if pass {
*files = append(*files, filePthParam)
}
}
return nil
}
filePthParam = fileUtils.AbosutePath(filePthParam)
dir, err := ioutil.ReadDir(filePthParam)
if err != nil {
return err
}
for _, fi := range dir {
name := fi.Name()
if commonUtils.IngoreFile(name) {
continue
}
if fi.IsDir() { // 目录, 递归遍历
GetAllScriptsInDir(filePthParam+name+sep, files)
} else {
path := filePthParam + name
regx := langUtils.GetSupportLanguageExtRegx()
pass, _ := regexp.MatchString("^*.\\."+regx+"$", path)
if pass {
pass = zentaoUtils.CheckFileIsScript(path)
if pass {
*files = append(*files, path)
}
}
}
}
return nil
}
func GetScriptByIdsInDir(dirPth string, idMap map[int]string, files *[]string) error {
dirPth = fileUtils.AbosutePath(dirPth)
sep := string(os.PathSeparator)
if commonUtils.IngoreFile(dirPth) {
return nil
}
dir, err := ioutil.ReadDir(dirPth)
if err != nil {
return err
}
for _, fi := range dir {
name := fi.Name()
if fi.IsDir() { // 目录, 递归遍历
GetScriptByIdsInDir(dirPth+name+sep, idMap, files)
} else {
regx := langUtils.GetSupportLanguageExtRegx()
pass, _ := regexp.MatchString("^*.\\."+regx+"$", name)
if !pass {
continue
}
path := dirPth + name
pass, id, _, _ := zentaoUtils.GetCaseInfo(path)
if pass {
_, ok := idMap[id]
if ok {
*files = append(*files, path)
}
}
}
}
return nil
}
func GetCaseIdsInSuiteFile(name string, fileIdMap *map[int]string) {
content := fileUtils.ReadFile(name)
for _, line := range strings.Split(content, "\n") {
idStr := strings.TrimSpace(line)
if idStr == "" {
continue
}
id, err := strconv.Atoi(idStr)
if err == nil {
(*fileIdMap)[id] = ""
}
}
}
func GetFailedCasesDirectlyFromTestResult(resultFile string) []string {
cases := make([]string, 0)
extName := path.Ext(resultFile)
if extName == "."+constant.ExtNameResult {
resultFile = strings.Replace(resultFile, extName, "."+constant.ExtNameJson, -1)
}
content := fileUtils.ReadFile(resultFile)
var report model.TestReport
json.Unmarshal([]byte(content), &report)
for _, cs := range report.FuncResult {
if cs.Status != "pass" {
cases = append(cases, cs.Path)
}
}
return cases
}
func GetScriptType(scripts []string) []string {
vari.ScriptExtToNameMap = langUtils.GetExtToNameMap()
exts := make([]string, 0)
for _, script := range scripts {
ext := path.Ext(script)
if ext != "" {
ext = ext[1:]
name := vari.ScriptExtToNameMap[ext]
if !stringUtils.FindInArr(name, exts) {
exts = append(exts, name)
}
}
}
return exts
}
package commonUtils
import (
"github.com/easysoft/zentaoatf/src/model"
"github.com/easysoft/zentaoatf/src/utils/const"
stringUtils "github.com/easysoft/zentaoatf/src/utils/string"
"github.com/easysoft/zendata/src/model"
"github.com/easysoft/zendata/src/utils/const"
stringUtils "github.com/easysoft/zendata/src/utils/string"
"github.com/emirpasic/gods/maps"
"os"
"path"
......
......@@ -2,17 +2,15 @@ package configUtils
import (
"fmt"
"github.com/easysoft/zentaoatf/src/model"
assertUtils "github.com/easysoft/zentaoatf/src/utils/assert"
commonUtils "github.com/easysoft/zentaoatf/src/utils/common"
"github.com/easysoft/zentaoatf/src/utils/const"
"github.com/easysoft/zentaoatf/src/utils/display"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
"github.com/easysoft/zentaoatf/src/utils/i118"
langUtils "github.com/easysoft/zentaoatf/src/utils/lang"
logUtils "github.com/easysoft/zentaoatf/src/utils/log"
stdinUtils "github.com/easysoft/zentaoatf/src/utils/stdin"
"github.com/easysoft/zentaoatf/src/utils/vari"
"github.com/easysoft/zendata/src/model"
commonUtils "github.com/easysoft/zendata/src/utils/common"
"github.com/easysoft/zendata/src/utils/const"
"github.com/easysoft/zendata/src/utils/display"
fileUtils "github.com/easysoft/zendata/src/utils/file"
"github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log"
stdinUtils "github.com/easysoft/zendata/src/utils/stdin"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/fatih/color"
"gopkg.in/ini.v1"
"os"
......@@ -20,10 +18,10 @@ import (
)
func InitConfig() {
vari.ZTFDir = fileUtils.GetZTFDir()
vari.ZDataDir = fileUtils.GetZTFDir()
CheckConfigPermission()
constant.ConfigFile = vari.ZTFDir + constant.ConfigFile
constant.ConfigFile = vari.ZDataDir + constant.ConfigFile
vari.Config = getInst()
// screen size
......@@ -109,12 +107,12 @@ func getInst() model.Config {
}
func CheckConfigPermission() {
//err := syscall.Access(vari.ZTFDir, syscall.O_RDWR)
//err := syscall.Access(vari.ZDataDir, syscall.O_RDWR)
err := fileUtils.MkDirIfNeeded(vari.ZTFDir + "conf")
err := fileUtils.MkDirIfNeeded(vari.ZDataDir + "conf")
if err != nil {
logUtils.PrintToWithColor(
fmt.Sprintf("Permission denied to open %s for write. Please change work dir.", vari.ZTFDir), color.FgRed)
fmt.Sprintf("Permission denied to open %s for write. Please change work dir.", vari.ZDataDir), color.FgRed)
os.Exit(0)
}
}
......@@ -161,15 +159,6 @@ func InputForSet() {
conf.Password = stdinUtils.GetInput("(.{2,})", conf.Password, "enter_password", conf.Password)
}
if commonUtils.IsWin() {
var configInterpreter bool
stdinUtils.InputForBool(&configInterpreter, true, "config_script_interpreter")
if configInterpreter {
scripts := assertUtils.GetCaseByDirAndFile([]string{"."})
InputForScriptInterpreter(scripts, &conf, "set")
}
}
SaveConfig(conf)
PrintCurrConfig()
}
......@@ -191,39 +180,4 @@ func InputForRequest() {
conf.Password = stdinUtils.GetInput("(.{2,})", conf.Password, "enter_password", conf.Password)
SaveConfig(conf)
}
func InputForScriptInterpreter(scripts []string, config *model.Config, from string) bool {
configChanged := false
langs := assertUtils.GetScriptType(scripts)
for _, lang := range langs {
if lang == "bat" || lang == "shell" {
continue
}
deflt := commonUtils.GetFieldVal(*config, lang)
if from == "run" && deflt != "" { // already set when run, "-" means ignore
continue
}
if deflt == "-" {
deflt = ""
}
sampleOrDefaultTips := ""
if deflt == "" {
sampleOrDefaultTips = i118Utils.I118Prt.Sprintf("for_example", langUtils.LangMap[lang]["interpreter"]) + " " +
i118Utils.I118Prt.Sprintf("empty_to_ignore")
} else {
sampleOrDefaultTips = deflt
}
configChanged = true
inter := stdinUtils.GetInputForScriptInterpreter(deflt, "set_script_interpreter", lang, sampleOrDefaultTips)
commonUtils.SetFieldVal(config, lang, inter)
}
return configChanged
}
}
\ No newline at end of file
package display
import (
"github.com/easysoft/zentaoatf/src/utils/common"
"github.com/easysoft/zentaoatf/src/utils/shell"
"github.com/easysoft/zendata/src/utils/common"
"github.com/easysoft/zendata/src/utils/shell"
"os"
"os/exec"
"regexp"
......
......@@ -2,10 +2,10 @@ package fileUtils
import (
"fmt"
"github.com/easysoft/zentaoatf/res"
commonUtils "github.com/easysoft/zentaoatf/src/utils/common"
constant "github.com/easysoft/zentaoatf/src/utils/const"
"github.com/easysoft/zentaoatf/src/utils/vari"
"github.com/easysoft/zendata/res"
commonUtils "github.com/easysoft/zendata/src/utils/common"
constant "github.com/easysoft/zendata/src/utils/const"
"github.com/easysoft/zendata/src/utils/vari"
"io"
"io/ioutil"
"os"
......@@ -155,7 +155,7 @@ func GetZTFDir() string { // where ztf command in
}
func GetLogDir() string {
path := vari.ZTFDir + constant.LogDir
path := vari.ZDataDir + constant.LogDir
dir, _ := ioutil.ReadDir(path)
......
......@@ -2,9 +2,9 @@ package i118Utils
import (
"encoding/json"
"github.com/easysoft/zentaoatf/res"
"github.com/easysoft/zentaoatf/src/utils/common"
constant "github.com/easysoft/zentaoatf/src/utils/const"
"github.com/easysoft/zendata/res"
"github.com/easysoft/zendata/src/utils/common"
constant "github.com/easysoft/zendata/src/utils/const"
"golang.org/x/text/language"
"golang.org/x/text/message"
"io/ioutil"
......
package langUtils
import (
i118Utils "github.com/easysoft/zentaoatf/src/utils/i118"
logUtils "github.com/easysoft/zentaoatf/src/utils/log"
stringUtils "github.com/easysoft/zentaoatf/src/utils/string"
"github.com/easysoft/zentaoatf/src/utils/vari"
i118Utils "github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log"
stringUtils "github.com/easysoft/zendata/src/utils/string"
"github.com/fatih/color"
"path"
"sort"
"strconv"
"strings"
......@@ -160,15 +158,6 @@ func GetExtToNameMap() map[string]string {
return extMap
}
func GetLangByFile(filePath string) string {
ext := path.Ext(filePath)
ext = ext[1:]
lang := vari.ScriptExtToNameMap[ext]
return lang
}
func init() {
initSupportedScriptLang()
}
......@@ -2,8 +2,9 @@ package logUtils
import (
"fmt"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
"github.com/easysoft/zentaoatf/src/utils/vari"
fileUtils "github.com/easysoft/zendata/src/utils/file"
i118Utils "github.com/easysoft/zendata/src/utils/i118"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/fatih/color"
"github.com/rifflock/lfshook"
"github.com/sirupsen/logrus"
......
......@@ -3,11 +3,9 @@ package logUtils
import (
"encoding/json"
"fmt"
commonUtils "github.com/easysoft/zentaoatf/src/utils/common"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
"github.com/easysoft/zentaoatf/src/utils/vari"
commonUtils "github.com/easysoft/zendata/src/utils/common"
fileUtils "github.com/easysoft/zendata/src/utils/file"
"github.com/fatih/color"
"io"
"os"
"regexp"
"strings"
......@@ -63,12 +61,7 @@ func PrintToWithColor(msg string, attr color.Attribute) {
}
func PrintToCmd(msg string, attr color.Attribute) {
var output io.Writer
if vari.RunFromCui {
output, _ = vari.Cui.View("cmd")
} else {
output = color.Output
}
output := color.Output
if attr == -1 {
fmt.Fprint(output, msg+"\n")
......
......@@ -2,9 +2,9 @@ package scriptUtils
import (
"fmt"
"github.com/easysoft/zentaoatf/src/model"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
zentaoUtils "github.com/easysoft/zentaoatf/src/utils/zentao"
"github.com/easysoft/zendata/src/model"
fileUtils "github.com/easysoft/zendata/src/utils/file"
zentaoUtils "github.com/easysoft/zendata/src/utils/zentao"
"github.com/emirpasic/gods/maps"
"github.com/emirpasic/gods/maps/linkedhashmap"
"regexp"
......
......@@ -4,14 +4,9 @@ import (
"bufio"
"bytes"
"fmt"
commonUtils "github.com/easysoft/zentaoatf/src/utils/common"
i118Utils "github.com/easysoft/zentaoatf/src/utils/i118"
langUtils "github.com/easysoft/zentaoatf/src/utils/lang"
logUtils "github.com/easysoft/zentaoatf/src/utils/log"
stringUtils "github.com/easysoft/zentaoatf/src/utils/string"
"github.com/easysoft/zentaoatf/src/utils/vari"
commonUtils "github.com/easysoft/zendata/src/utils/common"
logUtils "github.com/easysoft/zendata/src/utils/log"
"io"
"os"
"os/exec"
"strings"
)
......@@ -69,71 +64,4 @@ func ExeShellWithOutput(cmdStr string) []string {
cmd.Wait()
return output
}
func ExecFile(filePath string) string {
var cmd *exec.Cmd
if commonUtils.IsWin() {
lang := langUtils.GetLangByFile(filePath)
scriptInterpreter := ""
if strings.ToLower(lang) != "bat" {
if vari.Interpreter != "" {
scriptInterpreter = vari.Interpreter
fmt.Printf("use interpreter %s for script %s\n", scriptInterpreter, filePath)
} else {
scriptInterpreter = commonUtils.GetFieldVal(vari.Config, stringUtils.Ucfirst(lang))
}
}
if scriptInterpreter != "" {
if strings.Index(strings.ToLower(scriptInterpreter), "autoit") > -1 {
cmd = exec.Command("cmd", "/C", scriptInterpreter, filePath, "|", "more")
} else {
cmd = exec.Command("cmd", "/C", scriptInterpreter, filePath)
}
} else if strings.ToLower(lang) == "bat" {
cmd = exec.Command("cmd", "/C", filePath)
} else {
fmt.Printf("use interpreter %s for script %s\n", scriptInterpreter, filePath)
i118Utils.I118Prt.Printf("no_interpreter_for_run", filePath, lang)
}
} else {
err := os.Chmod(filePath, 0777)
if err != nil {
logUtils.Screen("chmod error" + err.Error())
}
filePath = "\"" + filePath + "\""
cmd = exec.Command("/bin/bash", "-c", filePath)
}
output := make([]string, 0)
stdout, err := cmd.StdoutPipe()
if err != nil {
fmt.Println(err)
return ""
}
cmd.Start()
if err != nil {
return fmt.Sprint(err)
}
reader := bufio.NewReader(stdout)
for {
line, err2 := reader.ReadString('\n')
if err2 != nil || io.EOF == err2 {
break
}
//logUtils.Trace(strings.TrimRight(line, "\n"))
output = append(output, line)
}
cmd.Wait()
return strings.Join(output, "")
}
}
\ No newline at end of file
......@@ -3,10 +3,10 @@ package stdinUtils
import (
"bufio"
"fmt"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
i118Utils "github.com/easysoft/zentaoatf/src/utils/i118"
langUtils "github.com/easysoft/zentaoatf/src/utils/lang"
logUtils "github.com/easysoft/zentaoatf/src/utils/log"
fileUtils "github.com/easysoft/zendata/src/utils/file"
i118Utils "github.com/easysoft/zendata/src/utils/i118"
langUtils "github.com/easysoft/zendata/src/utils/lang"
logUtils "github.com/easysoft/zendata/src/utils/log"
"github.com/fatih/color"
"os"
"regexp"
......
......@@ -4,7 +4,7 @@ import (
"bytes"
"encoding/binary"
"encoding/hex"
constant "github.com/easysoft/zentaoatf/src/utils/const"
constant "github.com/easysoft/zendata/src/utils/const"
"github.com/mattn/go-runewidth"
"strings"
"unicode"
......
package vari
import (
"github.com/awesome-gocui/gocui"
"github.com/easysoft/zentaoatf/src/model"
"github.com/easysoft/zentaoatf/src/utils/const"
"github.com/easysoft/zendata/src/model"
"github.com/easysoft/zendata/src/utils/const"
)
var (
Config = model.Config{}
Cui *gocui.Gui
MainViewHeight int
RunMode constant.RunMode
ZTFDir string
LogDir string
RunFromCui bool
UnitTestType string
UnitTestTool string
UnitTestResult string
ProductId string
SessionVar string
SessionId string
RequestType string
RequestFix string = ""
ScriptExtToNameMap map[string]string
CurrScriptFile string // scripts/tc-001.py
CurrResultDate string // 2019-08-15T173802
CurrCaseId int // 2019-08-15T173802
ScreenWidth int
ScreenHeight int
ZentaoBugFileds model.ZentaoBugFileds
//ZentaoCaseFileds model.ZentaoCaseFileds
CurrBug model.Bug
CurrBugStepIds string
RunMode constant.RunMode
ZDataDir string
LogDir string
ScreenWidth int
ScreenHeight int
RequestType string
Verbose bool
Interpreter string
)
......@@ -2,45 +2,10 @@ package zentaoUtils
import (
"fmt"
constant "github.com/easysoft/zentaoatf/src/utils/const"
dateUtils "github.com/easysoft/zentaoatf/src/utils/date"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
"github.com/easysoft/zentaoatf/src/utils/vari"
"os"
"path"
"regexp"
"strconv"
"strings"
"time"
constant "github.com/easysoft/zendata/src/utils/const"
"github.com/easysoft/zendata/src/utils/vari"
)
func GenSuperApiUri(model string, methd string, params [][]string) string {
var sep string
if vari.RequestType == constant.RequestTypePathInfo {
sep = ","
} else {
sep = "&"
}
paramStr := "" // format is key1=val1&key2=val2
i := 0
for _, p := range params {
if i > 0 {
paramStr += sep
}
paramStr += p[0] + "=" + p[1]
i++
}
var uri string
if vari.RequestType == constant.RequestTypePathInfo {
uri = fmt.Sprintf("api-getmodel-%s-%s-%s.json", model, methd, paramStr)
} else {
uri = fmt.Sprintf("index.php?m=api&f=getmodel&model=%s&methodName=%s&params=%s&t=json", model, methd, paramStr)
}
return uri
}
func GenApiUri(module string, methd string, param string) string {
var uri string
......@@ -51,250 +16,4 @@ func GenApiUri(module string, methd string, param string) string {
}
return uri
}
func ScriptToExpectName(file string) string {
fileSuffix := path.Ext(file)
expectName := strings.TrimSuffix(file, fileSuffix) + ".exp"
return expectName
}
func RunDateFolder() string {
runName := dateUtils.DateTimeStrFmt(time.Now(), "2006-01-02T150405") + string(os.PathSeparator)
return runName
}
func GetCaseInfo(file string) (bool, int, int, string) {
var caseId int
var productId int
var title string
content := fileUtils.ReadFile(file)
pass := CheckFileContentIsScript(content)
if !pass {
return false, caseId, productId, title
}
caseInfo := ""
myExp := regexp.MustCompile(`(?s)\[case\](.*)\[esac\]`)
arr := myExp.FindStringSubmatch(content)
if len(arr) > 1 {
caseInfo = arr[1]
}
myExp = regexp.MustCompile(`[\S\s]*cid=\s*([^\n]*?)\s*\n`)
arr = myExp.FindStringSubmatch(caseInfo)
if len(arr) > 1 {
caseId, _ = strconv.Atoi(arr[1])
}
myExp = regexp.MustCompile(`[\S\s]*pid=\s*([^\n]*?)\s*\n`)
arr = myExp.FindStringSubmatch(caseInfo)
if len(arr) > 1 {
productId, _ = strconv.Atoi(arr[1])
}
myExp = regexp.MustCompile(`[\S\s]*title=\s*([^\n]*?)\s*\n`)
arr = myExp.FindStringSubmatch(caseInfo)
if len(arr) > 1 {
title = arr[1]
}
return pass, caseId, productId, title
}
//func ReadScriptCheckpoints(file string) ([]string, [][]string) {
// _, expectIndependentContent := GetDependentExpect(file)
//
// content := fileUtils.ReadFile(file)
// _, checkpoints := ReadCaseInfo(content)
//
// cpStepArr, expectArr := getCheckpointStepArr(checkpoints, expectIndependentContent)
//
// return cpStepArr, expectArr
//}
func getCheckpointStepArr(content string, expectIndependentContent string) ([]string, [][]string) {
cpStepArr := make([]string, 0)
expectArr := make([][]string, 0)
independentExpect := expectIndependentContent != ""
lines := strings.Split(content, "\n")
i := 0
for i < len(lines) {
step := ""
expects := make([]string, 0)
line := strings.TrimSpace(lines[i])
regx := regexp.MustCompile(`(?U:[\d\.]*)(.+)>>(.*)`)
arr := regx.FindStringSubmatch(line)
if len(arr) > 2 {
step = arr[1]
if !independentExpect {
expects = append(expects, strings.TrimSpace(arr[2]))
}
} else {
regx = regexp.MustCompile(`\[([\d\.]*).*expects\]`)
arr = regx.FindStringSubmatch(line)
if len(arr) > 1 {
step = arr[1]
if !independentExpect {
for i+1 < len(lines) {
ln := strings.TrimSpace(lines[i+1])
if strings.Index(ln, "[") == 0 || strings.Index(ln, ">>") > 0 || ln == "" {
break
} else {
expects = append(expects, ln)
i++
}
}
}
}
}
if step != "" && len(expects) > 0 {
cpStepArr = append(cpStepArr, step)
if !independentExpect {
expectArr = append(expectArr, expects)
}
}
i++
}
if independentExpect {
expectArr = ReadExpectIndependentArr(expectIndependentContent)
}
return cpStepArr, expectArr
}
func ReadExpectIndependentArr(content string) [][]string {
lines := strings.Split(content, "\n")
ret := make([][]string, 0)
var cpArr []string
for idx, line := range lines {
line = strings.TrimSpace(line)
if line == ">>" { // more than one line
cpArr = make([]string, 0)
} else if strings.Index(line, ">>") == 0 { // single line
line = strings.Replace(line, ">>", "", -1)
line = strings.TrimSpace(line)
cpArr = append(cpArr, line)
ret = append(ret, cpArr)
cpArr = make([]string, 0)
} else { // under >>
cpArr = append(cpArr, line)
if idx == len(lines)-1 || strings.Index(lines[idx+1], ">>") > -1 {
ret = append(ret, cpArr)
cpArr = make([]string, 0)
}
}
}
return ret
}
func ReadLogArr(content string) (bool, [][]string) {
lines := strings.Split(content, "\n")
ret := make([][]string, 0)
var cpArr []string
model := ""
for idx, line := range lines {
line = strings.TrimSpace(line)
if line == "skip" {
return true, nil
}
if line == ">>" { // more than one line
model = "multi"
cpArr = make([]string, 0)
} else if strings.Index(line, ">>") == 0 { // single line
model = "single"
line = strings.Replace(line, ">>", "", -1)
line = strings.TrimSpace(line)
cpArr = append(cpArr, line)
ret = append(ret, cpArr)
cpArr = make([]string, 0)
} else {
if model == "" || model == "single" {
continue
}
// under >>
cpArr = append(cpArr, line)
if idx == len(lines)-1 || strings.Index(lines[idx+1], ">>") > -1 {
ret = append(ret, cpArr)
cpArr = make([]string, 0)
}
}
}
return false, ret
}
func CheckFileIsScript(path string) bool {
content := fileUtils.ReadFile(path)
pass := CheckFileContentIsScript(content)
return pass
}
func CheckFileContentIsScript(content string) bool {
pass, _ := regexp.MatchString(`\[case\]`, content)
return pass
}
func ReadCaseInfo(content string) (string, string) {
myExp := regexp.MustCompile(`(?s)\[case\]((?U:.*pid.*))\n(.*)\[esac\]`)
arr := myExp.FindStringSubmatch(content)
if len(arr) > 2 {
info := strings.TrimSpace(arr[1])
checkpoints := strings.TrimSpace(arr[2])
return info, checkpoints
}
return "", ""
}
func ReadCaseId(content string) string {
myExp := regexp.MustCompile(`(?s)\[case\].*\ncid=((?U:.*))\n.*\[esac\]`)
arr := myExp.FindStringSubmatch(content)
if len(arr) > 1 {
id := strings.TrimSpace(arr[1])
return id
}
return ""
}
func GetDependentExpect(file string) (bool, string) {
expectIndependentFile := strings.Replace(file, path.Ext(file), ".exp", -1)
if fileUtils.FileExist(expectIndependentFile) {
expectIndependentContent := fileUtils.ReadFile(expectIndependentFile)
return true, expectIndependentContent
}
return false, ""
}
}
\ No newline at end of file
......@@ -2,9 +2,8 @@ package main
import (
"flag"
configUtils "github.com/easysoft/zendata/src/utils/config"
"github.com/easysoft/zendata/src/action"
logUtils "github.com/easysoft/zendata/src/utils/log"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/fatih/color"
"os"
"os/signal"
......@@ -15,11 +14,11 @@ var (
language string
file string
count string
field string
count int
fields string
parse string
out bool
out string
table string
help bool
......@@ -62,9 +61,9 @@ func main() {
}
switch os.Args[1] {
case "checkout", "co":
case "gen":
if err := flagSet.Parse(os.Args[2:]); err == nil {
action.Generate(file, count, fields, out, table)
}
case "help", "-h":
logUtils.PrintUsage()
......@@ -84,9 +83,7 @@ func main() {
func init() {
cleanup()
vari.RunFromCui = false
configUtils.InitConfig()
//configUtils.InitConfig()
}
func cleanup() {
......
fields:
field1:
datatype: list
range: 10-20
prefix: int_
postfix: ' '
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册