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

Merge remote-tracking branch 'origin/master'

......@@ -52,6 +52,7 @@ print(">> $title\n");
$driver->close();
exec('taskkill /F /im chrome80.exe');
function isWindows() {
function isWindows()
{
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}
\ No newline at end of file
......@@ -16,5 +16,4 @@ func CommitZTFTestResult(files []string, noNeedConfirm bool) {
resultDir = fileUtils.UpdateDir(resultDir)
zentaoService.CommitZTFTestResult(resultDir, noNeedConfirm)
}
......@@ -265,3 +265,49 @@ type GTestSuites struct {
Duration int
}
// cppunit xml
type CppUnitSuites struct {
XMLName xml.Name `xml:"TestRun"`
SuccessfulTests struct {
TestCases []CppUnitTest `json:"test" xml:"Test"`
} `json:"successfulTests" xml:"SuccessfulTests"`
FailedTests struct {
TestCases []CppUnitTest `json:"test" xml:"FailedTest"`
} `json:"failedTests" xml:"FailedTests"`
Duration int
}
type CppUnitTest struct {
Id int `json:"id" xml:"Id,attr"`
Title string `json:"name" xml:"Name"`
FailureType string `json:"failureType" xml:"FailureType"`
Message string `json:"message" xml:"Message"`
Location []struct {
File string `json:"file" xml:"File"`
Line string `json:"line" xml:"Line"`
} `json:"location" xml:"Location"`
Duration int
}
// qtest xml
type QTestSuites struct {
XMLName xml.Name `xml:"testsuite"`
Name string `json:"name" xml:"name,attr"`
TestCases []struct {
Title string `json:"name" xml:"name,attr"`
Result string `json:"result" xml:"result,attr"`
Failure *struct {
Type string `json:"type" xml:"tag,attr"`
Desc string `json:"desc" xml:"message,attr"`
} `json:"failure" xml:"failure"`
} `json:"testCases" xml:"testcase"`
Properties Properties `json:"properties" xml:"properties"`
Duration int
}
......@@ -2,8 +2,6 @@ package client
import (
"encoding/json"
"fmt"
"github.com/ajg/form"
"github.com/easysoft/zentaoatf/src/model"
constant "github.com/easysoft/zentaoatf/src/utils/const"
"github.com/easysoft/zentaoatf/src/utils/log"
......@@ -93,19 +91,20 @@ func PostObject(url string, params interface{}) (string, bool) {
} else {
url = url + "&" + vari.SessionVar + "=" + vari.SessionId
}
url = url + "&XDEBUG_SESSION_START=PHPSTORM"
val, _ := json.Marshal(params)
if vari.Verbose {
logUtils.PrintToCmd(url, -1)
logUtils.PrintToCmd(fmt.Sprintf("%+v", params), -1)
logUtils.PrintToCmd(string(val), -1)
}
client := &http.Client{}
val, _ := form.EncodeToString(params)
// convert data to post fomat
re3, _ := regexp.Compile(`([^&]*?)=`)
data := re3.ReplaceAllStringFunc(val, replacePostData)
data := re3.ReplaceAllStringFunc(string(val), replacePostData)
req, reqErr := http.NewRequest("POST", url, strings.NewReader(data))
if reqErr != nil {
......@@ -116,6 +115,7 @@ func PostObject(url string, params interface{}) (string, bool) {
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
//req.Header.Set("cookie", vari.SessionVar+"="+vari.SessionId)
resp, respErr := client.Do(req)
......
......@@ -57,8 +57,8 @@ func GenUnitTestReport(cases []model.UnitResult, classNameMaxWidth int,
postFix = "."
}
logUtils.ScreenAndResult(time.Now().Format("2006-01-02 15:04:05") + " " +
i118Utils.I118Prt.Sprintf("found_scripts", color.CyanString(strconv.Itoa(len(cases)))) + postFix)
logUtils.ScreenAndResult("\n" + logUtils.GetWholeLine(time.Now().Format("2006-01-02 15:04:05")+" "+
i118Utils.I118Prt.Sprintf("found_scripts", color.CyanString(strconv.Itoa(len(cases))))+postFix, "="))
if report.Total == 0 {
return report
......
......@@ -78,6 +78,20 @@ func RetrieveUnitResult() []model.UnitTestSuite {
if err == nil {
testSuite = ConvertGTestResult(gTestSuite)
}
} else if vari.UnitTestType == "cppunit" {
content = strings.Replace(content, "ISO-8859-1", "UTF-8", -1)
cppUnitSuites := model.CppUnitSuites{}
err = xml.Unmarshal([]byte(content), &cppUnitSuites)
if err == nil {
testSuite = ConvertCppUnitResult(cppUnitSuites)
}
} else if vari.UnitTestType == "qtest" {
qTestSuite := model.QTestSuites{}
err = xml.Unmarshal([]byte(content), &qTestSuite)
if err == nil {
testSuite = ConvertQTestResult(qTestSuite)
}
} else {
testSuite = model.UnitTestSuite{}
err = xml.Unmarshal([]byte(content), &testSuite)
......@@ -230,3 +244,52 @@ func ConvertGTestResult(gTestSuite model.GTestSuites) model.UnitTestSuite {
return testSuite
}
func ConvertCppUnitResult(cppunitSuite model.CppUnitSuites) model.UnitTestSuite {
testSuite := model.UnitTestSuite{}
for _, cs := range cppunitSuite.FailedTests.TestCases {
caseResult := model.UnitResult{}
caseResult.Id = cs.Id
caseResult.Title = cs.Title
fail := model.Failure{}
fail.Type = cs.FailureType
fail.Desc = cs.Message
caseResult.Failure = &fail
testSuite.TestCases = append(testSuite.TestCases, caseResult)
}
for _, cs := range cppunitSuite.SuccessfulTests.TestCases {
caseResult := model.UnitResult{}
caseResult.Id = cs.Id
caseResult.Title = cs.Title
testSuite.TestCases = append(testSuite.TestCases, caseResult)
}
return testSuite
}
func ConvertQTestResult(qTestSuite model.QTestSuites) model.UnitTestSuite {
testSuite := model.UnitTestSuite{}
for _, cs := range qTestSuite.TestCases {
caseResult := model.UnitResult{}
caseResult.TestSuite = qTestSuite.Name
caseResult.Title = cs.Title
caseResult.Status = cs.Result
if cs.Failure != nil {
fail := model.Failure{}
fail.Type = cs.Failure.Type
fail.Desc = cs.Failure.Desc
caseResult.Failure = &fail
}
testSuite.TestCases = append(testSuite.TestCases, caseResult)
}
return testSuite
}
......@@ -22,8 +22,8 @@ func ExeScripts(casesToRun []string, casesToIgnore []string, report *model.TestR
postFix = "."
}
logUtils.ScreenAndResult(now.Format("2006-01-02 15:04:05") + " " +
i118Utils.I118Prt.Sprintf("found_scripts", color.CyanString(strconv.Itoa(len(casesToRun)))) + postFix)
logUtils.ScreenAndResult("\n" + logUtils.GetWholeLine(now.Format("2006-01-02 15:04:05")+" "+
i118Utils.I118Prt.Sprintf("found_scripts", color.CyanString(strconv.Itoa(len(casesToRun))))+postFix, "="))
if len(casesToIgnore) > 0 {
logUtils.ScreenAndResult(" " +
......
package zentaoService
import (
"encoding/json"
"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"
)
func CommitTestResult(report model.TestReport, testTaskId int) {
......@@ -19,18 +20,14 @@ func CommitTestResult(report model.TestReport, testTaskId int) {
report.ZentaoData = os.Getenv("ZENTAO_DATA")
report.BuildUrl = os.Getenv("BUILD_URL")
report.ProductId, _ = strconv.Atoi(vari.ProductId)
report.TaskId = testTaskId
if len(report.ZTFResults) > 0 {
report.ProductId = report.ZTFResults[0].ProductId
}
url := conf.Url + zentaoUtils.GenApiUri("unittest", "commitResult", "")
logUtils.Screen(url)
reportJson, _ := json.Marshal(report)
logUtils.Screen(string(reportJson))
url := conf.Url + zentaoUtils.GenApiUri("ci", "commitResult", "")
resp, ok := client.PostObject(url, report)
if ok {
......@@ -55,6 +52,7 @@ func CommitTestResult(report model.TestReport, testTaskId int) {
}
logUtils.Screen(msg)
logUtils.Screen(logUtils.GetWholeLine("=", "=") + "\n")
if report.Fail > 0 || !ok {
os.Exit(1)
......
......@@ -18,6 +18,7 @@ var (
UnitTestType string
UnitTestTool string
UnitTestResult string
ProductId string
SessionVar string
SessionId string
......
......@@ -158,18 +158,33 @@ func main() {
func run(args []string) {
if len(args) >= 3 && stringUtils.FindInArr(args[2], constant.UnitTestType) { // unit test
// junit -p 1 mvn clean package test
vari.UnitTestType = args[2]
if args[3] == "mvn" {
vari.UnitTestTool = "mvn"
} else {
flagSet.Parse(args[3:])
end := 8
if end > len(args) - 1 {
end = len(args) - 1
}
flagSet.Parse(args[3:end])
start := 3
if vari.UnitTestResult != "" {
start = start + 2
} else {
vari.UnitTestResult = "./"
}
if productId != "" {
start = start + 2
vari.ProductId = productId
}
if vari.Verbose {
start = start + 1
}
if args[start] == "mvn" {
vari.UnitTestTool = "mvn"
}
cmd := strings.Join(args[start:], " ")
action.RunUnitTest(cmd)
} else { // func test
......@@ -177,6 +192,8 @@ func run(args []string) {
err := flagSet.Parse(args[len(files)+2:])
if err == nil {
vari.ProductId = productId
if len(files) == 0 {
files = append(files, ".")
}
......@@ -200,4 +217,4 @@ func init() {
func cleanup() {
color.Unset()
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册