Skip to content

Commit

Permalink
polish code
Browse files Browse the repository at this point in the history
  • Loading branch information
littlejiancc committed Sep 29, 2021
1 parent 999dc42 commit 58bb27e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
8 changes: 4 additions & 4 deletions apistructs/sceneset.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const (
SceneSetsAutotestExecType = "sceneSets"
SceneAutotestExecType = "scene"

nameMaxLength int = 50
descMaxLength int = 255
SceneSetNameMaxLength int = 50
SceneSetDescMaxLength int = 255
)

type SceneSet struct {
Expand Down Expand Up @@ -63,10 +63,10 @@ type SceneSetRequest struct {
}

func (req *SceneSetRequest) Validate() error {
if err := strutil.Validate(req.Name, strutil.MaxRuneCountValidator(nameMaxLength)); err != nil {
if err := strutil.Validate(req.Name, strutil.MaxRuneCountValidator(SceneSetNameMaxLength)); err != nil {
return err
}
if err := strutil.Validate(req.Description, strutil.MaxRuneCountValidator(descMaxLength)); err != nil {
if err := strutil.Validate(req.Description, strutil.MaxRuneCountValidator(SceneSetDescMaxLength)); err != nil {
return err
}
if ok, _ := regexp.MatchString("^[a-zA-Z\u4e00-\u9fa50-9_-]*$", req.Name); !ok {
Expand Down
2 changes: 1 addition & 1 deletion bundle/autotest_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (b *Bundle) ListTestPlanV2Step(testPlanID, groupID uint64) ([]*apistructs.T
hc := b.hc

var getResp apistructs.TestPlanV2StepListResponse
resp, err := hc.Get(host).Path(fmt.Sprintf("/api/autotests/testplans-steps/%d/actions/by-groupID", testPlanID)).
resp, err := hc.Get(host).Path(fmt.Sprintf("/api/autotests/testplans/%d/steps/actions/list-by-group-id", testPlanID)).
Param("groupID", strconv.FormatUint(groupID, 10)).
Header(httputil.InternalHeader, "bundle").Do().JSON(&getResp)

Expand Down
10 changes: 4 additions & 6 deletions modules/dop/dao/testplan_v2_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,10 @@ func (client *DBClient) AddTestPlanV2Step(req *apistructs.TestPlanV2StepAddReque
func (client *DBClient) DeleteTestPlanV2Step(req *apistructs.TestPlanV2StepDeleteRequest) error {
return client.Transaction(func(tx *gorm.DB) (err error) {
var step, nextStep TestPlanV2Step
defer func() error {
defer func() {
if err == nil {
return updateStepGroup(tx, step.GroupID)
err = updateStepGroup(tx, step.GroupID)
}
return nil
}()

// Get the step
Expand Down Expand Up @@ -175,12 +174,11 @@ func (client *DBClient) MoveTestPlanV2Step(req *apistructs.TestPlanV2StepMoveReq
return client.Transaction(func(tx *gorm.DB) (err error) {
var oldGroupID, newGroupID uint64
// update step groupID in the group if isGroup is false
defer func() error {
defer func() {
if err == nil && !req.IsGroup {
groupIDs := strutil.DedupUint64Slice([]uint64{oldGroupID, newGroupID}, true)
return updateStepGroup(tx, groupIDs...)
err = updateStepGroup(tx, groupIDs...)
}
return nil
}()

var (
Expand Down
2 changes: 1 addition & 1 deletion modules/dop/endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (e *Endpoints) Routes() []httpserver.Endpoint {
{Path: "/api/autotests/testplans/{testPlanID}/actions/move-step", Method: http.MethodPut, Handler: e.MoveTestPlanV2Step},
{Path: "/api/autotests/testplans-step/{stepID}", Method: http.MethodGet, Handler: e.GetTestPlanV2Step},
{Path: "/api/autotests/testplans-step/{stepID}", Method: http.MethodPut, Handler: e.UpdateTestPlanV2Step},
{Path: "/api/autotests/testplans-steps/{testPlanID}/actions/by-groupID", Method: http.MethodGet, Handler: e.ListTestPlanV2Step},
{Path: "/api/autotests/testplans/{testPlanID}/steps/actions/list-by-group-id", Method: http.MethodGet, Handler: e.ListTestPlanV2Step},

{Path: "/api/reportsets/{pipelineID}", Method: http.MethodGet, Handler: e.queryReportSets},

Expand Down

0 comments on commit 58bb27e

Please sign in to comment.