Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: scene set supports parallel in autoTest #2173

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `dice_autotest_plan_step` ADD `group_id` BIGINT(20) NOT NULL DEFAULT 0 COMMENT 'auto test plan step group';
26 changes: 24 additions & 2 deletions apistructs/sceneset.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@
package apistructs

import (
"fmt"
"regexp"
"strconv"
"time"

"github.com/erda-project/erda/pkg/strutil"
)

const SceneSetsAutotestExecType = "sceneSets"
const SceneAutotestExecType = "scene"
const (
SceneSetsAutotestExecType = "sceneSets"
SceneAutotestExecType = "scene"

SceneSetNameMaxLength int = 50
SceneSetDescMaxLength int = 255
)

type SceneSet struct {
ID uint64 `json:"id"`
Expand Down Expand Up @@ -53,6 +62,19 @@ type SceneSetRequest struct {
IdentityInfo
}

func (req *SceneSetRequest) Validate() error {
if err := strutil.Validate(req.Name, strutil.MaxRuneCountValidator(SceneSetNameMaxLength)); err != nil {
return err
}
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 {
return fmt.Errorf("the name not match %s", "^[a-zA-Z\u4e00-\u9fa50-9_-]*$")
}
return nil
}

// type SceneSetUpdateRequest struct {
// Name string `json:"name"`
// Description string `json:"description"`
Expand Down
44 changes: 44 additions & 0 deletions apistructs/sceneset_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package apistructs

import (
"testing"

"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/util/rand"
)

func TestSceneSetRequestValidate(t *testing.T) {
tt := []struct {
req SceneSetRequest
want bool
}{
{SceneSetRequest{Name: rand.String(50), Description: "1"}, true},
{SceneSetRequest{Name: rand.String(51), Description: "1"}, false},
{SceneSetRequest{Name: "1", Description: rand.String(255)}, true},
{SceneSetRequest{Name: "1", Description: rand.String(256)}, false},
{SceneSetRequest{Name: "****", Description: "1"}, false},
{SceneSetRequest{Name: "/", Description: "1"}, false},
{SceneSetRequest{Name: "_abd1", Description: "1"}, true},
{SceneSetRequest{Name: "_测试", Description: "1"}, true},
{SceneSetRequest{Name: "1_测试a", Description: "1"}, true},
{SceneSetRequest{Name: "a_测试1", Description: "1"}, true},
}
for _, v := range tt {
assert.Equal(t, v.want, v.req.Validate() == nil)
}

}
21 changes: 21 additions & 0 deletions apistructs/testplan_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ type TestPlanV2StepGetResponse struct {
Data TestPlanV2Step `json:"data"`
}

// TestPlanV2StepListResponse testplan get response
type TestPlanV2StepListResponse struct {
Header
Data []*TestPlanV2Step `json:"data"`
}

// TestPlanV2PagingResponseData testplan query response data
type TestPlanV2PagingResponseData struct {
Total int `json:"total"`
Expand All @@ -184,6 +190,7 @@ type TestPlanV2Step struct {
SceneSetName string `json:"sceneSetName"`
PreID uint64 `json:"preID"`
PlanID uint64 `json:"planID"`
GroupID uint64 `json:"groupID"`
ID uint64 `json:"id"`
}

Expand All @@ -192,6 +199,7 @@ type TestPlanV2StepAddRequest struct {
SceneSetID uint64 `json:"sceneSetID"`
PreID uint64 `json:"preID"`
TestPlanID uint64 `json:"-"`
GroupID uint64 `json:"groupID"`

IdentityInfo
}
Expand Down Expand Up @@ -228,3 +236,16 @@ type TestPlanV2StepUpdateResp struct {
Header
Data string `json:"data"`
}

// TestPlanV2StepMoveRequest move a step in the test plan request
type TestPlanV2StepMoveRequest struct {
StepID uint64 `json:"stepID"`
LastStepID uint64 `json:"lastStepID"`
PreID uint64 `json:"preID"`
ScenesSetId uint64 `json:"scenesSetId"`
TestPlanID uint64 `json:"-"`
TargetStepID uint64 `json:"targetStepID"`
IsGroup bool `json:"isGroup"` // true: means move with group

IdentityInfo
}
29 changes: 26 additions & 3 deletions bundle/autotest_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (b *Bundle) DeleteTestPlansV2Step(req apistructs.TestPlanV2StepDeleteReques
}

// MoveTestPlansV2Step 移动测试计划步骤
func (b *Bundle) MoveTestPlansV2Step(req apistructs.TestPlanV2StepUpdateRequest) error {
func (b *Bundle) MoveTestPlansV2Step(req apistructs.TestPlanV2StepMoveRequest) error {
host, err := b.urls.DOP()
if err != nil {
return err
Expand Down Expand Up @@ -177,7 +177,7 @@ func (b *Bundle) GetTestPlanV2(testPlanID uint64) (*apistructs.TestPlanV2GetResp
return &getResp, nil
}

// GetTestPlanV2 获取测试计划步骤
// GetTestPlanV2Step 获取测试计划步骤
func (b *Bundle) GetTestPlanV2Step(stepID uint64) (*apistructs.TestPlanV2Step, error) {
host, err := b.urls.DOP()
if err != nil {
Expand All @@ -199,7 +199,30 @@ func (b *Bundle) GetTestPlanV2Step(stepID uint64) (*apistructs.TestPlanV2Step, e
return &getResp.Data, nil
}

// GetTestPlanV2 获取测试计划步骤
// ListTestPlanV2Step list test plan step
func (b *Bundle) ListTestPlanV2Step(testPlanID, groupID uint64) ([]*apistructs.TestPlanV2Step, error) {
host, err := b.urls.DOP()
if err != nil {
return nil, err
}
hc := b.hc

var getResp apistructs.TestPlanV2StepListResponse
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)

if err != nil {
return nil, apierrors.ErrInvoke.InternalError(err)
}
if !resp.IsOK() || !getResp.Success {
return nil, toAPIError(resp.StatusCode(), getResp.Error)
}

return getResp.Data, nil
}

// UpdateTestPlanV2Step 获取测试计划步骤
func (b *Bundle) UpdateTestPlanV2Step(req apistructs.TestPlanV2StepUpdateRequest) error {
host, err := b.urls.DOP()
if err != nil {
Expand Down
Loading