diff --git a/res/messages_en.json b/res/messages_en.json index 7898c4bc4..396216c8b 100644 --- a/res/messages_en.json +++ b/res/messages_en.json @@ -499,6 +499,19 @@ { "id": "fail_md5_check", "translation": "Check file %s MD5 failed." + }, + + { + "id": "fail_to_upload_file", + "translation": "Fail to upload file: %s." + }, + { + "id": "fail_to_parse_upload_file_response", + "translation": "Fail to parse upload file response: %s." + }, + { + "id": "upload_file_result", + "translation": "Upload file result: %s,%s." } ] } diff --git a/res/messages_zh.json b/res/messages_zh.json index 01c6a9dc6..dc2d1543b 100644 --- a/res/messages_zh.json +++ b/res/messages_zh.json @@ -506,6 +506,19 @@ { "id": "fail_md5_check", "translation": "验证文件%s的MD5失败。" + }, + + { + "id": "fail_to_upload_file", + "translation": "上传文件失败:%s。" + }, + { + "id": "fail_to_parse_upload_file_response", + "translation": "解析上传文件响应失败:%s。" + }, + { + "id": "upload_file_result", + "translation": "上传文件响应结果:%s,%s。" } ] } diff --git a/src/action/bug.go b/src/action/bug.go index 9c0d278d9..4ea41d8f5 100644 --- a/src/action/bug.go +++ b/src/action/bug.go @@ -37,7 +37,7 @@ func CommitBug(files []string) { } for { - logUtils.PrintToWithColor("\n"+i118Utils.I118Prt.Sprintf("enter_case_id_for_report_bug"), color.FgCyan) + logUtils.PrintToWithColor("\n"+i118Utils.Sprintf("enter_case_id_for_report_bug"), color.FgCyan) logUtils.PrintToWithColor(strings.Join(lines, "\n"), -1) var caseId string @@ -50,7 +50,7 @@ func CommitBug(files []string) { if stringUtils.FindInArr(caseId, ids) { page.CuiReportBug(resultDir, caseId) } else { - logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("invalid_input"), color.FgRed) + logUtils.PrintToWithColor(i118Utils.Sprintf("invalid_input"), color.FgRed) } } } diff --git a/src/action/clean.go b/src/action/clean.go index beb0c7818..270e65f8a 100644 --- a/src/action/clean.go +++ b/src/action/clean.go @@ -15,5 +15,5 @@ func Clean() { os.RemoveAll(path) os.RemoveAll(bak) - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("success_to_clean_logs")) + logUtils.PrintTo(i118Utils.Sprintf("success_to_clean_logs")) } diff --git a/src/action/expect.go b/src/action/expect.go index a10828ab7..75de50e2d 100644 --- a/src/action/expect.go +++ b/src/action/expect.go @@ -21,7 +21,7 @@ func GenExpectFiles(files []string) error { cases := assertUtils.GetCaseByDirAndFile(files) if len(cases) < 1 { - logUtils.PrintTo("\n" + i118Utils.I118Prt.Sprintf("no_cases")) + logUtils.PrintTo("\n" + i118Utils.Sprintf("no_cases")) return nil } diff --git a/src/action/extract.go b/src/action/extract.go index a2f544990..936941169 100644 --- a/src/action/extract.go +++ b/src/action/extract.go @@ -29,7 +29,7 @@ func Extract(files []string) error { cases := assertUtils.GetCaseByDirAndFile(files) if len(cases) < 1 { - logUtils.PrintTo("\n" + i118Utils.I118Prt.Sprintf("no_cases")) + logUtils.PrintTo("\n" + i118Utils.Sprintf("no_cases")) return nil } diff --git a/src/action/gen.go b/src/action/gen.go index 74fe76dbd..4587c5849 100644 --- a/src/action/gen.go +++ b/src/action/gen.go @@ -57,13 +57,13 @@ func Generate(productId string, moduleId string, suiteId string, taskId string, count, err := scriptUtils.Generate(cases, scriptLang, independentFile, targetDir, byModule, prefix) if err == nil { - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("success_to_generate", count, targetDir) + "\n") + logUtils.PrintTo(i118Utils.Sprintf("success_to_generate", count, targetDir) + "\n") } else { logUtils.PrintToWithColor(err.Error(), color.FgRed) } } else { if !loginFail { - logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("no_cases"), color.FgRed) + logUtils.PrintToWithColor(i118Utils.Sprintf("no_cases"), color.FgRed) } } } diff --git a/src/action/ztfTest.go b/src/action/ztfTest.go index 2ac381e5b..a7726bec4 100644 --- a/src/action/ztfTest.go +++ b/src/action/ztfTest.go @@ -64,7 +64,7 @@ func RunZTFTest(files []string, suiteIdStr, taskIdStr string) error { } if len(cases) < 1 { - logUtils.PrintTo("\n" + i118Utils.I118Prt.Sprintf("no_cases")) + logUtils.PrintTo("\n" + i118Utils.Sprintf("no_cases")) return nil } diff --git a/src/server/service/build.go b/src/server/service/build.go index 9d5ed2cb5..932a10030 100644 --- a/src/server/service/build.go +++ b/src/server/service/build.go @@ -22,14 +22,14 @@ func (s *BuildService) Add(req domain.ReqData) (reply domain.OptResult) { reqStr, _ := json.Marshal(req.Data) err := json.Unmarshal(reqStr, &build) if err != nil { - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("fail_parse_req", err)) + logUtils.PrintTo(i118Utils.Sprintf("fail_parse_req", err)) return } size := s.taskService.GetSize() if size == 0 { s.taskService.Add(build) - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("success_add_tak")) + logUtils.PrintTo(i118Utils.Sprintf("success_add_tak")) reply.Success("Success to add task.") } else { reply.Fail(fmt.Sprintf("Already has %d jobs to be done.", size)) diff --git a/src/server/service/config.go b/src/server/service/config.go index 09ebef655..65c444996 100644 --- a/src/server/service/config.go +++ b/src/server/service/config.go @@ -25,7 +25,7 @@ func (s *ConfigService) Update(req domain.ReqData) { reqStr, _ := json.Marshal(req.Data) err := json.Unmarshal(reqStr, &conf) if err != nil { - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("fail_parse_req", err)) + logUtils.PrintTo(i118Utils.Sprintf("fail_parse_req", err)) return } diff --git a/src/server/service/heartbeat.go b/src/server/service/heartbeat.go index 636974c04..1a3391db7 100644 --- a/src/server/service/heartbeat.go +++ b/src/server/service/heartbeat.go @@ -42,9 +42,9 @@ func (s *HeartBeatService) HeartBeat(isBusy bool) { _, ok := client.PostObject(url, data, false) if ok { - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("success_heart_beat")) + logUtils.PrintTo(i118Utils.Sprintf("success_heart_beat")) } else { - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("fail_heart_beat")) + logUtils.PrintTo(i118Utils.Sprintf("fail_heart_beat")) } return diff --git a/src/server/utils/common/download.go b/src/server/utils/common/download.go index 0f86d2b15..a5a6dd410 100644 --- a/src/server/utils/common/download.go +++ b/src/server/utils/common/download.go @@ -23,19 +23,19 @@ func Download(uri string, dst string) error { res, err := http.Get(uri) if err != nil { - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("download_fail", uri, err.Error())) + logUtils.PrintTo(i118Utils.Sprintf("download_fail", uri, err.Error())) } defer res.Body.Close() bytes, err := ioutil.ReadAll(res.Body) if err != nil { - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("download_read_fail", uri, err.Error())) + logUtils.PrintTo(i118Utils.Sprintf("download_read_fail", uri, err.Error())) } err = ioutil.WriteFile(dst, bytes, 0666) if err != nil { - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("download_write_fail", dst, err.Error())) + logUtils.PrintTo(i118Utils.Sprintf("download_write_fail", dst, err.Error())) } else { - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("download_success", uri, dst)) + logUtils.PrintTo(i118Utils.Sprintf("download_success", uri, dst)) } return err diff --git a/src/service/client/http.go b/src/service/client/http.go index 87edf06a5..050ee625b 100644 --- a/src/service/client/http.go +++ b/src/service/client/http.go @@ -26,13 +26,13 @@ func Get(url string) (string, bool) { } if vari.Verbose { - logUtils.Screen(i118Utils.I118Prt.Sprintf("server_address") + url) + logUtils.Screen(i118Utils.Sprintf("server_address") + url) } req, reqErr := http.NewRequest("GET", url, nil) if reqErr != nil { if vari.Verbose { - logUtils.PrintToCmd(i118Utils.I118Prt.Sprintf("server_return")+reqErr.Error(), color.FgRed) + logUtils.PrintToCmd(i118Utils.Sprintf("server_return")+reqErr.Error(), color.FgRed) } return "", false } @@ -40,14 +40,14 @@ func Get(url string) (string, bool) { resp, respErr := client.Do(req) if respErr != nil { if vari.Verbose { - logUtils.PrintToCmd(i118Utils.I118Prt.Sprintf("server_return")+respErr.Error(), color.FgRed) + logUtils.PrintToCmd(i118Utils.Sprintf("server_return")+respErr.Error(), color.FgRed) } return "", false } bodyStr, _ := ioutil.ReadAll(resp.Body) if vari.Verbose { - logUtils.Screen(i118Utils.I118Prt.Sprintf("server_return") + logUtils.ConvertUnicode(bodyStr)) + logUtils.Screen(i118Utils.Sprintf("server_return") + logUtils.ConvertUnicode(bodyStr)) } var bodyJson model.ZentaoResponse @@ -55,7 +55,7 @@ func Get(url string) (string, bool) { if jsonErr != nil { if strings.Index(string(bodyStr), "") > -1 { if vari.Verbose { - logUtils.Screen(i118Utils.I118Prt.Sprintf("server_return") + " HTML - " + + logUtils.Screen(i118Utils.Sprintf("server_return") + " HTML - " + gohtml.FormatWithLineNo(string(bodyStr))) } return "", false @@ -88,7 +88,7 @@ func PostObject(url string, params interface{}, useFormFormat bool) (string, boo jsonStr, _ := json.Marshal(params) if vari.Verbose { - logUtils.Screen(i118Utils.I118Prt.Sprintf("server_address") + url) + logUtils.Screen(i118Utils.Sprintf("server_address") + url) } client := &http.Client{} @@ -102,13 +102,13 @@ func PostObject(url string, params interface{}, useFormFormat bool) (string, boo } if vari.Verbose { - logUtils.Screen(i118Utils.I118Prt.Sprintf("server_params") + val) + logUtils.Screen(i118Utils.Sprintf("server_params") + val) } req, reqErr := http.NewRequest("POST", url, strings.NewReader(val)) if reqErr != nil { if vari.Verbose { - logUtils.PrintToCmd(i118Utils.I118Prt.Sprintf("server_return")+reqErr.Error(), color.FgRed) + logUtils.PrintToCmd(i118Utils.Sprintf("server_return")+reqErr.Error(), color.FgRed) } return "", false } @@ -118,14 +118,14 @@ func PostObject(url string, params interface{}, useFormFormat bool) (string, boo resp, respErr := client.Do(req) if respErr != nil { if vari.Verbose { - logUtils.PrintToCmd(i118Utils.I118Prt.Sprintf("server_return")+respErr.Error(), color.FgRed) + logUtils.PrintToCmd(i118Utils.Sprintf("server_return")+respErr.Error(), color.FgRed) } return "", false } bodyStr, _ := ioutil.ReadAll(resp.Body) if vari.Verbose { - logUtils.Screen(i118Utils.I118Prt.Sprintf("server_return") + logUtils.ConvertUnicode(bodyStr)) + logUtils.Screen(i118Utils.Sprintf("server_return") + logUtils.ConvertUnicode(bodyStr)) } var bodyJson model.ZentaoResponse @@ -133,13 +133,13 @@ func PostObject(url string, params interface{}, useFormFormat bool) (string, boo if jsonErr != nil { if strings.Index(string(bodyStr), "") > -1 { // some api return a html if vari.Verbose { - logUtils.Screen(i118Utils.I118Prt.Sprintf("server_return") + " HTML - " + + logUtils.Screen(i118Utils.Sprintf("server_return") + " HTML - " + gohtml.FormatWithLineNo(string(bodyStr))) } return string(bodyStr), true } else { if vari.Verbose { - logUtils.PrintToCmd(i118Utils.I118Prt.Sprintf("server_return")+jsonErr.Error(), color.FgRed) + logUtils.PrintToCmd(i118Utils.Sprintf("server_return")+jsonErr.Error(), color.FgRed) } return "", false } @@ -158,7 +158,7 @@ func PostObject(url string, params interface{}, useFormFormat bool) (string, boo func PostStr(url string, params map[string]string) (msg string, ok bool) { if vari.Verbose { - logUtils.Screen(i118Utils.I118Prt.Sprintf("server_address") + url) + logUtils.Screen(i118Utils.Sprintf("server_address") + url) } client := &http.Client{} @@ -173,7 +173,7 @@ func PostStr(url string, params map[string]string) (msg string, ok bool) { } if vari.Verbose { - logUtils.Screen(i118Utils.I118Prt.Sprintf("server_params") + paramStr) + logUtils.Screen(i118Utils.Sprintf("server_params") + paramStr) } req, reqErr := http.NewRequest("POST", url, strings.NewReader(paramStr)) @@ -199,7 +199,7 @@ func PostStr(url string, params map[string]string) (msg string, ok bool) { bodyStr, _ := ioutil.ReadAll(resp.Body) if vari.Verbose { - logUtils.Screen(i118Utils.I118Prt.Sprintf("server_return") + logUtils.ConvertUnicode(bodyStr)) + logUtils.Screen(i118Utils.Sprintf("server_return") + logUtils.ConvertUnicode(bodyStr)) } var bodyJson model.ZentaoResponse diff --git a/src/service/script/generator.go b/src/service/script/generator.go index 6ffd9d9dc..b3c705d13 100644 --- a/src/service/script/generator.go +++ b/src/service/script/generator.go @@ -55,7 +55,7 @@ func GenerateTestCaseScript(cs model.TestCase, langType string, independentFile steps := make([]string, 0) independentExpects := make([]string, 0) srcCode := fmt.Sprintf("%s %s", langUtils.LangMap[langType]["commentsTag"], - i118Utils.I118Prt.Sprintf("find_example", string(os.PathSeparator), langType)) + i118Utils.Sprintf("find_example", string(os.PathSeparator), langType)) info = append(info, fmt.Sprintf("title=%s", caseTitle)) info = append(info, fmt.Sprintf("cid=%s", caseId)) diff --git a/src/service/script/sort.go b/src/service/script/sort.go index a461008b2..d4f8b1ee1 100644 --- a/src/service/script/sort.go +++ b/src/service/script/sort.go @@ -11,5 +11,5 @@ func Sort(cases []string) { scriptUtils.SortFile(file) } - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("success_sort_steps", len(cases))) + logUtils.PrintTo(i118Utils.Sprintf("success_sort_steps", len(cases))) } diff --git a/src/service/script/viewer.go b/src/service/script/viewer.go index 8eaf4892d..eb097e3a9 100644 --- a/src/service/script/viewer.go +++ b/src/service/script/viewer.go @@ -45,7 +45,7 @@ func List(cases []string, keywords string) { width := strconv.Itoa(len(strconv.Itoa(total))) logUtils.Screen(time.Now().Format("2006-01-02 15:04:05") + " " + - i118Utils.I118Prt.Sprintf("found_scripts", color.CyanString(strconv.Itoa(total))) + "\n") + i118Utils.Sprintf("found_scripts", color.CyanString(strconv.Itoa(total))) + "\n") for idx, cs := range scriptArr { //format := "(%" + width + "d/%d) [%s] %d.%s" @@ -104,7 +104,7 @@ func View(cases []string, keywords string) { total := len(arrs) - logUtils.Screen(time.Now().Format("2006-01-02 15:04:05") + " " + i118Utils.I118Prt.Sprintf("found_scripts", + logUtils.Screen(time.Now().Format("2006-01-02 15:04:05") + " " + i118Utils.Sprintf("found_scripts", color.CyanString(strconv.Itoa(total)))) width := len(strconv.Itoa(len(arrs))) diff --git a/src/service/testing/unitTestReport.go b/src/service/testing/unitTestReport.go index f836319f5..1954a62d5 100644 --- a/src/service/testing/unitTestReport.go +++ b/src/service/testing/unitTestReport.go @@ -68,9 +68,9 @@ func GenUnitTestReport(cases []model.UnitResult, classNameMaxWidth int, timeVal } logUtils.Result("\n" + logUtils.GetWholeLine(time.Now().Format("2006-01-02 15:04:05")+" "+ - i118Utils.I118Prt.Sprintf("found_scripts", strconv.Itoa(len(cases)))+postFix, "=")) + i118Utils.Sprintf("found_scripts", strconv.Itoa(len(cases)))+postFix, "=")) logUtils.Screen("\n" + logUtils.GetWholeLine(time.Now().Format("2006-01-02 15:04:05")+" "+ - i118Utils.I118Prt.Sprintf("found_scripts", color.CyanString(strconv.Itoa(len(cases))))+postFix, "=")) + i118Utils.Sprintf("found_scripts", color.CyanString(strconv.Itoa(len(cases))))+postFix, "=")) if report.Total == 0 { return report @@ -84,11 +84,11 @@ func GenUnitTestReport(cases []model.UnitResult, classNameMaxWidth int, timeVal format := "(%" + width + "d/%d) %s [%s] [%" + width + "d. %s] (%.3fs)" logUtils.Screen(fmt.Sprintf(format, idx+1, report.Total, statusColor, testSuite, cs.Id, cs.Title, cs.Duration)) logUtils.Result(fmt.Sprintf(format, idx+1, report.Total, - i118Utils.I118Prt.Sprintf(cs.Status), testSuite, cs.Id, cs.Title, cs.Duration)) + i118Utils.Sprintf(cs.Status), testSuite, cs.Id, cs.Title, cs.Duration)) } if report.Fail > 0 { - logUtils.ScreenAndResult("\n" + i118Utils.I118Prt.Sprintf("failed_scripts")) + logUtils.ScreenAndResult("\n" + i118Utils.Sprintf("failed_scripts")) logUtils.Screen(strings.Join(failedCaseLines, "\n")) logUtils.Result(strings.Join(failedCaseLinesDesc, "\n")) } @@ -99,13 +99,13 @@ func GenUnitTestReport(cases []model.UnitResult, classNameMaxWidth int, timeVal } fmtStr := "%d(%.1f%%) %s" - passStr := fmt.Sprintf(fmtStr, report.Pass, float32(report.Pass*100/report.Total), i118Utils.I118Prt.Sprintf("pass")) - failStr := fmt.Sprintf(fmtStr, report.Fail, float32(report.Fail*100/report.Total), i118Utils.I118Prt.Sprintf("fail")) - skipStr := fmt.Sprintf(fmtStr, report.Skip, float32(report.Skip*100/report.Total), i118Utils.I118Prt.Sprintf("skip")) + passStr := fmt.Sprintf(fmtStr, report.Pass, float32(report.Pass*100/report.Total), i118Utils.Sprintf("pass")) + failStr := fmt.Sprintf(fmtStr, report.Fail, float32(report.Fail*100/report.Total), i118Utils.Sprintf("fail")) + skipStr := fmt.Sprintf(fmtStr, report.Skip, float32(report.Skip*100/report.Total), i118Utils.Sprintf("skip")) // 输出到文件 logUtils.Result("\n" + time.Now().Format("2006-01-02 15:04:05") + " " + - i118Utils.I118Prt.Sprintf("run_scripts", + i118Utils.Sprintf("run_scripts", report.Total, report.Duration, secTag, passStr, failStr, skipStr, " "+vari.LogDir+"result.txt ", @@ -113,7 +113,7 @@ func GenUnitTestReport(cases []model.UnitResult, classNameMaxWidth int, timeVal // 输出到屏幕 logUtils.Screen("\n" + time.Now().Format("2006-01-02 15:04:05") + " " + - i118Utils.I118Prt.Sprintf("run_scripts", + i118Utils.Sprintf("run_scripts", report.Total, report.Duration, secTag, color.GreenString(passStr), color.RedString(failStr), color.YellowString(skipStr), " "+vari.LogDir+"result.txt ", diff --git a/src/service/testing/ztfCheck.go b/src/service/testing/ztfCheck.go index f85186a2e..9244b7ea5 100644 --- a/src/service/testing/ztfCheck.go +++ b/src/service/testing/ztfCheck.go @@ -117,7 +117,7 @@ func ValidateCaseResult(scriptFile string, langType string, format := "(%" + width + "d/%d) %s [%s] [%" + numbWidth + "d. %s] (%ss)" logUtils.Screen(fmt.Sprintf(format, idx+1, total, statusColor, path, cs.Id, cs.Title, secs)) - logUtils.Result(fmt.Sprintf(format, idx+1, total, i118Utils.I118Prt.Sprintf(cs.Status), path, cs.Id, cs.Title, secs)) + logUtils.Result(fmt.Sprintf(format, idx+1, total, i118Utils.Sprintf(cs.Status), path, cs.Id, cs.Title, secs)) } func ValidateStepResult(langType string, expectLines []string, actualLines []string) (bool, []model.CheckPointLog) { diff --git a/src/service/testing/ztfExec.go b/src/service/testing/ztfExec.go index 4d432b273..2fc0b8c20 100644 --- a/src/service/testing/ztfExec.go +++ b/src/service/testing/ztfExec.go @@ -23,15 +23,15 @@ func ExeScripts(casesToRun []string, casesToIgnore []string, report *model.TestR } logUtils.Result("\n" + logUtils.GetWholeLine(now.Format("2006-01-02 15:04:05")+" "+ - i118Utils.I118Prt.Sprintf("found_scripts", strconv.Itoa(len(casesToRun)))+postFix, "=")) + i118Utils.Sprintf("found_scripts", strconv.Itoa(len(casesToRun)))+postFix, "=")) logUtils.Screen("\n" + logUtils.GetWholeLine(now.Format("2006-01-02 15:04:05")+" "+ - i118Utils.I118Prt.Sprintf("found_scripts", color.CyanString(strconv.Itoa(len(casesToRun))))+postFix, "=")) + i118Utils.Sprintf("found_scripts", color.CyanString(strconv.Itoa(len(casesToRun))))+postFix, "=")) if len(casesToIgnore) > 0 { logUtils.Result(" " + - i118Utils.I118Prt.Sprintf("ignore_scripts", strconv.Itoa(len(casesToIgnore))) + postFix) + i118Utils.Sprintf("ignore_scripts", strconv.Itoa(len(casesToIgnore))) + postFix) logUtils.Screen(" " + - i118Utils.I118Prt.Sprintf("ignore_scripts", color.CyanString(strconv.Itoa(len(casesToIgnore)))) + postFix) + i118Utils.Sprintf("ignore_scripts", color.CyanString(strconv.Itoa(len(casesToIgnore)))) + postFix) } for idx, file := range casesToRun { diff --git a/src/service/testing/ztfTestReport.go b/src/service/testing/ztfTestReport.go index aac162f5c..762e025ee 100644 --- a/src/service/testing/ztfTestReport.go +++ b/src/service/testing/ztfTestReport.go @@ -58,7 +58,7 @@ func GenZTFTestReport(report model.TestReport, pathMaxWidth int) { stepNumb++ step.Id = strings.TrimRight(step.Id, ".") - status := i118Utils.I118Prt.Sprintf(commonUtils.BoolToPass(step.Status)) + status := i118Utils.Sprintf(commonUtils.BoolToPass(step.Status)) failedCaseLinesWithCheckpoint = append(failedCaseLinesWithCheckpoint, fmt.Sprintf("Step %s: %s", step.Id, status)) for idx1, cp := range step.CheckPoints { @@ -72,12 +72,12 @@ func GenZTFTestReport(report model.TestReport, pathMaxWidth int) { } } } else { - failedCaseLinesWithCheckpoint = append(failedCaseLinesWithCheckpoint, " "+i118Utils.I118Prt.Sprintf("no_checkpoints")) + failedCaseLinesWithCheckpoint = append(failedCaseLinesWithCheckpoint, " "+i118Utils.Sprintf("no_checkpoints")) } } } if failedCount > 0 { - logUtils.ScreenAndResult("\n" + i118Utils.I118Prt.Sprintf("failed_scripts")) + logUtils.ScreenAndResult("\n" + i118Utils.Sprintf("failed_scripts")) logUtils.Screen(strings.Join(failedCaseLines, "\n")) logUtils.Result(strings.Join(failedCaseLinesWithCheckpoint, "\n")) } @@ -89,20 +89,20 @@ func GenZTFTestReport(report model.TestReport, pathMaxWidth int) { // 生成统计行 fmtStr := "%d(%.1f%%) %s" - passStr := fmt.Sprintf(fmtStr, report.Pass, float32(report.Pass*100/report.Total), i118Utils.I118Prt.Sprintf("pass")) - failStr := fmt.Sprintf(fmtStr, report.Fail, float32(report.Fail*100/report.Total), i118Utils.I118Prt.Sprintf("fail")) - skipStr := fmt.Sprintf(fmtStr, report.Skip, float32(report.Skip*100/report.Total), i118Utils.I118Prt.Sprintf("skip")) + passStr := fmt.Sprintf(fmtStr, report.Pass, float32(report.Pass*100/report.Total), i118Utils.Sprintf("pass")) + failStr := fmt.Sprintf(fmtStr, report.Fail, float32(report.Fail*100/report.Total), i118Utils.Sprintf("fail")) + skipStr := fmt.Sprintf(fmtStr, report.Skip, float32(report.Skip*100/report.Total), i118Utils.Sprintf("skip")) // 打印到结果文件 logUtils.Result("\n" + time.Now().Format("2006-01-02 15:04:05") + " " + - i118Utils.I118Prt.Sprintf("run_scripts", + i118Utils.Sprintf("run_scripts", report.Total, report.Duration, secTag, passStr, failStr, skipStr, " "+vari.LogDir+"result.txt ", )) // 打印到屏幕 logUtils.Screen("\n" + time.Now().Format("2006-01-02 15:04:05") + " " + - i118Utils.I118Prt.Sprintf("run_scripts", + i118Utils.Sprintf("run_scripts", report.Total, report.Duration, secTag, color.GreenString(passStr), color.RedString(failStr), color.YellowString(skipStr), " "+vari.LogDir+"result.txt ", diff --git a/src/service/zentao/account.go b/src/service/zentao/account.go index 3db148bc0..9e49a3fe8 100644 --- a/src/service/zentao/account.go +++ b/src/service/zentao/account.go @@ -15,7 +15,7 @@ func Login(baseUrl string, account string, password string) bool { ok := GetConfig(baseUrl) if !ok { - logUtils.PrintToCmd(i118Utils.I118Prt.Sprintf("fail_to_login"), color.FgRed) + logUtils.PrintToCmd(i118Utils.Sprintf("fail_to_login"), color.FgRed) return false } @@ -38,10 +38,10 @@ func Login(baseUrl string, account string, password string) bool { } if ok { if vari.Verbose { - logUtils.Screen(i118Utils.I118Prt.Sprintf("success_to_login")) + logUtils.Screen(i118Utils.Sprintf("success_to_login")) } } else { - logUtils.PrintToCmd(i118Utils.I118Prt.Sprintf("fail_to_login"), color.FgRed) + logUtils.PrintToCmd(i118Utils.Sprintf("fail_to_login"), color.FgRed) } return ok diff --git a/src/service/zentao/bug.go b/src/service/zentao/bug.go index 8796fb083..6fa7d004f 100644 --- a/src/service/zentao/bug.go +++ b/src/service/zentao/bug.go @@ -118,7 +118,7 @@ func CommitBug() (ok bool, msg string) { } if ok { - msg = i118Utils.I118Prt.Sprintf("success_to_report_bug", bug.Case) + msg = i118Utils.Sprintf("success_to_report_bug", bug.Case) return } else { return diff --git a/src/service/zentao/testResult.go b/src/service/zentao/testResult.go index 1da09e399..16d554b1e 100644 --- a/src/service/zentao/testResult.go +++ b/src/service/zentao/testResult.go @@ -25,11 +25,11 @@ func CommitTestResult(report model.TestReport, testTaskId int) { } if report.Total == 0 { - logUtils.Screen(color.CyanString(i118Utils.I118Prt.Sprintf("ignore_to_submit_result_no_result_empty"))) + logUtils.Screen(color.CyanString(i118Utils.Sprintf("ignore_to_submit_result_no_result_empty"))) return } if vari.ProductId == "" { - logUtils.Screen(color.CyanString(i118Utils.I118Prt.Sprintf("ignore_to_submit_result_no_product_id"))) + logUtils.Screen(color.CyanString(i118Utils.Sprintf("ignore_to_submit_result_no_product_id"))) return } @@ -65,11 +65,11 @@ func CommitTestResult(report model.TestReport, testTaskId int) { msg := "\n" if ok { - msg += color.GreenString(i118Utils.I118Prt.Sprintf("success_to_submit_test_result")) + msg += color.GreenString(i118Utils.Sprintf("success_to_submit_test_result")) } else { - msg = i118Utils.I118Prt.Sprintf("fail_to_submit_test_result") + msg = i118Utils.Sprintf("fail_to_submit_test_result") if strings.Index(resp, "login") > -1 { - msg = i118Utils.I118Prt.Sprintf("fail_to_login") + msg = i118Utils.Sprintf("fail_to_login") } msg = color.RedString(msg) } diff --git a/src/service/zentao/testcase.go b/src/service/zentao/testcase.go index 715751c64..7d760d4fa 100644 --- a/src/service/zentao/testcase.go +++ b/src/service/zentao/testcase.go @@ -280,14 +280,14 @@ func CommitCase(caseId int, title string, stepMap maps.Map, stepTypeMap maps.Map logUtils.PrintToCmd(string(json), -1) var yes bool - logUtils.PrintToWithColor("\n"+i118Utils.I118Prt.Sprintf("case_update_confirm", caseId, title), -1) + logUtils.PrintToWithColor("\n"+i118Utils.Sprintf("case_update_confirm", caseId, title), -1) stdinUtils.InputForBool(&yes, true, "want_to_continue") if yes { _, ok = client.PostObject(url, requestObj, true) if ok { - logUtils.PrintTo(i118Utils.I118Prt.Sprintf("success_to_commit_case", caseId) + "\n") + logUtils.PrintTo(i118Utils.Sprintf("success_to_commit_case", caseId) + "\n") } } } diff --git a/src/service/zentao/ztfTestResult.go b/src/service/zentao/ztfTestResult.go index b56c61451..630fb1782 100644 --- a/src/service/zentao/ztfTestResult.go +++ b/src/service/zentao/ztfTestResult.go @@ -24,8 +24,8 @@ func CommitZTFTestResult(resultDir string, productId string, taskId string, noNe if taskId == "" && !noNeedConfirm { taskId = stdinUtils.GetInput("\\d*", "", - i118Utils.I118Prt.Sprintf("pls_enter")+" "+i118Utils.I118Prt.Sprintf("task_id")+ - i118Utils.I118Prt.Sprintf("task_id_empty_to_create")) + i118Utils.Sprintf("pls_enter")+" "+i118Utils.Sprintf("task_id")+ + i118Utils.Sprintf("task_id_empty_to_create")) } taskIdInt, _ := strconv.Atoi(taskId) diff --git a/src/ui/page/report-bug.go b/src/ui/page/report-bug.go index d08dbcb9b..a688fee74 100644 --- a/src/ui/page/report-bug.go +++ b/src/ui/page/report-bug.go @@ -40,7 +40,7 @@ func InitReportBugPage(resultDir string, caseId string) error { left = right + ui.Space stepsWidth := w - left - 3 stepsInput := widget.NewTextareaWidget("stepsInput", left, y, stepsWidth, h-constant.CmdViewHeight-2, bug.Steps) - stepsInput.Title = i118Utils.I118Prt.Sprintf("steps") + stepsInput.Title = i118Utils.Sprintf("steps") ui.ViewMap["reportBug"] = append(ui.ViewMap["reportBug"], stepsInput.Name()) // module @@ -48,7 +48,7 @@ func InitReportBugPage(resultDir string, caseId string) error { left = x right = left + widget.SelectWidth moduleInput := widget.NewSelectWidgetWithDefault("module", left, y, widget.SelectWidth, 6, - i118Utils.I118Prt.Sprintf("module"), + i118Utils.Sprintf("module"), vari.ZenTaoBugFields.Modules, zentaoService.GetNameById(bug.Module, vari.ZenTaoBugFields.Modules), bugSelectFieldCheckEvent()) ui.ViewMap["reportBug"] = append(ui.ViewMap["reportBug"], moduleInput.Name()) @@ -57,7 +57,7 @@ func InitReportBugPage(resultDir string, caseId string) error { left = right + ui.Space right = left + widget.SelectWidth typeInput := widget.NewSelectWidgetWithDefault("type", left, y, widget.SelectWidth, 6, - i118Utils.I118Prt.Sprintf("category"), + i118Utils.Sprintf("category"), vari.ZenTaoBugFields.Categories, zentaoService.GetNameById(bug.Type, vari.ZenTaoBugFields.Categories), bugSelectFieldCheckEvent()) ui.ViewMap["reportBug"] = append(ui.ViewMap["reportBug"], typeInput.Name()) @@ -66,7 +66,7 @@ func InitReportBugPage(resultDir string, caseId string) error { left = right + ui.Space right = left + widget.SelectWidth versionInput := widget.NewSelectWidgetWithDefault("version", left, y, widget.SelectWidth, 6, - i118Utils.I118Prt.Sprintf("version"), + i118Utils.Sprintf("version"), vari.ZenTaoBugFields.Versions, zentaoService.GetNameById(bugVersion, vari.ZenTaoBugFields.Versions), bugSelectFieldCheckEvent()) ui.ViewMap["reportBug"] = append(ui.ViewMap["reportBug"], versionInput.Name()) @@ -76,7 +76,7 @@ func InitReportBugPage(resultDir string, caseId string) error { left = x right = left + widget.SelectWidth severityInput := widget.NewSelectWidgetWithDefault("severity", left, y, widget.SelectWidth, 6, - i118Utils.I118Prt.Sprintf("severity"), + i118Utils.Sprintf("severity"), vari.ZenTaoBugFields.Severities, zentaoService.GetNameById(bug.Severity, vari.ZenTaoBugFields.Severities), bugSelectFieldCheckEvent()) ui.ViewMap["reportBug"] = append(ui.ViewMap["reportBug"], severityInput.Name()) @@ -85,7 +85,7 @@ func InitReportBugPage(resultDir string, caseId string) error { left = right + ui.Space right = left + widget.SelectWidth priorityInput := widget.NewSelectWidgetWithDefault("priority", left, y, widget.SelectWidth, 6, - i118Utils.I118Prt.Sprintf("priority"), + i118Utils.Sprintf("priority"), vari.ZenTaoBugFields.Priorities, zentaoService.GetNameById(bug.Pri, vari.ZenTaoBugFields.Priorities), bugSelectFieldCheckEvent()) ui.ViewMap["reportBug"] = append(ui.ViewMap["reportBug"], priorityInput.Name()) @@ -101,11 +101,11 @@ func InitReportBugPage(resultDir string, caseId string) error { y += 5 buttonX := x + widget.SelectWidth + ui.Space submitInput := widget.NewButtonWidgetAutoWidth("submitInput", buttonX, y, - i118Utils.I118Prt.Sprintf("submit"), reportBug) + i118Utils.Sprintf("submit"), reportBug) ui.ViewMap["reportBug"] = append(ui.ViewMap["reportBug"], submitInput.Name()) cancelReportBugInput := widget.NewButtonWidgetAutoWidth("cancelReportBugInput", - buttonX+11, y, i118Utils.I118Prt.Sprintf("cancel"), cancelReportBug) + buttonX+11, y, i118Utils.Sprintf("cancel"), cancelReportBug) ui.ViewMap["reportBug"] = append(ui.ViewMap["reportBug"], cancelReportBugInput.Name()) ui.BindEventForInputWidgets(ui.ViewMap["reportBug"]) @@ -173,7 +173,7 @@ func reportBug(g *gocui.Gui, v *gocui.View) error { cancelReportBugInput, _ := vari.Cui.View("cancelReportBugInput") cancelReportBugInput.Clear() - fmt.Fprint(cancelReportBugInput, " "+i118Utils.I118Prt.Sprintf("close")) + fmt.Fprint(cancelReportBugInput, " "+i118Utils.Sprintf("close")) } else { color.New(color.FgMagenta).Fprintf(msgView, msg) } diff --git a/src/ui/widget/widgetHelp.go b/src/ui/widget/widgetHelp.go index bba06a892..3283707ae 100644 --- a/src/ui/widget/widgetHelp.go +++ b/src/ui/widget/widgetHelp.go @@ -79,7 +79,7 @@ func HideHelp() error { func initContent() { HelpGlobal = fmt.Sprintf("%s \n %s \n %s \n", - i118Utils.I118Prt.Sprintf("help_key_bind"), - i118Utils.I118Prt.Sprintf("help_show"), - i118Utils.I118Prt.Sprintf("help_exit")) + i118Utils.Sprintf("help_key_bind"), + i118Utils.Sprintf("help_show"), + i118Utils.Sprintf("help_exit")) } diff --git a/src/utils/config/config.go b/src/utils/config/config.go index 1e54ae2af..6e31ac2ee 100644 --- a/src/utils/config/config.go +++ b/src/utils/config/config.go @@ -44,7 +44,7 @@ func InitScreenSize() { } func PrintCurrConfig() { - logUtils.PrintToWithColor("\n"+i118Utils.I118Prt.Sprintf("current_config"), color.FgCyan) + logUtils.PrintToWithColor("\n"+i118Utils.Sprintf("current_config"), color.FgCyan) val := reflect.ValueOf(vari.Config) typeOfS := val.Type() @@ -100,7 +100,7 @@ func SaveConfig(conf model.Config) error { if i118Utils.I118Prt == nil { // first time, i118 may not be init. logUtils.PrintToWithColor(fmt.Sprintf("Successfully update config file %s.", configPath), color.FgCyan) } else { - logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("success_update_config", configPath), color.FgCyan) + logUtils.PrintToWithColor(i118Utils.Sprintf("success_update_config", configPath), color.FgCyan) } vari.Config = ReadCurrConfig() @@ -132,7 +132,7 @@ func CheckConfigPermission() { err := fileUtils.MkDirIfNeeded(vari.ExeDir + "conf") if err != nil { logUtils.PrintToWithColor( - i118Utils.I118Prt.Sprintf("perm_deny", vari.ExeDir), color.FgRed) + i118Utils.Sprintf("perm_deny", vari.ExeDir), color.FgRed) os.Exit(0) } } @@ -148,7 +148,7 @@ func InputForSet() { var configSite bool - logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("begin_config"), color.FgCyan) + logUtils.PrintToWithColor(i118Utils.Sprintf("begin_config"), color.FgCyan) enCheck := "" var numb string @@ -202,7 +202,7 @@ func CheckRequestConfig() { func InputForRequest() { conf := ReadCurrConfig() - logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("need_config"), color.FgCyan) + logUtils.PrintToWithColor(i118Utils.Sprintf("need_config"), color.FgCyan) conf.Url = stdinUtils.GetInput("(http://.*)", conf.Url, "enter_url", conf.Url) conf.Account = stdinUtils.GetInput("(.{2,})", conf.Account, "enter_account", conf.Account) @@ -231,8 +231,8 @@ func InputForScriptInterpreter(scripts []string, config *model.Config, from stri } sampleOrDefaultTips := "" if deflt == "" { - sampleOrDefaultTips = i118Utils.I118Prt.Sprintf("for_example", langUtils.LangMap[lang]["interpreter"]) + " " + - i118Utils.I118Prt.Sprintf("empty_to_ignore") + sampleOrDefaultTips = i118Utils.Sprintf("for_example", langUtils.LangMap[lang]["interpreter"]) + " " + + i118Utils.Sprintf("empty_to_ignore") } else { sampleOrDefaultTips = deflt } diff --git a/src/utils/file/upload.go b/src/utils/file/upload.go new file mode 100644 index 000000000..597246479 --- /dev/null +++ b/src/utils/file/upload.go @@ -0,0 +1,45 @@ +package fileUtils + +import ( + "bytes" + i118Utils "github.com/easysoft/zentaoatf/src/utils/i118" + logUtils "github.com/easysoft/zentaoatf/src/utils/log" + "io" + "io/ioutil" + "mime/multipart" + "net/http" + "os" +) + +func Upload(url string, files []string, extraParams map[string]string) { + bodyBuffer := &bytes.Buffer{} + bodyWriter := multipart.NewWriter(bodyBuffer) + + for _, file := range files { + fw, _ := bodyWriter.CreateFormFile("file", file) + f, _ := os.Open(file) + defer f.Close() + io.Copy(fw, f) + } + + for key, value := range extraParams { + _ = bodyWriter.WriteField(key, value) + } + + contentType := bodyWriter.FormDataContentType() + bodyWriter.Close() + + resp, err := http.Post(url, contentType, bodyBuffer) + defer resp.Body.Close() + + if err != nil { + logUtils.Error(i118Utils.Sprintf("fail_to_upload_file", err.Error())) + } + + respBody, err := ioutil.ReadAll(resp.Body) + if err != nil { + logUtils.Error(i118Utils.Sprintf("fail_to_parse_upload_file_response", err.Error())) + } + + logUtils.Log(i118Utils.Sprintf("upload_file_result", resp.Status, string(respBody))) +} diff --git a/src/utils/i118/i118.go b/src/utils/i118/i118.go index 3d418bce4..e00fd7227 100644 --- a/src/utils/i118/i118.go +++ b/src/utils/i118/i118.go @@ -13,6 +13,11 @@ import ( var I118Prt *message.Printer +func Sprintf(tmpl string, params ...interface{}) (ret string) { + ret = I118Prt.Sprintf(tmpl, params...) + return +} + func InitI118(lang string) { //var once sync.Once //once.Do(func() { diff --git a/src/utils/lang/lang.go b/src/utils/lang/lang.go index 633c97fed..cbb121247 100644 --- a/src/utils/lang/lang.go +++ b/src/utils/lang/lang.go @@ -138,7 +138,7 @@ func GetSupportLanguageExtArr() []string { func CheckSupportLanguages(scriptLang string) bool { if LangMap[scriptLang] == nil { langStr := strings.Join(GetSupportLanguageArrSort(), ", ") - logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("only_support_script_language", langStr)+"\n", color.FgRed) + logUtils.PrintToWithColor(i118Utils.Sprintf("only_support_script_language", langStr)+"\n", color.FgRed) return false } diff --git a/src/utils/log/log.go b/src/utils/log/log.go index 9c5a33516..59990ec59 100644 --- a/src/utils/log/log.go +++ b/src/utils/log/log.go @@ -37,11 +37,11 @@ func ColoredStatus(status string) string { switch temp { case "pass": - return color.GreenString(i118Utils.I118Prt.Sprintf(temp)) + return color.GreenString(i118Utils.Sprintf(temp)) case "fail": - return color.RedString(i118Utils.I118Prt.Sprintf(temp)) + return color.RedString(i118Utils.Sprintf(temp)) case "skip": - return color.YellowString(i118Utils.I118Prt.Sprintf(temp)) + return color.YellowString(i118Utils.Sprintf(temp)) } return status diff --git a/src/utils/stdin/stdin.go b/src/utils/stdin/stdin.go index 60c48aee9..806d234fc 100644 --- a/src/utils/stdin/stdin.go +++ b/src/utils/stdin/stdin.go @@ -39,17 +39,17 @@ func InputForCheckout(productId *string, moduleId *string, suiteId *string, task coType = strings.ToLower(coType) if coType == "1" { *productId = GetInput("\\d+", *productId, - i118Utils.I118Prt.Sprintf("pls_enter")+" "+i118Utils.I118Prt.Sprintf("product_id")+": "+*productId) + i118Utils.Sprintf("pls_enter")+" "+i118Utils.Sprintf("product_id")+": "+*productId) *moduleId = GetInput("\\d*", *moduleId, - i118Utils.I118Prt.Sprintf("pls_enter")+" "+i118Utils.I118Prt.Sprintf("module_id")+": "+*moduleId) + i118Utils.Sprintf("pls_enter")+" "+i118Utils.Sprintf("module_id")+": "+*moduleId) } else if coType == "2" { *suiteId = GetInput("\\d+", *suiteId, - i118Utils.I118Prt.Sprintf("pls_enter")+" "+i118Utils.I118Prt.Sprintf("suite_id")+": "+*suiteId) + i118Utils.Sprintf("pls_enter")+" "+i118Utils.Sprintf("suite_id")+": "+*suiteId) } else if coType == "3" { *taskId = GetInput("\\d+", *taskId, - i118Utils.I118Prt.Sprintf("pls_enter")+" "+i118Utils.I118Prt.Sprintf("task_id")+": "+*taskId) + i118Utils.Sprintf("pls_enter")+" "+i118Utils.Sprintf("task_id")+": "+*taskId) } InputForBool(independentFile, false, "enter_co_independent") @@ -72,7 +72,7 @@ func InputForCheckout(productId *string, moduleId *string, suiteId *string, task } func InputForDir(dir *string, dft string, i118Key string) { - *dir = GetInput("is_dir", dft, "enter_dir", i118Utils.I118Prt.Sprintf(i118Key)) + *dir = GetInput("is_dir", dft, "enter_dir", i118Utils.Sprintf(i118Key)) } func InputForBool(in *bool, defaultVal bool, fmtStr string, fmtParam ...interface{}) { @@ -101,7 +101,7 @@ func InputForBool(in *bool, defaultVal bool, fmtStr string, fmtParam ...interfac func GetInput(regx string, defaultVal string, fmtStr string, params ...interface{}) string { var ret string - msg := i118Utils.I118Prt.Sprintf(fmtStr, params...) + msg := i118Utils.Sprintf(fmtStr, params...) for { logUtils.PrintToWithColor("\n"+msg, color.FgCyan) @@ -138,7 +138,7 @@ func GetInput(regx string, defaultVal string, fmtStr string, params ...interface return ret } else { ret = "" - logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf(msg), color.FgRed) + logUtils.PrintToWithColor(i118Utils.Sprintf(msg), color.FgRed) } } } @@ -146,7 +146,7 @@ func GetInput(regx string, defaultVal string, fmtStr string, params ...interface func GetInputForScriptInterpreter(defaultVal string, fmtStr string, params ...interface{}) string { var ret string - msg := i118Utils.I118Prt.Sprintf(fmtStr, params...) + msg := i118Utils.Sprintf(fmtStr, params...) for { logUtils.PrintToWithColor(msg, color.FgCyan) @@ -179,7 +179,7 @@ func GetInputForScriptInterpreter(defaultVal string, fmtStr string, params ...in return ret } else { ret = "" - logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("invalid_input"), color.FgRed) + logUtils.PrintToWithColor(i118Utils.Sprintf("invalid_input"), color.FgRed) } } } diff --git a/src/ztf.go b/src/ztf.go index 71f101cd5..608392e27 100644 --- a/src/ztf.go +++ b/src/ztf.go @@ -225,7 +225,7 @@ func run(args []string) { } if vari.Interpreter != "" { - logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("run_with_specific_interpreter", vari.Interpreter), color.FgCyan) + logUtils.PrintToWithColor(i118Utils.Sprintf("run_with_specific_interpreter", vari.Interpreter), color.FgCyan) } action.RunZTFTest(files, suiteId, taskId) } else { @@ -236,7 +236,7 @@ func run(args []string) { func startServer() { vari.IP = commonUtils.GetIp() - logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("start_server", vari.IP, strconv.Itoa(vari.Port)), color.FgCyan) + logUtils.PrintToWithColor(i118Utils.Sprintf("start_server", vari.IP, strconv.Itoa(vari.Port)), color.FgCyan) server := server.NewServer() server.Init()