Skip to content

Commit

Permalink
Feature/autotest scene set export import (#2470)
Browse files Browse the repository at this point in the history
* autotest scene set export

* autotest scene set import

* autotest scene set protocol
  • Loading branch information
chengjoey authored Oct 22, 2021
1 parent 6f09169 commit 5b52eb2
Show file tree
Hide file tree
Showing 34 changed files with 1,560 additions and 281 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE dice_test_file_records ADD COLUMN `space_id` int(11) DEFAULT false COMMENT 'autotest space id';
56 changes: 56 additions & 0 deletions apistructs/autotest_scene_set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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

type TestSceneSetFileType string

var (
TestSceneSetFileTypeExcel TestSceneSetFileType = "excel"
)

func (t TestSceneSetFileType) Valid() bool {
switch t {
case TestSceneSetFileTypeExcel:
return true
default:
return false
}
}

// AutoTestSceneSetExportRequest export autotest scene set
type AutoTestSceneSetExportRequest struct {
ID uint64 `json:"id"`
Locale string `schema:"-"`
IsCopy bool `json:"-"`
FileType TestSceneSetFileType `schema:"fileType"`
SceneSetName string `json:"sceneSetName"`
SpaceID uint64 `json:"spaceID"`
ProjectID uint64 `json:"projectID"`

IdentityInfo
}

type AutoTestSceneSetImportRequest struct {
ProjectID uint64 `schema:"projectID"`
SpaceID uint64 `schema:"spaceID"`
FileType TestSceneSetFileType `schema:"fileType"`

IdentityInfo
}

type AutoTestSceneSetImportResponse struct {
Header
Data uint64 `json:"data"`
}
1 change: 1 addition & 0 deletions apistructs/component_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ const (
UpdateSceneOperationKey OperationKey = "UpdateScene"
DeleteSceneOperationKey OperationKey = "DeleteScene"
DeleteSceneSetOperationKey OperationKey = "DeleteSceneSet"
ExportSceneSetOperationKey OperationKey = "exportSceneSet"
ClickAddSceneSeButtonOperationKey OperationKey = "ClickAddSceneSet"
DragSceneSetOperationKey OperationKey = "DragSceneSet"
CopySceneOperationKey OperationKey = "CopyScene"
Expand Down
33 changes: 22 additions & 11 deletions apistructs/file_records.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type TestFileRecord struct {
ProjectID uint64 `json:"projectID"`
TestSetID uint64 `json:"testSetID"`
ApiFileUUID string `json:"apiFileUUID"`
SpaceID uint64 `json:"spaceID"`
Type FileActionType `json:"type"`
State FileRecordState `json:"state"`
CreatedAt time.Time `json:"createdAt"`
Expand All @@ -38,6 +39,7 @@ type TestFileRecordRequest struct {
ID uint64 `json:"id"`
FileName string `json:"name"`
ProjectID uint64 `json:"projectID"`
SpaceID uint64 `json:"spaceID"`
Description string `json:"description"`
ApiFileUUID string `json:"apiFileUUID"`
Type FileActionType `json:"type"`
Expand All @@ -47,8 +49,9 @@ type TestFileRecordRequest struct {
}

type TestFileExtra struct {
ManualTestFileExtraInfo *ManualTestFileExtraInfo `json:"manualTestExtraFileInfo,omitempty"`
AutotestSpaceFileExtraInfo *AutoTestSpaceFileExtraInfo `json:"autotestSpaceFileExtraInfo,omitempty"`
ManualTestFileExtraInfo *ManualTestFileExtraInfo `json:"manualTestExtraFileInfo,omitempty"`
AutotestSpaceFileExtraInfo *AutoTestSpaceFileExtraInfo `json:"autotestSpaceFileExtraInfo,omitempty"`
AutotestSceneSetFileExtraInfo *AutoTestSceneSetFileExtraInfo `json:"autotestSceneSetFileExtraInfo,omitempty"`
}

type ManualTestFileExtraInfo struct {
Expand All @@ -63,24 +66,32 @@ type AutoTestSpaceFileExtraInfo struct {
ExportRequest *AutoTestSpaceExportRequest `json:"exportRequest,omitempty"`
}

type AutoTestSceneSetFileExtraInfo struct {
ExportRequest *AutoTestSceneSetExportRequest `json:"exportRequest,omitempty"`
ImportRequest *AutoTestSceneSetImportRequest `json:"importRequest"`
}

type FileRecordState string

type FileActionType string

const (
FileRecordStatePending FileRecordState = "pending"
FileRecordStateProcessing FileRecordState = "processing"
FileRecordStateSuccess FileRecordState = "success"
FileRecordStateFail FileRecordState = "fail"
FileActionTypeCopy FileActionType = "copy"
FileActionTypeImport FileActionType = "import"
FileActionTypeExport FileActionType = "export"
FileSpaceActionTypeExport FileActionType = "spaceExport"
FileSpaceActionTypeImport FileActionType = "spaceImport"
FileRecordStatePending FileRecordState = "pending"
FileRecordStateProcessing FileRecordState = "processing"
FileRecordStateSuccess FileRecordState = "success"
FileRecordStateFail FileRecordState = "fail"
FileActionTypeCopy FileActionType = "copy"
FileActionTypeImport FileActionType = "import"
FileActionTypeExport FileActionType = "export"
FileSpaceActionTypeExport FileActionType = "spaceExport"
FileSpaceActionTypeImport FileActionType = "spaceImport"
FileSceneSetActionTypeExport FileActionType = "sceneSetExport"
FileSceneSetActionTypeImport FileActionType = "sceneSetImport"
)

type ListTestFileRecordsRequest struct {
ProjectID uint64 `json:"projectID"`
SpaceID uint64 `json:"spaceID"`
Types []FileActionType `json:"types"`
Locale string `json:"locale"`
}
Expand Down
18 changes: 18 additions & 0 deletions bundle/autotest_sceneset.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,21 @@ func (b *Bundle) DragSceneSet(req apistructs.SceneSetRequest) error {
}
return nil
}

// ExportAutotestSceneSet export autotest scene set
func (b *Bundle) ExportAutotestSceneSet(userID string, req apistructs.AutoTestSceneSetExportRequest) error {
host, err := b.urls.DOP()
if err != nil {
return err
}
hc := b.hc
var exportID uint64
_, err = hc.Post(host).Path("/api/autotests/scenesets/actions/export").
Header(httputil.UserHeader, userID).
JSONBody(req).Do().JSON(&exportID)
if err != nil {
return apierrors.ErrInvoke.InternalError(err)
}

return nil
}
3 changes: 3 additions & 0 deletions conf/dop/dop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ component-protocol.components.code-coverage.tip:
component-protocol.components.code-coverage.executeHistoryButton:
component-protocol.components.code-coverage.downloadButton:

component-protocol.components.scenes-import-record.filter:
component-protocol.components.scenes-import-record.table:




Expand Down
34 changes: 34 additions & 0 deletions conf/dop/i18n/component-protocol.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@ zh:
mt-plan-chart: 手动测试计划分布图
at-case-rate-trending-chart: 自动化测试执行率和通过率趋势
at-plan-latest-waterfall-chart: 自动化测试计划执行详情瀑布图
import: 导入
export: 导出
scene-set-export-confirm: 是否确认导出
scene-set-export-success-msg: 导出任务已创建, 请在导入导出记录表中查看进度
status-success: 成功
status-failed: 失败,
status-pending: 排队中
status-processing: 进行中
download-file: 下载文件
import-export-record: 导入导出记录
import-export-table: 导入导出记录表
type: 类型
operator: 操作人
time: 时间
desc: 描述
status: 状态
result: 结果
en:
issue-manage: issue manage
issue: issue
Expand Down Expand Up @@ -194,6 +211,23 @@ en:
board-view: Board View
custom: Custom
state: State
import: Import
export: Export
scene-set-export-confirm: Are you sure to export?
scene-set-export-success-msg: The export task has been created, please check the progress in the import and export record table
status-success: Success
status-failed: Failed,
status-pending: Pending
status-processing: Processing
download-file: Download File
import-export-record: Import and export records
import-export-table: Import and export records table
type: Type
operator: Operator
time: Time,
desc: Description
status: Status
result: Result
test-case-num-total: Test Case Total Number
test-case-num-done: Finished
test-case-num-block: Block
Expand Down
1 change: 1 addition & 0 deletions conf/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ openapi-v1-routes:
- issue-manage
- issue-dashboard
- code-coverage
- scenes-import-record
- addr: http://localhost:8080
scenarios:
- demo
Expand Down
1 change: 1 addition & 0 deletions modules/dop/component-protocol/components/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ import (
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/code-coverage"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-dashboard"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/issue-manage"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/scenes-import-record"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/test-dashboard"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 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 filter

import (
"context"
"encoding/json"

"github.com/sirupsen/logrus"

"github.com/erda-project/erda-infra/base/servicehub"
"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
"github.com/erda-project/erda/modules/openapi/component-protocol/components/base"
)

type ComponentAction struct {
base.DefaultProvider

Name string `json:"name"`
Type string `json:"type"`
State State `json:"state"`
Props map[string]interface{} `json:"props"`
Operations map[string]interface{} `json:"operations"`
}

type State struct {
Conditions []interface{} `json:"conditions"`
Values struct {
Type []string `json:"type"`
} `json:"values"`
}

func (i *ComponentAction) GenComponentState(c *cptype.Component) error {
if c == nil || c.State == nil {
return nil
}
var state State
cont, err := json.Marshal(c.State)
if err != nil {
logrus.Errorf("marshal component state failed, content:%v, err:%v", c.State, err)
return err
}
err = json.Unmarshal(cont, &state)
if err != nil {
logrus.Errorf("unmarshal component state failed, content:%v, err:%v", cont, err)
return err
}
i.State = state
return nil
}

func (ca *ComponentAction) Render(ctx context.Context, c *cptype.Component, scenario cptype.Scenario, event cptype.ComponentEvent, gs *cptype.GlobalStateData) error {
if err := ca.GenComponentState(c); err != nil {
return err
}
ca.Props = map[string]interface{}{
"delay": 1000,
}
ca.State.Conditions = []interface{}{
map[string]interface{}{
"emptyText": "全部",
"fixed": true,
"key": "type",
"label": "类型",
"options": []interface{}{
map[string]interface{}{
"label": "导入",
"value": "import",
},
map[string]interface{}{
"label": "导出",
"value": "export",
},
},
"type": "select",
},
}
ca.Operations = map[string]interface{}{
"filter": map[string]interface{}{
"key": "filter",
"reload": true,
},
}
return nil
}

func init() {
base.InitProviderWithCreator("scenes-import-record", "filter", func() servicehub.Provider {
return &ComponentAction{}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package leftHeadButton
package scenes_import_record

import (
protocol "github.com/erda-project/erda/modules/openapi/component-protocol"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/scenes-import-record/filter"
_ "github.com/erda-project/erda/modules/dop/component-protocol/components/scenes-import-record/table"
)

type ComponentleftHeadButtonModal struct {
CtxBdl protocol.ContextBundle
Props map[string]interface{} `json:"props"`
Operations map[string]interface{} `json:"operations"`
State State `json:"state"`
}

type State struct {
ActionType string `json:"actionType"`
FormVisible bool `json:"formVisible"`
}

type Operation struct {
Key string `json:"key"`
Reload bool `json:"reload"`
}
Loading

0 comments on commit 5b52eb2

Please sign in to comment.