提交 4d0880b9 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

change json key to use Camel-Case

上级 324afa68
......@@ -25,11 +25,11 @@ func CommitBug(files []string) {
}
resultDir = fileUtils.UpdateDir(resultDir)
report := testingService.GetZtfTestReportForSubmit(resultDir)
report := testingService.GetZTFTestReportForSubmit(resultDir)
ids := make([]string, 0)
lines := make([]string, 0)
for _, cs := range report.ZtfCaseResults {
for _, cs := range report.ZTFCaseResults {
if cs.Status != constant.PASS.String() {
lines = append(lines, fmt.Sprintf("%d. %s %s", cs.Id, cs.Title, logUtils.ColoredStatus(cs.Status)))
ids = append(ids, strconv.Itoa(cs.Id))
......
......@@ -9,7 +9,7 @@ import (
)
func Clean() {
path := vari.ZtfDir + constant.LogDir
path := vari.ZTFDir + constant.LogDir
bak := path[:len(path)-1] + "-bak" + string(os.PathSeparator) + path[len(path):]
os.RemoveAll(path)
......
......@@ -6,7 +6,7 @@ import (
stdinUtils "github.com/easysoft/zentaoatf/src/utils/stdin"
)
func CommitZtfTestResult(files []string, noNeedConfirm bool) {
func CommitZTFTestResult(files []string, noNeedConfirm bool) {
var resultDir string
if len(files) > 0 {
resultDir = files[0]
......@@ -15,6 +15,6 @@ func CommitZtfTestResult(files []string, noNeedConfirm bool) {
}
resultDir = fileUtils.UpdateDir(resultDir)
zentaoService.CommitZtfTestResult(resultDir, noNeedConfirm)
zentaoService.CommitZTFTestResult(resultDir, noNeedConfirm)
}
......@@ -19,7 +19,7 @@ import (
"strconv"
)
func RunZtfTest(files []string, suiteIdStr string, taskIdStr string) error {
func RunZTFTest(files []string, suiteIdStr string, taskIdStr string) error {
logUtils.InitLogger()
cases := make([]string, 0)
......@@ -146,7 +146,7 @@ func runCases(files []string) {
}
var report = model.TestReport{Env: commonUtils.GetOs(),
Pass: 0, Fail: 0, Total: 0, ZtfCaseResults: make([]model.ZtfCaseResult, 0)}
Pass: 0, Fail: 0, Total: 0, ZTFCaseResults: make([]model.ZTFCaseResult, 0)}
report.TestType = "ztf"
report.TestFrame = "ztf"
......@@ -166,7 +166,7 @@ func runCases(files []string) {
}
testingService.ExeScripts(casesToRun, casesToIgnore, &report, pathMaxWidth, numbMaxWidth)
testingService.GenZtfTestReport(report, pathMaxWidth)
testingService.GenZTFTestReport(report, pathMaxWidth)
}
func isRunWithSuiteFile(files []string) (string, string) {
......
......@@ -113,48 +113,48 @@ type Bug struct {
}
type TestReport struct {
Env string
TestType string
TestFrame string
ProductId int
TaskId int
ZentaoData string
BuildUrl string
Pass int
Fail int
Skip int
Total int
StartTime int64
EndTime int64
Duration int64
ZtfCaseResults []ZtfCaseResult
UnitCaseResults []UnitCaseResult
Env string `json:"env"`
TestType string `json:"testType"`
TestFrame string `json:"TestFrame"`
ProductId int `json:"ProductId"`
TaskId int `json:"TaskId"`
ZentaoData string `json:"ZentaoData"`
BuildUrl string `json:"BuildUrl"`
Pass int `json:"Pass"`
Fail int `json:"Fail"`
Skip int `json:"Skip"`
Total int `json:"Total"`
StartTime int64 `json:"StartTime"`
EndTime int64 `json:"EndTime"`
Duration int64 `json:"Duration"`
ZTFCaseResults []ZTFCaseResult `json:"ZTFCaseResults"`
UnitCaseResults []UnitCaseResult `json:"UnitCaseResults"`
}
type ZtfCaseResult struct {
Id int
ProductId int
Path string
Status string
Title string
type ZTFCaseResult struct {
Id int `json:"Id"`
ProductId int `json:"ProductId"`
Path string `json:"Path"`
Status string `json:"Status"`
Title string `json:"Title"`
Steps []StepLog
Steps []StepLog `json:"Steps"`
}
type StepLog struct {
Id string
Name string
Status bool
Id string `json:"Id"`
Name string `json:"Name"`
Status bool `json:"Status"`
CheckPoints []CheckPointLog
CheckPoints []CheckPointLog `json:"CheckPoints"`
}
type CheckPointLog struct {
Numb int
Expect string
Actual string
Status bool
Numb int `json:"Numb"`
Expect string `json:"Expect"`
Actual string `json:"Actual"`
Status bool `json:"Status"`
}
// 单元测试
......@@ -168,26 +168,26 @@ type UnitTestSuite struct {
TestCases []UnitCaseResult `xml:"testcase"`
}
type UnitCaseResult struct {
Title string `xml:"name,attr"`
TestSuite string `xml:"classname,attr"`
Duration float32 `xml:"time,attr"`
Failure *Failure `xml:"failure,omitempty"`
Title string `json:"title" xml:"name,attr"`
TestSuite string `json:"testSuite" xml:"classname,attr"`
Duration float32 `json:"duration" xml:"time,attr"`
Failure *Failure `json:"failure" xml:"failure,omitempty"`
Id int
Status string
Id int `json:"id"`
Status string `json:"status"`
}
type Failure struct {
Type string `xml:"type,attr"`
Desc string `xml:",innerxml"`
Type string `json:"type" xml:"type,attr"`
Desc string `json:"desc" xml:",innerxml"`
}
type Properties struct {
Property []Property `xml:"property"`
Property []Property `json:"property" xml:"property"`
}
type Property struct {
Name string `xml:"name,attr"`
Value string `xml:"value,attr"`
Name string `json:"name" xml:"name,attr"`
Value string `json:"value" xml:"value,attr"`
}
// jtest xml
......
......@@ -19,7 +19,7 @@ import (
func List(cases []string, keywords string) {
keywords = strings.TrimSpace(keywords)
scriptArr := make([]model.ZtfCaseResult, 0)
scriptArr := make([]model.ZTFCaseResult, 0)
pathMaxWidth := 0
numbMaxWidth := 0
......@@ -62,7 +62,7 @@ func List(cases []string, keywords string) {
}
}
func SummaryObj(file string, keywords string) (bool, model.ZtfCaseResult) {
func SummaryObj(file string, keywords string) (bool, model.ZTFCaseResult) {
pass, caseId, _, title := zentaoUtils.GetCaseInfo(file)
if pass {
......@@ -78,12 +78,12 @@ func SummaryObj(file string, keywords string) (bool, model.ZtfCaseResult) {
if pass {
//fmt.Printf("%d. %s \n", caseId, title)
return true, model.ZtfCaseResult{Id: caseId, Title: title, Path: file}
return true, model.ZTFCaseResult{Id: caseId, Title: title, Path: file}
} else {
return false, model.ZtfCaseResult{}
return false, model.ZTFCaseResult{}
}
}
return false, model.ZtfCaseResult{}
return false, model.ZTFCaseResult{}
}
func View(cases []string, keywords string) {
......
......@@ -24,25 +24,27 @@ func RetrieveUnitResult() []model.UnitTestSuite {
resultDir = fmt.Sprintf("target%ssurefire-reports%s", sep, sep)
} else if vari.UnitTestType == "testng" && vari.UnitTestTool == "mvn" {
resultDir = fmt.Sprintf("target%ssurefire-reports%sjunitreports", sep, sep)
} else if vari.UnitTestType == "jtest" {
resultDir = "./"
} else if vari.UnitTestType == "phpunit" {
resultDir = "./"
} else if vari.UnitTestType == "pytest" {
resultDir = "./"
} else if vari.UnitTestType == "gtest" {
resultDir = "./"
} else {
resultDir = vari.UnitTestResult
}
dir, err := ioutil.ReadDir(resultDir)
if err == nil {
for _, fi := range dir {
name := fi.Name()
ext := path.Ext(name)
if ext == ".xml" {
resultFiles = append(resultFiles, resultDir+name)
if fileUtils.IsDir(resultDir) {
if resultDir[len(resultDir)-1:] != sep {
resultDir = resultDir + sep
}
dir, err := ioutil.ReadDir(resultDir)
if err == nil {
for _, fi := range dir {
name := fi.Name()
ext := path.Ext(name)
if ext == ".xml" {
resultFiles = append(resultFiles, resultDir+name)
}
}
}
} else {
resultFiles = append(resultFiles, resultDir)
}
suites := make([]model.UnitTestSuite, 0)
......
......@@ -78,9 +78,9 @@ func ValidateCaseResult(scriptFile string, langType string,
}
report.Total = report.Total + 1
cs := model.ZtfCaseResult{Id: caseId, ProductId: productId, Title: title,
cs := model.ZTFCaseResult{Id: caseId, ProductId: productId, Title: title,
Path: scriptFile, Status: caseResult, Steps: stepLogs}
report.ZtfCaseResults = append(report.ZtfCaseResults, cs)
report.ZTFCaseResults = append(report.ZTFCaseResults, cs)
// print case result to console
statusColor := logUtils.ColoredStatus(cs.Status)
......
......@@ -15,8 +15,8 @@ import (
"time"
)
func GenZtfTestReport(report model.TestReport, pathMaxWidth int) {
if len(report.ZtfCaseResults) == 0 {
func GenZTFTestReport(report model.TestReport, pathMaxWidth int) {
if len(report.ZTFCaseResults) == 0 {
return
}
......@@ -25,7 +25,7 @@ func GenZtfTestReport(report model.TestReport, pathMaxWidth int) {
failedCaseLines := make([]string, 0)
failedCaseLinesWithCheckpoint := make([]string, 0)
for _, cs := range report.ZtfCaseResults {
for _, cs := range report.ZTFCaseResults {
if cs.Status == "fail" {
if failedCount > 0 {
failedCaseLinesWithCheckpoint = append(failedCaseLinesWithCheckpoint, "")
......
......@@ -10,7 +10,7 @@ import (
"strings"
)
func GetZtfTestReportForSubmit(resultDir string) model.TestReport {
func GetZTFTestReportForSubmit(resultDir string) model.TestReport {
resultPath := resultDir + "result.json"
content := fileUtils.ReadFile(resultPath)
......
......@@ -23,8 +23,8 @@ func PrepareBug(resultDir string, caseIdStr string) (model.Bug, string) {
return model.Bug{}, ""
}
report := testingService.GetZtfTestReportForSubmit(resultDir)
for _, cs := range report.ZtfCaseResults {
report := testingService.GetZTFTestReportForSubmit(resultDir)
for _, cs := range report.ZTFCaseResults {
if cs.Id != caseId {
continue
}
......
......@@ -21,8 +21,8 @@ func CommitTestResult(report model.TestReport, testTaskId int) {
report.BuildUrl = os.Getenv("BUILD_URL")
report.TaskId = testTaskId
if len(report.ZtfCaseResults) > 0 {
report.ProductId = report.ZtfCaseResults[0].ProductId
if len(report.ZTFCaseResults) > 0 {
report.ProductId = report.ZTFCaseResults[0].ProductId
}
url := conf.Url + zentaoUtils.GenApiUri("unittest", "commitResult", "")
......
......@@ -8,11 +8,11 @@ import (
"strconv"
)
func CommitZtfTestResult(resultDir string, noNeedConfirm bool) {
func CommitZTFTestResult(resultDir string, noNeedConfirm bool) {
conf := configUtils.ReadCurrConfig()
Login(conf.Url, conf.Account, conf.Password)
report := testingService.GetZtfTestReportForSubmit(resultDir)
report := testingService.GetZTFTestReportForSubmit(resultDir)
task := stdinUtils.GetInput("\\d*", "",
i118Utils.I118Prt.Sprintf("pls_enter")+i118Utils.I118Prt.Sprintf("task_id")+
......
......@@ -150,7 +150,7 @@ func GetFailedCasesDirectlyFromTestResult(resultFile string) []string {
var report model.TestReport
json.Unmarshal([]byte(content), &report)
for _, cs := range report.ZtfCaseResults {
for _, cs := range report.ZTFCaseResults {
if cs.Status != "pass" {
cases = append(cases, cs.Path)
}
......
......@@ -20,10 +20,10 @@ import (
)
func InitConfig() {
vari.ZtfDir = fileUtils.GetZtfDir()
vari.ZTFDir = fileUtils.GetZTFDir()
CheckConfigPermission()
constant.ConfigFile = vari.ZtfDir + constant.ConfigFile
constant.ConfigFile = vari.ZTFDir + constant.ConfigFile
vari.Config = getInst()
// screen size
......@@ -40,7 +40,7 @@ func InitScreenSize() {
}
func SaveConfig(conf model.Config) error {
fileUtils.MkDirIfNeeded(fileUtils.GetZtfDir() + "conf")
fileUtils.MkDirIfNeeded(fileUtils.GetZTFDir() + "conf")
conf.Version = constant.ConfigVer
......@@ -109,12 +109,12 @@ func getInst() model.Config {
}
func CheckConfigPermission() {
//err := syscall.Access(vari.ZtfDir, syscall.O_RDWR)
//err := syscall.Access(vari.ZTFDir, syscall.O_RDWR)
err := fileUtils.MkDirIfNeeded(vari.ZtfDir + "conf")
err := fileUtils.MkDirIfNeeded(vari.ZTFDir + "conf")
if err != nil {
logUtils.PrintToWithColor(
fmt.Sprintf("Permission denied to open %s for write. Please change work dir.", vari.ZtfDir), color.FgRed)
fmt.Sprintf("Permission denied to open %s for write. Please change work dir.", vari.ZTFDir), color.FgRed)
os.Exit(0)
}
}
......
......@@ -133,7 +133,7 @@ func ReadResData(path string) string {
return jsonStr
}
func GetZtfDir() string { // where ztf command in
func GetZTFDir() string { // where ztf command in
var dir string
arg1 := strings.ToLower(os.Args[0])
......@@ -155,7 +155,7 @@ func GetZtfDir() string { // where ztf command in
}
func GetLogDir() string {
path := vari.ZtfDir + constant.LogDir
path := vari.ZTFDir + constant.LogDir
dir, _ := ioutil.ReadDir(path)
......
......@@ -11,12 +11,13 @@ var (
Cui *gocui.Gui
MainViewHeight int
RunMode constant.RunMode
ZtfDir string
LogDir string
RunFromCui bool
UnitTestType string
UnitTestTool string
RunMode constant.RunMode
ZTFDir string
LogDir string
RunFromCui bool
UnitTestType string
UnitTestTool string
UnitTestResult string
SessionVar string
SessionId string
......
......@@ -75,6 +75,8 @@ func main() {
flagSet.StringVar(&placeholder, "r", "", "")
flagSet.StringVar(&placeholder, "v", "", "")
flagSet.StringVar(&vari.UnitTestResult, "result", "", "")
if len(os.Args) == 1 {
os.Args = append(os.Args, "run", ".")
}
......@@ -102,7 +104,7 @@ func main() {
case "cr":
files := fileUtils.GetFilesFromParams(os.Args[2:])
if err := flagSet.Parse(os.Args[len(files)+2:]); err == nil {
action.CommitZtfTestResult(files, noNeedConfirm)
action.CommitZTFTestResult(files, noNeedConfirm)
}
case "cb":
......@@ -159,12 +161,17 @@ func run(args []string) {
vari.UnitTestType = args[2]
if args[3] == "mvn" {
vari.UnitTestTool = "mvn"
} else {
flagSet.Parse(args[3:])
}
cmd := strings.Join(args[3:], " ")
start := 3
if vari.UnitTestResult != "" {
start = start + 2
} else {
vari.UnitTestResult = "./"
}
cmd := strings.Join(args[start:], " ")
action.RunUnitTest(cmd)
} else { // func test
files := fileUtils.GetFilesFromParams(args[2:])
......@@ -177,7 +184,7 @@ func run(args []string) {
if vari.Interpreter != "" {
logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("run_with_specific_interpreter", vari.Interpreter), color.FgCyan)
}
action.RunZtfTest(files, suiteId, taskId)
action.RunZTFTest(files, suiteId, taskId)
} else {
logUtils.PrintUsage()
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册