Skip to content

Commit 56fcf95

Browse files
authored
Modify the type of the executed_time of the autotest-testplan,and fix the bug of taskHistoryTable will panic (#1736)
* fix testplan execute time * fix tasktable panic
1 parent a881a40 commit 56fcf95

File tree

6 files changed

+81
-27
lines changed

6 files changed

+81
-27
lines changed

modules/dop/dao/testplan_v2.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type TestPlanV2 struct {
3636
SpaceID uint64
3737
IsArchived bool
3838
PassRate float64
39-
ExecuteTime time.Time
39+
ExecuteTime *time.Time
4040
}
4141

4242
// TableName table name
@@ -58,7 +58,7 @@ func (tp *TestPlanV2) Convert2DTO() apistructs.TestPlanV2 {
5858
CreateAt: &tp.CreatedAt,
5959
UpdateAt: &tp.UpdatedAt,
6060
PassRate: tp.PassRate,
61-
ExecuteTime: &tp.ExecuteTime,
61+
ExecuteTime: tp.ExecuteTime,
6262
}
6363
}
6464

@@ -82,7 +82,7 @@ func (tp TestPlanV2Join) Convert2DTO() *apistructs.TestPlanV2 {
8282
Steps: []*apistructs.TestPlanV2Step{},
8383
IsArchived: tp.IsArchived,
8484
PassRate: tp.PassRate,
85-
ExecuteTime: &tp.ExecuteTime,
85+
ExecuteTime: tp.ExecuteTime,
8686
}
8787
}
8888

modules/dop/services/autotest_v2/testplan_v2.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ func (svc *Service) CreateTestPlanV2(req apistructs.TestPlanV2CreateRequest) (ui
3737

3838
// create test plan
3939
testPlanV2 := &dao.TestPlanV2{
40-
Name: req.Name,
41-
Desc: req.Desc,
42-
CreatorID: req.UserID,
43-
UpdaterID: req.UserID,
44-
SpaceID: req.SpaceID,
45-
ProjectID: req.ProjectID,
40+
Name: req.Name,
41+
Desc: req.Desc,
42+
CreatorID: req.UserID,
43+
UpdaterID: req.UserID,
44+
SpaceID: req.SpaceID,
45+
ProjectID: req.ProjectID,
46+
ExecuteTime: nil,
47+
PassRate: float64(0),
4648
}
4749

4850
if err := svc.db.CreateTestPlanV2(testPlanV2); err != nil {

modules/openapi/component-protocol/scenarios/auto-test-plan-detail/components/executeTaskTable/render.go

+5
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ func (e *ExecuteTaskTable) handlerListOperation(bdl protocol.ContextBundle, c *a
521521
e.State.PageNo = DefaultPageNo
522522
e.State.PageSize = DefaultPageSize
523523
}
524+
525+
if e.State.PipelineDetail == nil {
526+
c.Data = map[string]interface{}{}
527+
return nil
528+
}
524529
if e.State.PipelineDetail.ID == 0 {
525530
c.Data = map[string]interface{}{}
526531
return nil
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 executeTaskTable
16+
17+
import (
18+
"context"
19+
"testing"
20+
21+
"github.com/alecthomas/assert"
22+
23+
"github.com/erda-project/erda/apistructs"
24+
protocol "github.com/erda-project/erda/modules/openapi/component-protocol"
25+
)
26+
27+
func Test_handlerListOperation(t *testing.T) {
28+
ctx := protocol.ContextBundle{
29+
InParams: map[string]interface{}{},
30+
}
31+
ctx1 := context.WithValue(context.Background(), protocol.GlobalInnerKeyCtxBundle.String(), ctx)
32+
a := &ExecuteTaskTable{}
33+
a.State.PipelineDetail = nil
34+
err := a.Render(ctx1, &apistructs.Component{}, apistructs.ComponentProtocolScenario{},
35+
apistructs.ComponentEvent{
36+
Operation: apistructs.ExecuteChangePageNoOperationKey,
37+
OperationData: nil,
38+
}, nil)
39+
assert.NoError(t, err)
40+
a.State.PipelineDetail = &apistructs.PipelineDetailDTO{
41+
PipelineDTO: apistructs.PipelineDTO{
42+
ID: 0,
43+
},
44+
}
45+
assert.NoError(t, err)
46+
}

modules/openapi/component-protocol/scenarios/auto-test-plan-list/components/table/render.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,11 @@ func convertSortData(req *apistructs.TestPlanV2PagingRequest, c *apistructs.Comp
264264
}
265265

266266
func convertExecuteTime(data *apistructs.TestPlanV2) string {
267-
executeTime := ""
268-
if data.ExecuteTime != nil {
269-
executeTime = data.ExecuteTime.Format("2006-01-02 15:04:05")
270-
}
271-
if executeTime == "0001-01-01 00:00:00" {
272-
executeTime = ""
267+
if data.ExecuteTime == nil {
268+
return ""
273269
}
270+
var executeTime string
271+
executeTime = data.ExecuteTime.Format("2006-01-02 15:04:05")
274272
return executeTime
275273
}
276274

modules/openapi/component-protocol/scenarios/auto-test-plan-list/components/table/table_test.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,21 @@ func Test_ConvertSortData(t *testing.T) {
5959
}
6060

6161
func Test_executeTime(t *testing.T) {
62-
time := time.Now()
63-
data := &apistructs.TestPlanV2{
64-
ExecuteTime: nil,
62+
nowTime := time.Now()
63+
var data = []*apistructs.TestPlanV2{
64+
{
65+
ExecuteTime: nil,
66+
},
67+
{
68+
ExecuteTime: &nowTime,
69+
},
6570
}
66-
executeTime := convertExecuteTime(data)
67-
want := ""
68-
assert.Equal(t, want, executeTime)
69-
70-
data = &apistructs.TestPlanV2{
71-
ExecuteTime: &time,
71+
want := []string{
72+
"",
73+
nowTime.Format("2006-01-02 15:04:05"),
74+
}
75+
for i := range data {
76+
executeTime := convertExecuteTime(data[i])
77+
assert.Equal(t, executeTime, want[i])
7278
}
73-
executeTime = convertExecuteTime(data)
74-
want = time.Format("2006-01-02 15:04:05")
75-
assert.Equal(t, want, executeTime)
7679
}

0 commit comments

Comments
 (0)