Skip to content

Commit

Permalink
Fix auto test space list pageNo reset (#3064) (#3071)
Browse files Browse the repository at this point in the history
* Fix auto test space list pageNo reset

* Add audit templates

* Fix unit test

Co-authored-by: shuofan <fanshuo2015@gmail.com>
  • Loading branch information
erda-bot and shuofan authored Nov 16, 2021
1 parent 789ba0c commit 81a71d6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
12 changes: 6 additions & 6 deletions apistructs/audits.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ const (
UpdateAppNotifyGroupTemplate TemplateName = "updateAppNotifyGroup"

// ========================Test Platform================================
QaTestEnvCreateTemplate TemplateName = "qaTestEnvCreate"
QaTestEnvUpdateTemplate TemplateName = "qaTestEnvUpdate"
QaTestEnvDeleteTemplate TemplateName = "qaTestEnvDelete"
ArchiveTestplanTemplate TemplateName = "archiveTestPlan"
UnarchiveTestPlanTemplate TemplateName = "unarchiveTestPlan"
UpdateAutoTestSpaceTemplate TemplateName = "updateAutoTestSpace"
QaTestEnvCreateTemplate TemplateName = "qaTestEnvCreate"
QaTestEnvUpdateTemplate TemplateName = "qaTestEnvUpdate"
QaTestEnvDeleteTemplate TemplateName = "qaTestEnvDelete"
ArchiveTestplanTemplate TemplateName = "archiveTestPlan"
UnarchiveTestPlanTemplate TemplateName = "unarchiveTestPlan"
UpdateAutoTestSpaceTemplatePrefix string = "updateAutoTestSpace"
// ========================cmdb==========================================
CreateCertificatesTemplate TemplateName = "createCertificates"
DeleteCertificatesTemplate TemplateName = "deleteCertificates"
Expand Down
13 changes: 13 additions & 0 deletions apistructs/autotest_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ const (
TestSpaceCompleted AutoTestSpaceArchiveStatus = "Completed"
)

func (s AutoTestSpaceArchiveStatus) GetZhName() string {
switch s {
case TestSpaceInit:
return "未开始"
case TestSpaceInProgress:
return "进行中"
case TestSpaceCompleted:
return "已完成"
default:
return ""
}
}

func (s AutoTestSpaceArchiveStatus) Valid() bool {
switch s {
case TestSpaceInit, TestSpaceInProgress, TestSpaceCompleted:
Expand Down
9 changes: 4 additions & 5 deletions modules/dop/services/autotest_v2/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,19 @@ func getChangedFields(autoTestSpace *dao.AutoTestSpace, req apistructs.AutoTestS
changedField := make(map[string][]string)
if len(req.Name) > 0 {
if req.Name != autoTestSpace.Name {
changedField["name"] = []string{autoTestSpace.Name, req.Name}
changedField["Name"] = []string{autoTestSpace.Name, req.Name}
}
autoTestSpace.Name = req.Name
}
if len(req.ArchiveStatus) > 0 {
if req.ArchiveStatus != autoTestSpace.ArchiveStatus {
changedField["archiveStatus"] = []string{string(autoTestSpace.ArchiveStatus), string(req.ArchiveStatus)}
changedField["ArchiveStatus"] = []string{autoTestSpace.ArchiveStatus.GetZhName(), req.ArchiveStatus.GetZhName()}
}
autoTestSpace.ArchiveStatus = req.ArchiveStatus
}
if len(req.Description) > 0 {
if req.Description != autoTestSpace.Description {
changedField["description"] = []string{autoTestSpace.Description, req.Description}
changedField["Description"] = []string{autoTestSpace.Description, req.Description}
}
autoTestSpace.Description = req.Description
}
Expand All @@ -198,11 +198,10 @@ func (svc *Service) createAudits(space *dao.AutoTestSpace, changedField map[stri
Result: "success",
StartTime: now,
EndTime: now,
TemplateName: apistructs.UpdateAutoTestSpaceTemplate,
TemplateName: apistructs.TemplateName(apistructs.UpdateAutoTestSpaceTemplatePrefix + i),
Context: map[string]interface{}{
"projectName": project.Name,
"spaceName": space.Name,
"field": i,
"from": v[0],
"to": v[1],
},
Expand Down
6 changes: 3 additions & 3 deletions modules/dop/services/autotest_v2/space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func Test_getChangedFields(t *testing.T) {
},
},
want: map[string][]string{
"name": {"space", "space1"},
"description": {"not a space", "a space"},
"archiveStatus": {"Init", "InProgress"},
"Name": {"space", "space1"},
"Description": {"not a space", "a space"},
"ArchiveStatus": {"未开始", "进行中"},
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ func (a *ComponentSpaceList) handlerListOperation(bdl protocol.ContextBundle, c
} else if a.State.PageSize != 10 && a.State.PageSize != 20 && a.State.PageSize != 50 && a.State.PageSize != 100 {
return fmt.Errorf("无效的pageSize")
}

if event.Operation == apistructs.InitializeOperation || event.Operation == apistructs.RenderingOperation {
a.State.PageNo = 1
}
// spaceList, err := bdl.Bdl.ListTestSpace(inParams.ProjectID, a.State.PageSize, a.State.PageNo, a.State.Values.Order)
spaceList, err := bdl.Bdl.ListTestSpace(apistructs.AutoTestSpaceListRequest{
ProjectID: inParams.ProjectID,
Expand Down
22 changes: 18 additions & 4 deletions pkg/erda-configs/audit/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1939,11 +1939,25 @@
"en": "Change MySQL account [@preMysqlUsername] -> [@mysqlUsername] for runtime [@runtimeName](runtimeDetailRoot) in [@projectName](project) / [@appName](app)"
}
},
"updateAutoTestSpace": {
"desc": "更新自动化测试空间",
"updateAutoTestSpaceName": {
"desc": "更新自动化测试空间名称",
"success": {
"zh": "在 [@projectName](project) 项目中, 更新了测试空间 [@spaceName] 的[@field], 由 [@from] 变成 [@to] ",
"en": "Update auto test space [@spaceName] [@field] from [@from] to [@to] in project [@projectName](project)"
"zh": "在 [@projectName](project) 项目中, 更新了测试空间 [@spaceName] 的名称, 由 [@from] 变成 [@to] ",
"en": "Update auto test space [@spaceName] name from [@from] to [@to] in project [@projectName](project)"
}
},
"updateAutoTestSpaceDescription": {
"desc": "更新自动化测试空间描述",
"success": {
"zh": "在 [@projectName](project) 项目中, 更新了测试空间 [@spaceName] 的描述, 由 [@from] 变成 [@to] ",
"en": "Update auto test space [@spaceName] description from [@from] to [@to] in project [@projectName](project)"
}
},
"updateAutoTestSpaceArchiveStatus": {
"desc": "更新自动化测试空间状态",
"success": {
"zh": "在 [@projectName](project) 项目中, 更新了测试空间 [@spaceName] 的状态, 由 [@from] 变成 [@to] ",
"en": "Update auto test space [@spaceName] archiveStatus from [@from] to [@to] in project [@projectName](project)"
}
}
}

0 comments on commit 81a71d6

Please sign in to comment.