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

save test cases in module dit

上级 0c700cc4
......@@ -41,6 +41,22 @@
"message": "enter password",
"translation": "enter password"
},
{
"id": "enter_co_type",
"message": "enter co type",
"translation": "select case source? Product / Module / Suite / Task"
},
{
"id": "enter_co_independent",
"message": "enter co independent",
"translation": "save expect results in independent file? Yes / No"
},
{
"id": "enter_co_language",
"message": "enter co language",
"translation": "select script language. %s"
},
{
"id": "invalid_input",
"message": "invalid input",
......
......@@ -14,7 +14,7 @@
{
"id": "enter_language",
"message": "enter language",
"translation": "请输入你期望使用的语言En / Zh"
"translation": "请输入你期望使用的语言En / Zh"
},
{
"id": "config_zentao_site",
......@@ -36,6 +36,21 @@
"message": "enter password",
"translation": "请输入账号密码"
},
{
"id": "enter_co_type",
"message": "enter co type",
"translation": "请选择用例来源。Product / Module / Suite / Task"
},
{
"id": "enter_co_independent",
"message": "enter co independent",
"translation": "是否将用例期待结果保存在独立的文件中?Yes / No"
},
{
"id": "enter_co_language",
"message": "enter co language",
"translation": "请选择脚本语言。 %s"
},
{
"id": "invalid_input",
"message": "invalid input",
......
......@@ -6,31 +6,22 @@ import (
"github.com/easysoft/zentaoatf/src/utils/config"
"github.com/easysoft/zentaoatf/src/utils/const"
"github.com/easysoft/zentaoatf/src/utils/i118"
"github.com/easysoft/zentaoatf/src/utils/langUtils"
"github.com/easysoft/zentaoatf/src/utils/log"
"github.com/fatih/color"
)
func GenerateScript(productId string, moduleId string, suiteId string, taskId string,
independentFile bool, scriptLang string) {
LangMap := scriptService.GetSupportedScriptLang()
langs := ""
if LangMap[scriptLang] == nil {
i := 0
for lang, _ := range LangMap {
if i > 0 {
langs += ", "
}
langs += lang
i++
}
logUtils.PrintToCmd(color.RedString(i118Utils.I118Prt.Sprintf("only_support_script_language", langs)) + "\n")
return
config := configUtils.ReadCurrConfig()
if config.Url == "" || config.Account == "" || config.Password == "" {
configUtils.ConfigForCheckout(&productId, &moduleId, &suiteId, &taskId,
&independentFile, &scriptLang)
}
config := configUtils.ReadCurrConfig()
if config.Url == "" {
configUtils.ConfigForCheckout()
ok := langUtils.CheckSupportLangages(scriptLang)
if !ok {
return
}
cases := zentaoService.LoadTestCases(productId, moduleId, suiteId, taskId)
......
......@@ -6,6 +6,7 @@ import (
constant "github.com/easysoft/zentaoatf/src/utils/const"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
i118Utils "github.com/easysoft/zentaoatf/src/utils/i118"
"github.com/easysoft/zentaoatf/src/utils/langUtils"
"github.com/easysoft/zentaoatf/src/utils/vari"
zentaoUtils "github.com/easysoft/zentaoatf/src/utils/zentao"
"os"
......@@ -36,7 +37,7 @@ func GenerateTestCaseScript(cs model.TestCase, langType string, independentFile
modulePath = modulePath[1:]
}
scriptFile := fmt.Sprintf(constant.ScriptDir+"%stc-%s.%s", modulePath, caseId, LangMap[langType]["extName"])
scriptFile := fmt.Sprintf(constant.ScriptDir+"%stc-%s.%s", modulePath, caseId, langUtils.LangMap[langType]["extName"])
fileUtils.MkDirIfNeeded(constant.ScriptDir)
*caseIds = append(*caseIds, caseId)
......@@ -71,7 +72,7 @@ func GenerateTestCaseScript(cs model.TestCase, langType string, independentFile
return
}
temp := fmt.Sprintf("\n%sCODE: %s", LangMap[langType]["commentsTag"],
temp := fmt.Sprintf("\n%sCODE: %s", langUtils.LangMap[langType]["commentsTag"],
i118Utils.I118Prt.Sprintf("your_codes_here"))
srcCode = append(srcCode, temp)
......@@ -101,7 +102,7 @@ func GenerateTestCaseScript(cs model.TestCase, langType string, independentFile
func GenerateTestStepScript(ts model.TestStep, langType string, stepWidth int,
steps *[]string, expects *[]string, srcCode *[]string) {
LangMap := GetSupportedScriptLang()
LangMap := langUtils.GetSupportedScriptLang()
isGroup := ts.Type == "group"
isCheckPoint := ts.Expect != ""
......
package main
import (
"flag"
"fmt"
commonUtils "github.com/easysoft/zentaoatf/src/utils/common"
"github.com/easysoft/zentaoatf/src/utils/langUtils"
"strings"
)
func main() {
var languages []string
flag.Var(commonUtils.NewSliceValue([]string{}, &languages), "slice", "I like programming `languages`")
flag.Parse()
fmtParam := strings.Join(langUtils.GetSupportLangageArr(), " / ")
scriptLang := fmt.Sprintf("enter_co_language%s", fmtParam)
fmt.Println(languages)
fmt.Println(scriptLang)
}
......@@ -8,6 +8,7 @@ import (
"github.com/easysoft/zentaoatf/src/utils/display"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
"github.com/easysoft/zentaoatf/src/utils/i118"
"github.com/easysoft/zentaoatf/src/utils/langUtils"
"github.com/easysoft/zentaoatf/src/utils/log"
"github.com/easysoft/zentaoatf/src/utils/vari"
"github.com/fatih/color"
......@@ -45,18 +46,18 @@ func ConfigForSet() {
fmt.Println(i118Utils.I118Prt.Sprintf("begin_config"))
language = getInput("enter_language", "(english|chinese|e|c)")
language = getInput("(english|chinese|e|c)", "enter_language")
if strings.Index(strings.ToLower(language), "e") == 0 {
language = "en"
} else {
language = "zh"
}
configSite = getInput("config_zentao_site", "(yes|no|y|n)")
configSite = getInput("(yes|no|y|n)", "config_zentao_site")
if strings.Index(configSite, "y") == 0 {
url = getInput("enter_url", "http://.*")
account = getInput("enter_account", ".{3,}")
password = getInput("enter_password", ".{4,}")
url = getInput("http://.*", "enter_url")
account = getInput(".{3,}", "enter_account")
password = getInput(".{4,}", "enter_password")
}
SaveConfig(language, url, account, password)
......@@ -64,32 +65,58 @@ func ConfigForSet() {
PrintCurrConfig()
}
func ConfigForCheckout() {
language := ""
url := ""
account := ""
password := ""
func ConfigForCheckout(productId *string, moduleId *string, suiteId *string, taskId *string,
independentFile *bool, scriptLang *string) {
fmt.Println(i118Utils.I118Prt.Sprintf("need_config"))
color.Cyan("\n" + i118Utils.I118Prt.Sprintf("need_config"))
url = getInput("enter_url", "http://.*")
account = getInput("enter_account", ".{3,}")
password = getInput("enter_password", ".{4,}")
url := getInput("http://.*", "enter_url")
account := getInput(".{3,}", "enter_account")
password := getInput(".{4,}", "enter_password")
SaveConfig(language, url, account, password)
coType := getInput("(product|module|suite|task|p|m|s|t)", "enter_co_type")
coType = strings.ToLower(coType)
if coType == "product" || coType == "p" {
*productId = getInput("\\d+", "productId")
} else if coType == "module" || coType == "m" {
*productId = getInput("\\d+", "productId")
*moduleId = getInput("\\d+", "moduleId")
} else if coType == "suite" || coType == "s" {
*suiteId = getInput("\\d+", "suiteId")
} else if coType == "task" || coType == "t" {
*taskId = getInput("\\d+", "taskId")
}
indep := getInput("(yes|no|y|n)", "enter_co_independent")
regx := "(" + strings.Join(langUtils.GetSupportLangageArr(), "|") + ")"
fmtParam := strings.Join(langUtils.GetSupportLangageArr(), " / ")
*scriptLang = getInput(regx, "enter_co_language", fmtParam)
indep = strings.ToLower(indep)
if indep == "yes" || indep == "y" {
*independentFile = true
} else {
*independentFile = false
}
SaveConfig("en", url, account, password)
PrintCurrConfig()
}
func getInput(msg string, regx string) string {
func getInput(regx string, fmtStr string, params ...interface{}) string {
var ret string
msg := i118Utils.I118Prt.Sprintf(fmtStr, params...)
for {
fmt.Println(i118Utils.I118Prt.Sprintf(msg) + ": ")
color.Cyan("\n" + msg + " \n")
fmt.Scanln(&ret)
ret = strings.ToLower(ret)
if ret == "exit" {
temp := strings.ToLower(ret)
if temp == "exit" {
os.Exit(1)
}
......@@ -97,7 +124,7 @@ func getInput(msg string, regx string) string {
return ret
}
pass, _ := regexp.MatchString(regx, ret)
pass, _ := regexp.MatchString("^"+regx+"$", temp)
if pass {
return ret
} else {
......@@ -211,7 +238,10 @@ func ReadCurrConfig() model.Config {
}
func saveEmptyConfig() error {
SaveConfig("en", "", "", "")
config := model.Config{Language: "en", Url: "", Account: "", Password: ""}
data, _ := yaml.Marshal(&config)
ioutil.WriteFile(constant.ConfigFile, data, 0666)
return nil
}
package scriptService
package langUtils
import "sync"
import (
i118Utils "github.com/easysoft/zentaoatf/src/utils/i118"
logUtils "github.com/easysoft/zentaoatf/src/utils/log"
"github.com/fatih/color"
"strings"
"sync"
)
var LangMap map[string]map[string]string
......@@ -59,6 +65,29 @@ func GetSupportedScriptLang() map[string]map[string]string {
return LangMap
}
func GetSupportLangageArr() []string {
langMap := GetSupportedScriptLang()
arr := make([]string, 0)
for lang, _ := range langMap {
arr = append(arr, lang)
}
return arr
}
func CheckSupportLangages(scriptLang string) bool {
langMap := GetSupportedScriptLang()
if langMap[scriptLang] == nil {
langs := strings.Join(GetSupportLangageArr(), ", ")
logUtils.PrintToCmd(color.RedString(i118Utils.I118Prt.Sprintf("only_support_script_language", langs)) + "\n")
return false
}
return true
}
func init() {
GetSupportedScriptLang()
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册