提交 83816d47 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

success to submit bug

上级 6f14e2fe
......@@ -68,6 +68,7 @@ type CaseLog struct {
ZentaoResultId int
Path string
Status string
Title string
Steps []StepLog
}
......
......@@ -39,7 +39,7 @@ func Get(url string, params map[string]string) (string, bool) {
}
bodyStr, _ := ioutil.ReadAll(resp.Body)
println(string(bodyStr))
printUtils.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 PostJson(url string, params interface{}) (string, bool) {
func PostObject(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)
println(string(bodyStr))
printUtils.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)
println(string(bodyStr))
printUtils.PrintUnicode(bodyStr)
var bodyJson model.ZentaoResponse
json.Unmarshal(bodyStr, &bodyJson)
......
......@@ -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)
}
......
......@@ -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 {
stepList += strconv.Itoa(step.Id) + "_"
stepIds += 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>&nbsp;Checkpoint: %s</p>"+
"<p>&nbsp;&nbsp;Expect</p>"+
"&nbsp;&nbsp;&nbsp;%s"+
"<p>&nbsp;&nbsp;Actual<p/>"+
"&nbsp;&nbsp;&nbsp;%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, stepList)
id, zentaoResultId, idInTask, stepIds)
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.PostStr(url, requestObj)
_, ok := client.PostObject(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))
}
}
}
......@@ -49,7 +49,7 @@ func SubmitResult(assert string, date string) {
}
url := conf.Url + uri
_, ok := client.PostJson(url, requestObj)
_, ok := client.PostObject(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)
}
}
}
......
......@@ -6,5 +6,5 @@ import (
func main() {
zentaoService.Login("http://ztpmp.ngtesting.org/", "admin", "P2ssw0rd")
zentaoService.SubmitResult("scripts/all.suite", "2019-08-15T104735")
zentaoService.SubmitResult("scripts/all.suite", "2019-08-15T170425")
}
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))
}
}
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()
}
}
......@@ -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.
先完成此消息的编辑!
想要评论请 注册