Skip to content

Commit

Permalink
add upload file function
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronchen2k committed Dec 13, 2021
1 parent 1737ff9 commit 22a9751
Show file tree
Hide file tree
Showing 34 changed files with 181 additions and 105 deletions.
13 changes: 13 additions & 0 deletions res/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
]
}
13 changes: 13 additions & 0 deletions res/messages_zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -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。"
}
]
}
4 changes: 2 additions & 2 deletions src/action/bug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/action/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
2 changes: 1 addition & 1 deletion src/action/expect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/action/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/action/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion src/action/ztfTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/service/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/server/service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/service/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/server/utils/common/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions src/service/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,36 @@ 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
}

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
jsonErr := json.Unmarshal(bodyStr, &bodyJson)
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
Expand Down Expand Up @@ -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{}
Expand All @@ -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
}
Expand All @@ -118,28 +118,28 @@ 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
jsonErr := json.Unmarshal(bodyStr, &bodyJson)
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
}
Expand All @@ -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{}

Expand All @@ -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))
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/service/script/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/service/script/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
4 changes: 2 additions & 2 deletions src/service/script/viewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)))
Expand Down
18 changes: 9 additions & 9 deletions src/service/testing/unitTestReport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
}
Expand All @@ -99,21 +99,21 @@ 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 ",
))

// 输出到屏幕
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 ",
Expand Down
2 changes: 1 addition & 1 deletion src/service/testing/ztfCheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 22a9751

Please sign in to comment.