Skip to content

Commit 32169b9

Browse files
feature: scene set supports parallel in autoTest (#2173) (#2440)
* feature: scene set supports parallel in autoTest * add ListTestPlanV2Step api * update move group * add split op of render * fix: add unit test * add unit test * add unit test for render * add migrations * polish code * fix: update timeout of Test_initCron Co-authored-by: littlejian <[email protected]>
1 parent 7a2e43f commit 32169b9

File tree

17 files changed

+1046
-133
lines changed

17 files changed

+1046
-133
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE `dice_autotest_plan_step` ADD `group_id` BIGINT(20) NOT NULL DEFAULT 0 COMMENT 'auto test plan step group';

apistructs/sceneset.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@
1515
package apistructs
1616

1717
import (
18+
"fmt"
19+
"regexp"
1820
"strconv"
1921
"time"
22+
23+
"github.com/erda-project/erda/pkg/strutil"
2024
)
2125

22-
const SceneSetsAutotestExecType = "sceneSets"
23-
const SceneAutotestExecType = "scene"
26+
const (
27+
SceneSetsAutotestExecType = "sceneSets"
28+
SceneAutotestExecType = "scene"
29+
30+
SceneSetNameMaxLength int = 50
31+
SceneSetDescMaxLength int = 255
32+
)
2433

2534
type SceneSet struct {
2635
ID uint64 `json:"id"`
@@ -53,6 +62,19 @@ type SceneSetRequest struct {
5362
IdentityInfo
5463
}
5564

65+
func (req *SceneSetRequest) Validate() error {
66+
if err := strutil.Validate(req.Name, strutil.MaxRuneCountValidator(SceneSetNameMaxLength)); err != nil {
67+
return err
68+
}
69+
if err := strutil.Validate(req.Description, strutil.MaxRuneCountValidator(SceneSetDescMaxLength)); err != nil {
70+
return err
71+
}
72+
if ok, _ := regexp.MatchString("^[a-zA-Z\u4e00-\u9fa50-9_-]*$", req.Name); !ok {
73+
return fmt.Errorf("the name not match %s", "^[a-zA-Z\u4e00-\u9fa50-9_-]*$")
74+
}
75+
return nil
76+
}
77+
5678
// type SceneSetUpdateRequest struct {
5779
// Name string `json:"name"`
5880
// Description string `json:"description"`

apistructs/sceneset_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2021 Terminus, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package apistructs
16+
17+
import (
18+
"testing"
19+
20+
"github.com/stretchr/testify/assert"
21+
"k8s.io/apimachinery/pkg/util/rand"
22+
)
23+
24+
func TestSceneSetRequestValidate(t *testing.T) {
25+
tt := []struct {
26+
req SceneSetRequest
27+
want bool
28+
}{
29+
{SceneSetRequest{Name: rand.String(50), Description: "1"}, true},
30+
{SceneSetRequest{Name: rand.String(51), Description: "1"}, false},
31+
{SceneSetRequest{Name: "1", Description: rand.String(255)}, true},
32+
{SceneSetRequest{Name: "1", Description: rand.String(256)}, false},
33+
{SceneSetRequest{Name: "****", Description: "1"}, false},
34+
{SceneSetRequest{Name: "/", Description: "1"}, false},
35+
{SceneSetRequest{Name: "_abd1", Description: "1"}, true},
36+
{SceneSetRequest{Name: "_测试", Description: "1"}, true},
37+
{SceneSetRequest{Name: "1_测试a", Description: "1"}, true},
38+
{SceneSetRequest{Name: "a_测试1", Description: "1"}, true},
39+
}
40+
for _, v := range tt {
41+
assert.Equal(t, v.want, v.req.Validate() == nil)
42+
}
43+
44+
}

apistructs/testplan_v2.go

+21
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ type TestPlanV2StepGetResponse struct {
171171
Data TestPlanV2Step `json:"data"`
172172
}
173173

174+
// TestPlanV2StepListResponse testplan get response
175+
type TestPlanV2StepListResponse struct {
176+
Header
177+
Data []*TestPlanV2Step `json:"data"`
178+
}
179+
174180
// TestPlanV2PagingResponseData testplan query response data
175181
type TestPlanV2PagingResponseData struct {
176182
Total int `json:"total"`
@@ -184,6 +190,7 @@ type TestPlanV2Step struct {
184190
SceneSetName string `json:"sceneSetName"`
185191
PreID uint64 `json:"preID"`
186192
PlanID uint64 `json:"planID"`
193+
GroupID uint64 `json:"groupID"`
187194
ID uint64 `json:"id"`
188195
}
189196

@@ -192,6 +199,7 @@ type TestPlanV2StepAddRequest struct {
192199
SceneSetID uint64 `json:"sceneSetID"`
193200
PreID uint64 `json:"preID"`
194201
TestPlanID uint64 `json:"-"`
202+
GroupID uint64 `json:"groupID"`
195203

196204
IdentityInfo
197205
}
@@ -228,3 +236,16 @@ type TestPlanV2StepUpdateResp struct {
228236
Header
229237
Data string `json:"data"`
230238
}
239+
240+
// TestPlanV2StepMoveRequest move a step in the test plan request
241+
type TestPlanV2StepMoveRequest struct {
242+
StepID uint64 `json:"stepID"`
243+
LastStepID uint64 `json:"lastStepID"`
244+
PreID uint64 `json:"preID"`
245+
ScenesSetId uint64 `json:"scenesSetId"`
246+
TestPlanID uint64 `json:"-"`
247+
TargetStepID uint64 `json:"targetStepID"`
248+
IsGroup bool `json:"isGroup"` // true: means move with group
249+
250+
IdentityInfo
251+
}

bundle/autotest_plan.go

+26-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (b *Bundle) DeleteTestPlansV2Step(req apistructs.TestPlanV2StepDeleteReques
6868
}
6969

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

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

202-
// GetTestPlanV2 获取测试计划步骤
202+
// ListTestPlanV2Step list test plan step
203+
func (b *Bundle) ListTestPlanV2Step(testPlanID, groupID uint64) ([]*apistructs.TestPlanV2Step, error) {
204+
host, err := b.urls.DOP()
205+
if err != nil {
206+
return nil, err
207+
}
208+
hc := b.hc
209+
210+
var getResp apistructs.TestPlanV2StepListResponse
211+
resp, err := hc.Get(host).Path(fmt.Sprintf("/api/autotests/testplans/%d/steps/actions/list-by-group-id", testPlanID)).
212+
Param("groupID", strconv.FormatUint(groupID, 10)).
213+
Header(httputil.InternalHeader, "bundle").Do().JSON(&getResp)
214+
215+
if err != nil {
216+
return nil, apierrors.ErrInvoke.InternalError(err)
217+
}
218+
if !resp.IsOK() || !getResp.Success {
219+
return nil, toAPIError(resp.StatusCode(), getResp.Error)
220+
}
221+
222+
return getResp.Data, nil
223+
}
224+
225+
// UpdateTestPlanV2Step 获取测试计划步骤
203226
func (b *Bundle) UpdateTestPlanV2Step(req apistructs.TestPlanV2StepUpdateRequest) error {
204227
host, err := b.urls.DOP()
205228
if err != nil {

0 commit comments

Comments
 (0)