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

get and save last record id after result submition for bug report

上级 daf0331d
......@@ -59,10 +59,11 @@ type TestReport struct {
Cases []CaseLog
}
type CaseLog struct {
Id int
IdInTask int
Path string
Status string
Id int
IdInTask int
ZentaoRunId int
Path string
Status string
Steps []StepLog
}
......
......@@ -2,62 +2,15 @@ package testingService
import (
"encoding/json"
"fmt"
"github.com/easysoft/zentaoatf/src/model"
httpClient "github.com/easysoft/zentaoatf/src/service/client"
scriptService "github.com/easysoft/zentaoatf/src/service/script"
configUtils "github.com/easysoft/zentaoatf/src/utils/config"
constant "github.com/easysoft/zentaoatf/src/utils/const"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
printUtils "github.com/easysoft/zentaoatf/src/utils/print"
"github.com/easysoft/zentaoatf/src/utils/vari"
"os"
"strconv"
"strings"
)
func SubmitResult(assert string, date string) {
conf := configUtils.ReadCurrConfig()
report := GetTestTestReportForSubmit(assert, date)
for _, cs := range report.Cases {
id := cs.Id
runId := cs.IdInTask
var uri string
uri = fmt.Sprintf("testtask-runCase-%d-%d-1.json", runId, id)
requestObj := map[string]string{"case": strconv.Itoa(id), "version": "0"}
for _, step := range cs.Steps {
var stepStatus string
if step.Status {
stepStatus = constant.PASS.String()
} else {
stepStatus = constant.FAIL.String()
}
stepResults := ""
for _, checkpoint := range step.CheckPoints {
stepResults += checkpoint.Actual // strconv.FormatBool(checkpoint.Status) + ": " + checkpoint.Actual
}
requestObj["steps["+strconv.Itoa(step.Id)+"]"] = stepStatus
requestObj["reals["+strconv.Itoa(step.Id)+"]"] = stepResults
}
reqStr, _ := json.Marshal(requestObj)
printUtils.PrintToCmd(string(reqStr))
url := conf.Url + uri
_, ok := httpClient.PostStr(url, requestObj)
if ok {
printUtils.PrintToCmd(fmt.Sprintf("success to submit the results for case %d", id))
}
}
}
func GetTestTestReportForSubmit(assert string, date string) model.TestReport {
mode, name := scriptService.GetRunModeAndName(assert)
resultPath := vari.Prefer.WorkDir + constant.LogDir + scriptService.LogFolder(mode, name, date) +
......@@ -71,3 +24,11 @@ func GetTestTestReportForSubmit(assert string, date string) model.TestReport {
return report
}
func SaveTestTestReportAfterSubmit(assert string, date string, content string) {
mode, name := scriptService.GetRunModeAndName(assert)
resultPath := vari.Prefer.WorkDir + constant.LogDir + scriptService.LogFolder(mode, name, date) +
string(os.PathSeparator) + "result.json"
fileUtils.WriteFile(resultPath, content)
}
package zentaoService
import (
"encoding/json"
"fmt"
"github.com/bitly/go-simplejson"
"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"
"github.com/easysoft/zentaoatf/src/utils/zentao"
"strconv"
)
func SubmitResult(assert string, date string) {
conf := configUtils.ReadCurrConfig()
report := testingService.GetTestTestReportForSubmit(assert, date)
for idx, cs := range report.Cases {
id := cs.Id
idInTask := cs.IdInTask
var uri string
uri = fmt.Sprintf("testtask-runCase-%d-%d-1.json", idInTask, id)
requestObj := map[string]string{"case": strconv.Itoa(id), "version": "0"}
for _, step := range cs.Steps {
var stepStatus string
if step.Status {
stepStatus = constant.PASS.String()
} else {
stepStatus = constant.FAIL.String()
}
stepResults := ""
for _, checkpoint := range step.CheckPoints {
stepResults += checkpoint.Actual // strconv.FormatBool(checkpoint.Status) + ": " + checkpoint.Actual
}
requestObj["steps["+strconv.Itoa(step.Id)+"]"] = stepStatus
requestObj["reals["+strconv.Itoa(step.Id)+"]"] = stepResults
}
reqStr, _ := json.Marshal(requestObj)
printUtils.PrintToCmd(string(reqStr))
url := conf.Url + uri
_, ok := client.PostStr(url, requestObj)
if ok {
resultId := GetLastResult(conf.Url, idInTask, id)
report.Cases[idx].ZentaoRunId = 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))
}
}
}
func GetLastResult(baseUrl string, caseInTaskId int, caseId int) int {
params := fmt.Sprintf("%d-%d-1.json", caseInTaskId, caseId)
url := baseUrl + zentaoUtils.GenApiUri("testtask", "results", params)
dataStr, ok := client.Get(url, nil)
resultId := -1
if ok {
jsonData, err := simplejson.NewJson([]byte(dataStr))
if err == nil {
results, _ := jsonData.Get("results").Map()
for key, _ := range results {
numb, _ := strconv.Atoi(key)
if resultId < numb {
resultId = numb
}
}
}
}
return resultId
}
package main
import (
testingService "github.com/easysoft/zentaoatf/src/service/testing"
zentaoService "github.com/easysoft/zentaoatf/src/service/zentao"
)
func main() {
zentaoService.Login("http://ztpmp.ngtesting.org/", "admin", "P2ssw0rd")
testingService.SubmitResult("scripts/all.suite", "2019-08-15T082332")
zentaoService.SubmitResult("scripts/all.suite", "2019-08-15T090121")
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册