Skip to content

Commit

Permalink
+ [feat#55957] not found cid support create testcase
Browse files Browse the repository at this point in the history
ysicing committed Jul 23, 2024
1 parent 27d6c77 commit 8090be0
Showing 6 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmd/command/main.go
Original file line number Diff line number Diff line change
@@ -168,7 +168,7 @@ func checkout() {
func ci() {
files := fileUtils.GetFilesFromParams(os.Args[2:])
if err := flagSet.Parse(os.Args[len(files)+2:]); err == nil {
action.CheckIn(files, noNeedConfirm, withCode)
action.CheckIn(productId, files, noNeedConfirm, withCode)
}
}

4 changes: 2 additions & 2 deletions internal/command/action/case.go
Original file line number Diff line number Diff line change
@@ -11,12 +11,12 @@ import (
stringUtils "github.com/easysoft/zentaoatf/pkg/lib/string"
)

func CheckIn(files []string, noNeedConfirm, withCode bool) {
func CheckIn(productId string, files []string, noNeedConfirm, withCode bool) {
cases := scriptHelper.GetCaseByDirAndFile(files)

config := configHelper.LoadByWorkspacePath(commConsts.ZtfDir)

zentaoHelper.CheckIn(cases, config, noNeedConfirm, withCode)
zentaoHelper.CheckIn(productId, cases, config, noNeedConfirm, withCode)
}

func Checkout(productId, moduleId, suiteId, taskId string, independentFile bool, scriptLang string) {
2 changes: 1 addition & 1 deletion internal/pkg/helper/zentao/bug.go
Original file line number Diff line number Diff line change
@@ -330,7 +330,7 @@ func generateCaseId(bugs []*commDomain.ZentaoBug, config commDomain.WorkspaceCon
}
}
if bug.Case == 0 {
caseInfo, _ := CreateCase(bug.Product, bug.Title, nil, serverDomain.TestScript{}, config)
caseInfo, _ := CreateCase(fmt.Sprintf("%v", bug.Product), bug.Title, nil, serverDomain.TestScript{}, config)
bug.Case = caseInfo.Id
}
}
18 changes: 12 additions & 6 deletions internal/pkg/helper/zentao/case.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import (
"strconv"
"strings"

"github.com/davecgh/go-spew/spew"
serverConfig "github.com/easysoft/zentaoatf/internal/server/config"

"github.com/fatih/color"
@@ -28,7 +27,7 @@ import (
"github.com/kataras/iris/v12"
)

func CommitCase(caseId int, title string, steps []commDomain.ZentaoCaseStep, script serverDomain.TestScript,
func CommitCase(productId string, caseId int, title string, steps []commDomain.ZentaoCaseStep, script serverDomain.TestScript,
config commDomain.WorkspaceConf, noNeedConfirm, withCode bool) (err error) {

if serverConfig.CONFIG.AuthToken == "" {
@@ -40,6 +39,15 @@ func CommitCase(caseId int, title string, steps []commDomain.ZentaoCaseStep, scr

_, err = GetCaseById(config, caseId)
if err != nil {
if !strings.Contains(err.Error(), "404") {
return
}
if len(productId) == 0 {
logUtils.Info("not found productId, like: pid=1")
return fmt.Errorf("not found productId, like: pid=1")
}
// 创建cases
_, err = CreateCase(productId, title, steps, script, config)
return
}

@@ -87,15 +95,15 @@ func CommitCase(caseId int, title string, steps []commDomain.ZentaoCaseStep, scr
return
}

func CreateCase(productId int, title string, steps []commDomain.ZentaoCaseStep, script serverDomain.TestScript,
func CreateCase(productId, title string, steps []commDomain.ZentaoCaseStep, script serverDomain.TestScript,
config commDomain.WorkspaceConf) (cs commDomain.ZtfCase, err error) {

err = Login(config)
if err != nil {
return
}

uri := fmt.Sprintf("/products/%d/testcases", productId)
uri := fmt.Sprintf("/products/%v/testcases", productId)
url := GenApiUrl(uri, nil, config.Url)

requestObj := map[string]interface{}{
@@ -616,13 +624,11 @@ func ListCaseByModule(baseUrl string, productId, moduleId int) (casesResp commDo
"module": moduleId,
"limit": 10000,
}, baseUrl)
spew.Dump(url)
bytes, err := httpUtils.Get(url)
if err != nil {
err = ZentaoRequestErr(err.Error())
return
}
spew.Dump(string(bytes))
casesResp, err = parseCases(bytes)
if err != nil {
err = ZentaoRequestErr(url, commConsts.ResponseParseErr.Message)
8 changes: 3 additions & 5 deletions internal/pkg/helper/zentao/sync.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import (
"fmt"
"path/filepath"

"github.com/davecgh/go-spew/spew"
fileUtils "github.com/easysoft/zentaoatf/pkg/lib/file"
i118Utils "github.com/easysoft/zentaoatf/pkg/lib/i118"
logUtils "github.com/easysoft/zentaoatf/pkg/lib/log"
@@ -34,7 +33,6 @@ func Checkout(settings commDomain.SyncSettings, config commDomain.WorkspaceConf,
if !ok {
return
}
spew.Dump(settings)
cases := make([]commDomain.ZtfCase, 0)
if caseId != 0 {
cs, err := GetTestCaseDetail(caseId, config)
@@ -72,16 +70,16 @@ func Checkout(settings commDomain.SyncSettings, config commDomain.WorkspaceConf,
return
}

func CheckIn(cases []string, config commDomain.WorkspaceConf, noNeedConfirm, withCode bool) (count int, err error) {
func CheckIn(productId string, cases []string, config commDomain.WorkspaceConf, noNeedConfirm, withCode bool) (count int, err error) {
for _, cs := range cases {
pass, id, _, title, _ := scriptHelper.GetCaseInfo(cs)
pass, caseId, _, title, _ := scriptHelper.GetCaseInfo(cs)
if !pass {
continue
}

steps := scriptHelper.GetStepAndExpectMap(cs)
script, _ := scriptHelper.GetScriptContent(cs, -1)
err = CommitCase(id, title, steps, script, config, noNeedConfirm, withCode)
err = CommitCase(productId, caseId, title, steps, script, config, noNeedConfirm, withCode)

if err == nil {
count++
13 changes: 8 additions & 5 deletions internal/server/modules/v1/controller/test-script.go
Original file line number Diff line number Diff line change
@@ -2,9 +2,10 @@ package controller

import (
"fmt"
serverConfig "github.com/easysoft/zentaoatf/internal/server/config"
"strings"

serverConfig "github.com/easysoft/zentaoatf/internal/server/config"

commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts"
commDomain "github.com/easysoft/zentaoatf/internal/pkg/domain"
configHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/config"
@@ -249,9 +250,9 @@ func (c *TestScriptCtrl) SyncFromZentao(ctx iris.Context) {

func (c *TestScriptCtrl) SyncToZentao(ctx iris.Context) {
currSiteId, _ := ctx.URLParamInt("currSiteId")
currProductId, _ := ctx.URLParamInt("currProductId")
currProductId := ctx.URLParam("currProductId")

if currProductId == 0 {
if len(currProductId) == 0 {
ctx.JSON(c.ErrResp(commConsts.ParamErr, ""))
return
}
@@ -271,7 +272,7 @@ func (c *TestScriptCtrl) SyncToZentao(ctx iris.Context) {
for _, set := range sets {
totalNum += len(set.Cases)

count, _ := zentaoHelper.CheckIn(set.Cases, config, true, true)
count, _ := zentaoHelper.CheckIn(currProductId, set.Cases, config, true, true)

successNum += count
}
@@ -284,14 +285,16 @@ func (c *TestScriptCtrl) SyncToZentao(ctx iris.Context) {

func (c *TestScriptCtrl) SyncDirToZentao(ctx iris.Context) {
dir := ctx.URLParam("dir")
productId := ctx.URLParam("productId")

cases := scriptHelper.GetCaseByDirAndFile([]string{dir})

config := commDomain.WorkspaceConf{
Url: serverConfig.CONFIG.Server,
}

zentaoHelper.CheckIn(cases, config, true, true)
// TODO 产品ID 新增
zentaoHelper.CheckIn(productId, cases, config, true, true)

return
}

0 comments on commit 8090be0

Please sign in to comment.