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

add upload file function

上级 1737ff94
......@@ -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."
}
]
}
......@@ -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。"
}
]
}
......@@ -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)
}
}
}
......
......@@ -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"))
}
......@@ -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
}
......
......@@ -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
}
......
......@@ -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)
}
}
}
......@@ -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
}
......
......@@ -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))
......
......@@ -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
}
......
......@@ -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
......
......@@ -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
......
......@@ -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), "<html>") > -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), "<html>") > -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
......
......@@ -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))
......
......@@ -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)))
}
......@@ -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)))
......
......@@ -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 ",
......
......@@ -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) {
......
......@@ -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 {
......
......@@ -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 ",
......
......@@ -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
......
......@@ -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
......
......@@ -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)
}
......
......@@ -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")
}
}
}
......
......@@ -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)
......
......@@ -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)
}
......
......@@ -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"))
}
......@@ -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
}
......
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)))
}
......@@ -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() {
......
......@@ -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
}
......
......@@ -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
......
......@@ -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)
}
}
}
......
......@@ -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()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册