/
testResult.go
83 lines (72 loc) · 2.13 KB
/
testResult.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package zentaoService
import (
"github.com/bitly/go-simplejson"
"github.com/easysoft/zentaoatf/src/model"
"github.com/easysoft/zentaoatf/src/service/client"
configUtils "github.com/easysoft/zentaoatf/src/utils/config"
i118Utils "github.com/easysoft/zentaoatf/src/utils/i118"
logUtils "github.com/easysoft/zentaoatf/src/utils/log"
"github.com/easysoft/zentaoatf/src/utils/vari"
"github.com/easysoft/zentaoatf/src/utils/zentao"
"github.com/fatih/color"
"os"
"strconv"
"strings"
)
func CommitTestResult(report model.TestReport, testTaskId int) {
if vari.ProductId == "" {
if len(report.FuncResult) > 0 {
vari.ProductId = strconv.Itoa(report.FuncResult[0].ProductId)
} else if len(report.UnitResult) > 0 {
vari.ProductId = strconv.Itoa(report.ProductId)
}
}
if report.Total == 0 {
logUtils.Screen(color.CyanString(i118Utils.Sprintf("ignore_to_submit_result_no_result_empty")))
return
}
if vari.ProductId == "" {
logUtils.Screen(color.CyanString(i118Utils.Sprintf("ignore_to_submit_result_no_product_id")))
return
}
conf := configUtils.ReadCurrConfig()
ok := Login(conf.Url, conf.Account, conf.Password)
if !ok {
return
}
report.ZentaoData = os.Getenv("ZENTAO_DATA")
report.BuildUrl = os.Getenv("BUILD_URL")
report.ProductId, _ = strconv.Atoi(vari.ProductId)
report.TaskId = testTaskId
if len(report.FuncResult) > 0 {
report.ProductId = report.FuncResult[0].ProductId
}
url := conf.Url + zentaoUtils.GenApiUri("ci", "commitResult", "")
resp, ok := client.PostObject(url, report, false)
if ok {
json, err1 := simplejson.NewJson([]byte(resp))
if err1 == nil {
result, err2 := json.Get("result").String()
if err2 != nil || result != "success" {
ok = false
}
} else {
ok = false
}
}
msg := "\n"
if ok {
msg += color.GreenString(i118Utils.Sprintf("success_to_submit_test_result"))
} else {
msg = i118Utils.Sprintf("fail_to_submit_test_result")
if strings.Index(resp, "login") > -1 {
msg = i118Utils.Sprintf("fail_to_login")
}
msg = color.RedString(msg)
}
logUtils.Screen(msg)
logUtils.Screen(logUtils.GetWholeLine("=", "=") + "\n")
if report.Fail > 0 || !ok {
os.Exit(1)
}
}