Skip to content

Commit

Permalink
don't need use goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey committed Oct 27, 2021
1 parent 87c450d commit 468100d
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 4 deletions.
3 changes: 2 additions & 1 deletion modules/dop/services/autotest_v2/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package autotestv2

import (
"bytes"
"fmt"
"io/ioutil"
"strconv"

Expand Down Expand Up @@ -256,7 +257,7 @@ func (svc *Service) ExportSceneSet(req apistructs.AutoTestSceneSetExportRequest)
}

l := svc.bdl.GetLocale(req.Locale)
fileName := l.Get(i18n.I18nKeySceneSetSheetName)
fileName := fmt.Sprintf("%s-%s", l.Get(i18n.I18nKeySceneSetSheetName), req.SceneSetName)
if req.FileType == apistructs.TestSceneSetFileTypeExcel {
fileName += ".xlsx"
}
Expand Down
113 changes: 113 additions & 0 deletions modules/dop/services/autotest_v2/space_data_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// 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 autotestv2

import (
"fmt"
"reflect"
"testing"

"bou.ke/monkey"
"github.com/stretchr/testify/assert"

"github.com/erda-project/erda/apistructs"
)

func TestCopy(t *testing.T) {
a := &AutoTestSpaceData{
Space: &apistructs.AutoTestSpace{Status: "open"},
IsCopy: true,
NewSpace: &apistructs.AutoTestSpace{},
IdentityInfo: apistructs.IdentityInfo{UserID: "1"},
Steps: map[uint64][]apistructs.AutoTestSceneStep{
1: []apistructs.AutoTestSceneStep{},
},
Scenes: map[uint64][]apistructs.AutoTestScene{
1: []apistructs.AutoTestScene{},
},
}
m1 := monkey.PatchInstanceMethod(reflect.TypeOf(a), "CreateNewSpace",
func(a *AutoTestSpaceData) error {
return nil
})
defer m1.Unpatch()

autotestSvc := New()
a.svc = autotestSvc

m2 := monkey.PatchInstanceMethod(reflect.TypeOf(autotestSvc), "UpdateAutoTestSpace",
func(svc *Service, req apistructs.AutoTestSpace, UserID string) (*apistructs.AutoTestSpace, error) {
return &apistructs.AutoTestSpace{}, nil
})
defer m2.Unpatch()

m3 := monkey.PatchInstanceMethod(reflect.TypeOf(a), "CopySceneSets",
func(a *AutoTestSpaceData) error {
return nil
})
defer m3.Unpatch()

m4 := monkey.PatchInstanceMethod(reflect.TypeOf(a), "CopyScenes",
func(a *AutoTestSpaceData) error {
return nil
})
defer m4.Unpatch()

m5 := monkey.PatchInstanceMethod(reflect.TypeOf(a), "CopySceneSteps",
func(a *AutoTestSpaceData) error {
return nil
})
defer m5.Unpatch()

m6 := monkey.PatchInstanceMethod(reflect.TypeOf(a), "CopyInputs",
func(a *AutoTestSpaceData) error {
if len(a.Steps) == 0 {
return fmt.Errorf("invalid steps")
}
return nil
})
defer m6.Unpatch()

m7 := monkey.PatchInstanceMethod(reflect.TypeOf(a), "CopyOutputs",
func(a *AutoTestSpaceData) error {
if len(a.Scenes) == 0 {
return fmt.Errorf("invalid steps")
}
return nil
})
defer m7.Unpatch()

_, err := a.Copy()
assert.NoError(t, err)
emptyStepsData := &AutoTestSpaceData{
Space: &apistructs.AutoTestSpace{Status: "open"},
IsCopy: true,
NewSpace: &apistructs.AutoTestSpace{},
IdentityInfo: apistructs.IdentityInfo{UserID: "1"},
}
_, err = emptyStepsData.Copy()
assert.Equal(t, false, err == nil)
emptyScenesData := &AutoTestSpaceData{
Space: &apistructs.AutoTestSpace{Status: "open"},
IsCopy: true,
NewSpace: &apistructs.AutoTestSpace{},
IdentityInfo: apistructs.IdentityInfo{UserID: "1"},
Steps: map[uint64][]apistructs.AutoTestSceneStep{
1: []apistructs.AutoTestSceneStep{},
},
}
_, err = emptyScenesData.Copy()
assert.Equal(t, false, err == nil)
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func (ca *ComponentAction) Render(ctx context.Context, c *apistructs.Component,
}
c.State["createStepID"] = stepID
c.State["visible"] = false
c.State["apiText"] = ""
c.State["formData"] = map[string]string{
"apiText": "",
}
case apistructs.InitializeOperation, apistructs.RenderingOperation:
c.Props = map[string]interface{}{
"width": 850,
Expand Down
4 changes: 2 additions & 2 deletions pkg/erda-configs/i18n/qa.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"tp.export.space.project.num": "项目编号",
"tp.export.space.description": "测试空间描述",

"tp.export.scene.set.sheet.name": "自动化测试场景集",
"tp.export.scene.set.sheet.name": "场景集",
"tp.export.scene.set.num": "用例编号",
"tp.export.scene.set.name": "场景集名称",
"tp.export.scene.set.space.num": "测试空间编号",
Expand Down Expand Up @@ -128,7 +128,7 @@
"tp.export.space.project.num": "project num",
"tp.export.space.description": "description",

"tp.export.scene.set.sheet.name": "AutoTest SceneSet",
"tp.export.scene.set.sheet.name": "SceneSet",
"tp.export.scene.set.num": "scene set num",
"tp.export.scene.set.name": "scene set name",
"tp.export.scene.set.space.num": "space num",
Expand Down

0 comments on commit 468100d

Please sign in to comment.