From 4774500e55787af959042a9daf4d430b5d5aef2b Mon Sep 17 00:00:00 2001
From: Aaron Chen <462826@qq.com>
Date: Wed, 28 Aug 2019 17:52:07 +0800
Subject: [PATCH] submit bug
---
res/messages_en.json | 14 +++++++++++--
res/messages_zh.json | 14 +++++++++++--
src/action/bug.go | 25 ++++++++++++++++++++++++
src/atf.go | 10 ++++++++++
src/model/config.go | 3 ---
src/model/testing.go | 8 +++-----
src/service/zentao/bug.go | 37 ++++++++++++++++++-----------------
src/service/zentao/field.go | 2 +-
src/ui/page/pageReportBug.go | 4 ++--
src/utils/config/config.go | 4 ++++
src/utils/const/const.go | 35 +++++++++++++++++++++++++++++++++
src/utils/log/print.go | 38 +++---------------------------------
12 files changed, 126 insertions(+), 68 deletions(-)
create mode 100644 src/action/bug.go
diff --git a/res/messages_en.json b/res/messages_en.json
index 092c3bb5..a2f7b4b5 100644
--- a/res/messages_en.json
+++ b/res/messages_en.json
@@ -11,6 +11,11 @@
"message": "begin config, type 'exit' to quit",
"translation": "begin to config"
},
+ {
+ "id": "test_case",
+ "message": "test case",
+ "translation": "case"
+ },
{
"id": "result",
"message": "result",
@@ -21,6 +26,11 @@
"message": "enter dir",
"translation": "enter %s dir."
},
+ {
+ "id": "enter_id",
+ "message": "enter id",
+ "translation": "enter %s id."
+ },
{
"id": "dir_not_exist",
"message": "",
@@ -271,8 +281,8 @@
},
{
"id": "success_to_report_bug",
- "message": "success to report a bug for case %s-%s",
- "translation": "success to report a bug for case %s-%s"
+ "message": "success to report a bug for case %s",
+ "translation": "success to report a bug for case %s"
},
{
"id": "success_to_submit_result",
diff --git a/res/messages_zh.json b/res/messages_zh.json
index 1391b802..8f94f56f 100644
--- a/res/messages_zh.json
+++ b/res/messages_zh.json
@@ -11,6 +11,11 @@
"message": "begin config",
"translation": "开始配置, 输入'exit'退出"
},
+ {
+ "id": "test_case",
+ "message": "test case",
+ "translation": "用例"
+ },
{
"id": "result",
"message": "result",
@@ -21,6 +26,11 @@
"message": "enter dir",
"translation": "输入%s目录"
},
+ {
+ "id": "enter_id",
+ "message": "enter id",
+ "translation": "enter %s id."
+ },
{
"id": "dir_not_exist",
"message": "",
@@ -263,8 +273,8 @@
},
{
"id": "success_to_report_bug",
- "message": "success to report a bug for case %s-%s",
- "translation": "成功为用例%s-%s提交缺陷"
+ "message": "success to report a bug for case %s",
+ "translation": "成功为用例%s提交缺陷"
},
{
"id": "success_to_submit_result",
diff --git a/src/action/bug.go b/src/action/bug.go
new file mode 100644
index 00000000..addd6bb8
--- /dev/null
+++ b/src/action/bug.go
@@ -0,0 +1,25 @@
+package action
+
+import (
+ zentaoService "github.com/easysoft/zentaoatf/src/service/zentao"
+ configUtils "github.com/easysoft/zentaoatf/src/utils/config"
+ fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
+)
+
+func CommitBug(files []string, caseId string) {
+ var resultDir string
+ if len(files) > 0 {
+ resultDir = files[0]
+ } else {
+ configUtils.ConfigForDir(&resultDir, "result")
+ }
+
+ if caseId == "" {
+ configUtils.ConfigForInt(&caseId, "test_case")
+ }
+
+ resultDir = fileUtils.UpdateDir(resultDir)
+
+ bug, stepIds := zentaoService.GenBug(resultDir, caseId)
+ zentaoService.CommitBug(bug, stepIds)
+}
diff --git a/src/atf.go b/src/atf.go
index 3c36300c..f6fcd594 100644
--- a/src/atf.go
+++ b/src/atf.go
@@ -20,6 +20,7 @@ func main() {
var task string
var suite string
var result string
+ var caseId string
flagSet := flag.NewFlagSet("atf", flag.ContinueOnError)
@@ -49,6 +50,9 @@ func main() {
flagSet.StringVar(&keywords, "k", "", "")
flagSet.StringVar(&keywords, "keywords", "", "")
+ flagSet.StringVar(&caseId, "c", "", "")
+ flagSet.StringVar(&caseId, "case", "", "")
+
switch os.Args[1] {
case "run":
files, idx := commonUtils.GetFilesFromParams(os.Args[2:])
@@ -80,6 +84,12 @@ func main() {
action.CommitResult(files)
}
+ case "bug":
+ files, idx := commonUtils.GetFilesFromParams(os.Args[2:])
+ if err := flagSet.Parse(os.Args[idx+1:]); err == nil {
+ action.CommitBug(files, caseId)
+ }
+
case "ls":
files, idx := commonUtils.GetFilesFromParams(os.Args[2:])
if err := flagSet.Parse(os.Args[idx+1:]); err == nil {
diff --git a/src/model/config.go b/src/model/config.go
index 3a572750..56ca5497 100644
--- a/src/model/config.go
+++ b/src/model/config.go
@@ -6,7 +6,4 @@ type Config struct {
Url string
Account string
Password string
-
- ProductId int
- ProjectId int
}
diff --git a/src/model/testing.go b/src/model/testing.go
index 45d8de26..6fa0e69e 100644
--- a/src/model/testing.go
+++ b/src/model/testing.go
@@ -110,11 +110,9 @@ type TestReport struct {
type CaseLog struct {
Id int
ProductId int
- TaskId int
- //ZentaoResultId int
- Path string
- Status string
- Title string
+ Path string
+ Status string
+ Title string
Steps []StepLog
}
diff --git a/src/service/zentao/bug.go b/src/service/zentao/bug.go
index b9d01780..33be71ef 100644
--- a/src/service/zentao/bug.go
+++ b/src/service/zentao/bug.go
@@ -6,6 +6,7 @@ import (
"github.com/easysoft/zentaoatf/src/model"
"github.com/easysoft/zentaoatf/src/service/client"
testingService "github.com/easysoft/zentaoatf/src/service/testing"
+ configUtils "github.com/easysoft/zentaoatf/src/utils/config"
i118Utils "github.com/easysoft/zentaoatf/src/utils/i118"
"github.com/easysoft/zentaoatf/src/utils/log"
"github.com/easysoft/zentaoatf/src/utils/vari"
@@ -14,14 +15,16 @@ import (
"strings"
)
-func GenBug(resultDir string) (model.Bug, string) {
- //conf := configUtils.ReadCurrConfig()
- productId := 0 // conf.ProductId
- projectId := 0 // conf.ProjectId
+func GenBug(resultDir string, caseIdStr string) (model.Bug, string) {
+ caseId, err := strconv.Atoi(caseIdStr)
+
+ if err != nil {
+ return model.Bug{}, ""
+ }
report := testingService.GetTestTestReportForSubmit(resultDir)
for _, cs := range report.Cases {
- if cs.Id != vari.CurrCaseId {
+ if cs.Id != caseId {
continue
}
@@ -32,11 +35,8 @@ func GenBug(resultDir string) (model.Bug, string) {
severity := GetFirstNoEmptyVal(vari.ZentaoBugFileds.Severities)
priority := GetFirstNoEmptyVal(vari.ZentaoBugFileds.Priorities)
- product := productId
- project := projectId
+ product := cs.ProductId
caseId := cs.Id
- //Result := cs.ZentaoResultId
- taskId := cs.TaskId
uid := uuid.NewV4().String()
caseVersion := "0"
@@ -55,9 +55,8 @@ func GenBug(resultDir string) (model.Bug, string) {
bug := model.Bug{Title: title,
Module: module, Type: typ, OpenedBuild: openedBuild, Severity: severity, Pri: priority,
- Product: strconv.Itoa(product), Project: strconv.Itoa(project), Case: strconv.Itoa(caseId),
- //Result: strconv.Itoa(Result),
- Testtask: strconv.Itoa(taskId), Steps: strings.Join(steps, "
"),
+ Product: strconv.Itoa(product), Project: "0", Case: strconv.Itoa(caseId),
+ Testtask: "0", Steps: strings.Join(steps, "
"),
Uid: uid, CaseVersion: caseVersion, OldTaskID: oldTaskID,
}
return bug, stepIds
@@ -67,17 +66,19 @@ func GenBug(resultDir string) (model.Bug, string) {
return model.Bug{}, ""
}
-func SubmitBug(bug model.Bug, idInTask string, stepIds string) bool {
- //conf := configUtils.ReadCurrConfig()
- Login("conf.Url", "conf.Account", "conf.Password")
+func CommitBug(bug model.Bug, stepIds string) bool {
+ // TODO: open cui
+
+ conf := configUtils.ReadCurrConfig()
+ Login(conf.Url, conf.Account, conf.Password)
productId := bug.Product
projectId := bug.Project
// bug-create-1-0-caseID=1,version=3,resultID=93,runID=0,stepIdList=9_12_
// bug-create-1-0-caseID=1,version=3,resultID=84,runID=6,stepIdList=9_12_,testtask=2,projectID=1,buildID=1
- params := fmt.Sprintf("caseID=%s,version=0,resultID=%s,runID=%s,stepIdList=%s",
- bug.Case, bug.Result, idInTask, stepIds)
+ params := fmt.Sprintf("caseID=%s,version=0,resultID=%s,runID=0,stepIdList=%s",
+ bug.Case, bug.Result, stepIds)
bug.Steps = strings.Replace(bug.Steps, " ", " ", -1)
if bug.Testtask != "" {
@@ -93,7 +94,7 @@ func SubmitBug(bug model.Bug, idInTask string, stepIds string) bool {
json, _ := simplejson.NewJson([]byte(body))
msg, _ := json.Get("message").String()
if ok && msg == "" {
- logUtils.PrintToCmd(i118Utils.I118Prt.Sprintf("success_to_report_bug", bug.Case, idInTask) + "\n")
+ logUtils.PrintToCmd(i118Utils.I118Prt.Sprintf("success_to_report_bug", bug.Case) + "\n")
return true
} else {
diff --git a/src/service/zentao/field.go b/src/service/zentao/field.go
index 7071ddb4..a724716b 100644
--- a/src/service/zentao/field.go
+++ b/src/service/zentao/field.go
@@ -18,7 +18,7 @@ func GetBugFiledOptions() {
conf := configUtils.ReadCurrConfig()
Login(conf.Url, conf.Account, conf.Password)
- params := fmt.Sprintf("%d-%d", conf.ProductId, conf.ProjectId)
+ params := fmt.Sprintf("%d-%0", conf.ProductId)
url := "conf.Url" + zentaoUtils.GenApiUri("bug", "ajaxGetBugFieldOptions", params)
dataStr, ok := client.Get(url, nil)
diff --git a/src/ui/page/pageReportBug.go b/src/ui/page/pageReportBug.go
index f7bfc0e4..6cb3ac8d 100644
--- a/src/ui/page/pageReportBug.go
+++ b/src/ui/page/pageReportBug.go
@@ -26,7 +26,7 @@ func InitReportBugPage() error {
zentaoService.GetBugFiledOptions()
- bug, idInTask, stepIds = zentaoService.SubmitBug()
+ bug, idInTask, stepIds = zentaoService.CommitBug()
maxX, maxY := vari.Cui.Size()
pageWidth := 120
@@ -172,7 +172,7 @@ func reportBug(g *gocui.Gui, v *gocui.View) error {
bug.Pri = zentaoService.GetIdByName(priorityStr, vari.ZentaoBugFileds.Priorities)
logUtils.PrintStructToCmd(bug)
- ret := zentaoService.SubmitBug(bug, idInTask, stepIds)
+ ret := zentaoService.CommitBug(bug, idInTask, stepIds)
if ret {
DestoryReportBugPage()
diff --git a/src/utils/config/config.go b/src/utils/config/config.go
index 7d0f4c07..a023d061 100644
--- a/src/utils/config/config.go
+++ b/src/utils/config/config.go
@@ -113,6 +113,10 @@ func ConfigForDir(dir *string, entity string) {
*dir = getInput("is_dir", "enter_dir", i118Utils.I118Prt.Sprintf(entity))
}
+func ConfigForInt(in *string, entity string) {
+ *in = getInput("\\d+", "enter_id", i118Utils.I118Prt.Sprintf(entity))
+}
+
func getInput(regx string, fmtStr string, params ...interface{}) string {
var ret string
diff --git a/src/utils/const/const.go b/src/utils/const/const.go
index 49ad5294..4142e6fe 100644
--- a/src/utils/const/const.go
+++ b/src/utils/const/const.go
@@ -36,4 +36,39 @@ var (
CuiRunOutputView = "panelFileContent"
RequestTypePathInfo = "PATH_INFO"
+
+ Usage = `
+ help 查看使用帮助。
+ set 全局设置语言、禅道站点连接参数。
+ co checkout 导出禅道系统中的用例,已存在的将更新标题和步骤描述。可指定产品、套件、测试单编号。
+ up update 从禅道系统更新已存在的用例。可指定产品、模块、套件、测试单编号。
+ run 执行测试用例。可指定目录、套件、脚本、测试结果文件的路径,也支持套件和任务的编号,多个参数之间用空格隔开。
+ ci commit 将执行结果提交到禅道系统中。可指定测试日志目录,会弹出命令行图形界面。
+ bug 将执行结果中的失败用例,作为缺陷提交到餐到系统。可指定测试日志目录和用例编号,弹出命令行图形界面。
+ ls list 查看测试用例列表。可指定目录和文件的列表,之间用空格隔开。
+ view 查看测试用例详情。可指定目录和文件的列表,之间用空格隔开。
+`
+
+ Example = `
+ $>atf.exe run -f scripts-demo/tc-01.bat 执行本项目自带的测试用,非windows系统使用tc-01.sh脚本
+
+ $>atf.exe co 交互式导出测试用例,将提示用户输入导出类型和编号。
+ $>atf.exe co -p 1 -l python 从禅道导出编号为1的产品测试用例,使用python语言。
+ $>atf.exe co -p 1 -m 16 -l python 从禅道导出产品编号为1、模块编号为16的测试用例。
+ $>atf.exe co -s 1 -l python 从禅道导出编号为1的套件所含测试用例。
+ $>atf.exe co -t 1 -l python 从禅道导出编号为1的测试单所含用例。
+
+ $>atf.exe run dir1 dir2 tc01.py 执行目录dir1和dir2目录下,以及tc01.py文件的用例
+ $>atf.exe run c:\scripts -s 1 执行禅道系统中编号为1的套件所含用例,脚本在目录c:\scripts中
+ $>atf.exe run c:\scripts -s all.cs 执行本机all.cs套件下的所有用例
+ $>atf.exe run c:\scripts -t 1 执行禅道系统中编号为1的任务所含用例
+ $>atf.exe run c:\scripts -r c:\19-08-27\result.txt 执行指定结果文件中失败的用例,脚本在目录c:\scripts中
+
+ $>atf.exe ci logs/2019-08-28T164819 提交指定路径的测试结果到禅道系统
+ $>atf.exe bug logs/2019-08-28T164819 -c 16 将测试结果中失败的用例提交为缺陷
+
+ $>atf.exe list dir1 . 列出目录dir1,以及当前目录下的所有脚本文件
+ $>atf.exe view tc01.py tc02.py 查看指定路径的测试脚本
+
+`
)
diff --git a/src/utils/log/print.go b/src/utils/log/print.go
index 7efc6a57..1efc93d9 100644
--- a/src/utils/log/print.go
+++ b/src/utils/log/print.go
@@ -3,6 +3,7 @@ package logUtils
import (
"encoding/json"
"fmt"
+ constant "github.com/easysoft/zentaoatf/src/utils/const"
stringUtils "github.com/easysoft/zentaoatf/src/utils/string"
"github.com/easysoft/zentaoatf/src/utils/vari"
"github.com/fatih/color"
@@ -10,44 +11,11 @@ import (
)
func PrintUsage() {
- usage :=
- `
- help 查看使用帮助。
- set 全局设置语言、禅道站点连接参数。
- co checkout 导出禅道系统中的用例,已存在的将更新标题和步骤描述。可指定产品、套件、测试单编号。
- up update 从禅道系统更新已存在的用例。可指定产品、模块、套件、测试单编号。
- run 执行测试用例。可指定目录、套件、脚本、测试结果文件的路径,也支持套件和任务的编号,多个参数之间用空格隔开。
- ci commit 将执行结果提交到禅道系统中。可指定测试日志目录,会弹出命令行图形界面。
- bug 将执行结果中的失败用例,作为缺陷提交到餐到系统。可指定测试日志目录和用例编号,弹出命令行图形界面。
- ls list 查看测试用例列表。可指定目录和文件的列表,之间用空格隔开。
- view 查看测试用例详情。可指定目录和文件的列表,之间用空格隔开。
-`
-
- example :=
- `
- $>atf.exe run -f scripts-demo/tc-01.bat 执行本项目自带的测试用,非windows系统使用tc-01.sh脚本
-
- $>atf.exe co 交互式导出测试用例,将提示用户输入导出类型和编号。
- $>atf.exe co -p 1 -l python 从禅道导出编号为1的产品测试用例,使用python语言。
- $>atf.exe co -p 1 -m 16 -l python 从禅道导出产品编号为1、模块编号为16的测试用例。
- $>atf.exe co -s 1 -l python 从禅道导出编号为1的套件所含测试用例。
- $>atf.exe co -t 1 -l python 从禅道导出编号为1的测试单所含用例。
-
- $>atf.exe run dir1 dir2 tc01.py 执行目录dir1和dir2目录下,以及tc01.py文件的用例
- $>atf.exe run c:\scripts -s 1 执行禅道系统中编号为1的套件所含用例,脚本在目录c:\scripts中
- $>atf.exe run c:\scripts -s all.cs 执行本机all.cs套件下的所有用例
- $>atf.exe run c:\scripts -t 1 执行禅道系统中编号为1的任务所含用例
- $>atf.exe run c:\scripts -r c:\19-08-27\result.txt 执行指定结果文件中失败的用例,脚本在目录c:\scripts中
- $>atf.exe list dir1 . 列出目录dir1,以及当前目录下的所有脚本文件
- $>atf.exe view tc01.py tc02.py 查看指定路径的测试脚本
-
-`
-
fmt.Println(color.CyanString("\nUsage: "))
- fmt.Fprintf(color.Output, "%s\n", usage)
+ fmt.Fprintf(color.Output, "%s\n", constant.Usage)
fmt.Println(color.CyanString("Example: "))
- fmt.Fprintf(color.Output, "%s\n", example)
+ fmt.Fprintf(color.Output, "%s\n", constant.Example)
}
func PrintToSide(msg string) {
--
GitLab