diff --git a/Makefile b/Makefile index 9dda064651a6f75f4aa9740048fe78b39bb17182..cfc11b1dc53f19a1f1279c467e91fb6d570c0aaa 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PROJECT=ztf -VERSION=`head -n 1 VERSION` +VERSION:=$(shell head -n 1 VERSION) ifeq ($(OS),Windows_NT) PLATFORM="Windows" diff --git a/internal/command/action/list.go b/internal/command/action/list.go index d7542f3a712324e8632d4f6115c5e64a31efe441..310c60a46bd5409a8a426d337c7c5ddf70a33685 100644 --- a/internal/command/action/list.go +++ b/internal/command/action/list.go @@ -2,6 +2,7 @@ package action import ( "fmt" + "github.com/easysoft/zentaoatf/pkg/consts" "strconv" "strings" "time" @@ -45,7 +46,7 @@ func List(files []string, keywords string) { total := len(scriptArr) width := strconv.Itoa(len(strconv.Itoa(total))) - logUtils.Info("\n" + time.Now().Format("2006-01-02 15:04:05") + " " + + logUtils.Info("\n" + time.Now().Format(consts.DateTimeFormat) + " " + i118Utils.Sprintf("found_scripts_no_ztf_dir", total, commConsts.WorkDir)) for idx, cs := range scriptArr { diff --git a/internal/command/action/view.go b/internal/command/action/view.go index bb85b2fd344eca3bb2db5996a996436c5a037568..c2360a935e6a735c8bdea32cd922b76d8ae4bc22 100644 --- a/internal/command/action/view.go +++ b/internal/command/action/view.go @@ -5,6 +5,7 @@ import ( commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts" langHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/lang" scriptHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/script" + "github.com/easysoft/zentaoatf/pkg/consts" commonUtils "github.com/easysoft/zentaoatf/pkg/lib/common" fileUtils "github.com/easysoft/zentaoatf/pkg/lib/file" i118Utils "github.com/easysoft/zentaoatf/pkg/lib/i118" @@ -44,7 +45,7 @@ func view(cases []string, keywords string) { total := len(arrs) - logUtils.Info("\n" + time.Now().Format("2006-01-02 15:04:05") + " " + + logUtils.Info("\n" + time.Now().Format(consts.DateTimeFormat) + " " + i118Utils.Sprintf("found_scripts_no_ztf_dir", total, commConsts.WorkDir)) width := len(strconv.Itoa(len(arrs))) diff --git a/internal/pkg/consts/enum.go b/internal/pkg/consts/enum.go index 4a19959248785b5352657d4e849afe5e5b0a8725..d5157e71c51a6af17d3204c3c22c17d5a446688d 100644 --- a/internal/pkg/consts/enum.go +++ b/internal/pkg/consts/enum.go @@ -29,9 +29,9 @@ var ( ErrDirNotEmpty = ResponseCode{1100, "Dir Not Empty Error"} ErrZentaoConfig = ResponseCode{2000, "Zentao Config Error"} ErrZentaoRequest = ResponseCode{3000, "zentao request Error"} - ErrRecordWithSameNameExist = ResponseCode{3010, "Record Exist"} - ErrRecordWithSamePathExist = ResponseCode{3011, "Record Exist"} - ErrRecordWithSameInterpreterExist = ResponseCode{2000, "Record Exist"} + ErrRecordWithSameNameExist = ResponseCode{3010, "Record With Same Name Exist"} + ErrRecordWithSamePathExist = ResponseCode{3011, "Record With Same Path Exist"} + ErrRecordWithSameInterpreterExist = ResponseCode{2000, "Record With Same Interpreter Exist"} ErrRecordNotExist = ResponseCode{4000, "Record Not Found"} ErrRecordNotAllowDelete = ResponseCode{2000, "Record Can Not Delete"} ErrPostParam = ResponseCode{2000, "Parameter Error"} diff --git a/internal/pkg/helper/exec/report-unit.go b/internal/pkg/helper/exec/report-unit.go index 98712fb45393b6eb3bfd3e3d8d63a1b161d82bb6..895302dcb6bb9551f7259fcd8fff101e157ddbe1 100644 --- a/internal/pkg/helper/exec/report-unit.go +++ b/internal/pkg/helper/exec/report-unit.go @@ -431,14 +431,8 @@ func ParserUnitTestResult(testSuites []commDomain.UnitTestSuite) ( idx := 1 for _, suite := range testSuites { - //if suite.Time != 0 && suite.Time { // for junit, there is a time on suite level - // dur += suite.Time - //} - for _, cs := range suite.Cases { - if cs.Id <= 0 { - cs.Id = idx - } + getCaseIdFromName(&cs, idx) if cs.Failure != nil { cs.Status = "fail" @@ -913,3 +907,24 @@ func getZapReport() (ret string) { return } + +func getCaseIdFromName(cs *commDomain.UnitResult, defaultVal int) { + if cs.Cid > 0 { + return + } + + cs.Title = strings.TrimSpace(cs.Title) + + regx := regexp.MustCompile(`^(\d+)\. (.+)`) + arr := regx.FindAllStringSubmatch(cs.Title, -1) + if len(arr) > 0 { + cs.Cid = stringUtils.ParseInt(arr[0][1]) + cs.Title = arr[0][2] + } + + if cs.Cid <= 0 { + cs.Cid = defaultVal + } + + return +} diff --git a/internal/pkg/helper/exec/report-ztf.go b/internal/pkg/helper/exec/report-ztf.go index 9483b055ca7d422b75067f9ebab483c47ffe4c1c..2ac345677da75a2730d29c271647568512a7241c 100644 --- a/internal/pkg/helper/exec/report-ztf.go +++ b/internal/pkg/helper/exec/report-ztf.go @@ -29,6 +29,7 @@ func GenZTFTestReport(report commDomain.ZtfReport, pathMaxWidth int, } default: } + // print failed case failedCount := 0 failedCaseLinesWithCheckpoint := make([]string, 0) diff --git a/internal/pkg/helper/script/parser.go b/internal/pkg/helper/script/parser.go index 48ef9454c4838bf0396f13cd6f7a3ab0bbf83e01..51fe6985f9e205fcb188503daad0aa404f9945c1 100644 --- a/internal/pkg/helper/script/parser.go +++ b/internal/pkg/helper/script/parser.go @@ -433,7 +433,7 @@ func GetCaseInfo(file string) (pass bool, caseId, productId int, title string, t return } - // TODO: deal with old format, will removed + // deal with old format, will be removed isOldFormat := strings.Index(content, "[esac]") > -1 pass = CheckFileContentIsScript(content) if !pass { diff --git a/internal/server/modules/v1/service/job.go b/internal/server/modules/v1/service/job.go index 0594f5ffe5b4198543bb66d004109caf22efcaa2..ab75c0292624aa51ef9454fb68affc6800e8e37b 100644 --- a/internal/server/modules/v1/service/job.go +++ b/internal/server/modules/v1/service/job.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" configHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/config" + "github.com/easysoft/zentaoatf/pkg/consts" i118Utils "github.com/easysoft/zentaoatf/pkg/lib/i118" "path/filepath" "strconv" @@ -203,8 +204,8 @@ func (s *JobService) SubmitJobStatus(job model.Job) (err error) { status := serverDomain.ZentaoJobSubmitReq{ Task: job.Task, Status: job.Status, - StartTime: (*job.StartDate).Format("2006-01-02 15:04:05"), - EndTime: (*job.EndDate).Format("2006-01-02 15:04:05"), + StartTime: (*job.StartDate).Format(consts.DateTimeFormat), + EndTime: (*job.EndDate).Format(consts.DateTimeFormat), RetryTime: job.Retry, Error: "", Data: "", @@ -246,8 +247,8 @@ func (s *JobService) SubmitExecResult(job model.Job, execErr error) (err error) ret := serverDomain.ZentaoJobSubmitReq{ Task: job.Task, Status: job.Status, - StartTime: (*job.StartDate).Format("2006-01-02 15:04:05"), - EndTime: (*job.EndDate).Format("2006-01-02 15:04:05"), + StartTime: (*job.StartDate).Format(consts.DateTimeFormat), + EndTime: (*job.EndDate).Format(consts.DateTimeFormat), RetryTime: job.Retry, Error: fmt.Sprintf("%v", execErr), Data: report, diff --git a/pkg/consts/consts.go b/pkg/consts/consts.go index 8cafbd70b4ec20ef27eb08705cb45ef249403adc..4919db8d67cda9caccc3dbcbcdbabe6ffa0da231 100644 --- a/pkg/consts/consts.go +++ b/pkg/consts/consts.go @@ -34,4 +34,6 @@ var ( Authorization = "Authorization" Bearer = "Bearer" + + DateTimeFormat = "2006-01-02 15:04:05" ) diff --git a/pkg/lib/date/date.go b/pkg/lib/date/date.go index a8ad21a2f28845c85906c53ec8a5514307ddb8b1..fb7ae6c20a0907e05850fe53b6ad218bc63bcd98 100644 --- a/pkg/lib/date/date.go +++ b/pkg/lib/date/date.go @@ -1,13 +1,10 @@ package dateUtils import ( + "github.com/easysoft/zentaoatf/pkg/consts" "time" ) -const ( - dateTimeFormat = "2006-01-02 15:04:05" -) - func DateStr(tm time.Time) string { return tm.Format("2006-01-02") } @@ -24,7 +21,7 @@ func DateTimeStrFmt(tm time.Time, fm string) string { } func DateTimeStr(tm time.Time) string { - return tm.Format("2006-01-02 15:04:05") + return tm.Format(consts.DateTimeFormat) } func DateTimeStrLong(tm time.Time) string { @@ -48,9 +45,9 @@ func DateStrToTimestamp(str string) (int64, error) { } func UnitToDate(unit int64) (date time.Time, err error) { - timeStr := time.Unix(unit, 0).Format(dateTimeFormat) + timeStr := time.Unix(unit, 0).Format(consts.DateTimeFormat) - date, _ = time.ParseInLocation(dateTimeFormat, timeStr, time.Local) + date, _ = time.ParseInLocation(consts.DateTimeFormat, timeStr, time.Local) return } diff --git a/pkg/lib/string/string.go b/pkg/lib/string/string.go index d7a32191cfde71f87b7467512d41ca5badb11b6e..1caf4be008d4a85bb16a10fdb738a462639d3787 100644 --- a/pkg/lib/string/string.go +++ b/pkg/lib/string/string.go @@ -85,6 +85,8 @@ func HashPassword(pwd string) string { } func ParseInt(str string) (ret int) { + str = strings.TrimSpace(str) + ret, _ = strconv.Atoi(str) return }