Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/autotest file record #2624

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
83 changes: 39 additions & 44 deletions modules/dop/services/autotest_v2/space_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,54 +493,49 @@ func (a *AutoTestSpaceData) Copy() (*apistructs.AutoTestSpace, error) {
return nil, err
}

go func() {
var err error

defer func() {
// unlock source space
if a.IsCopy {
if err := a.unlockSourceSpace(); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return
}
defer func() {
// unlock source space
if a.IsCopy {
if err := a.unlockSourceSpace(); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return
}
if err != nil {
a.NewSpace.Status = apistructs.TestSpaceFailed
if _, err := a.svc.UpdateAutoTestSpace(*a.NewSpace, a.UserID); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return
}
}
}()

if err = a.CopySceneSets(); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return
}
if err = a.CopyScenes(); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return
}
if err = a.CopySceneSteps(); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return
}
if err = a.CopyInputs(); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return
}
if err = a.CopyOutputs(); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return
}
a.NewSpace.Status = apistructs.TestSpaceOpen
if _, err = a.svc.UpdateAutoTestSpace(*a.NewSpace, a.UserID); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return
if err != nil {
a.NewSpace.Status = apistructs.TestSpaceFailed
if _, err := a.svc.UpdateAutoTestSpace(*a.NewSpace, a.UserID); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return
}
}

return
}()

if err = a.CopySceneSets(); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return a.NewSpace, err
}
if err = a.CopyScenes(); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return a.NewSpace, err
}
if err = a.CopySceneSteps(); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return a.NewSpace, err
}
if err = a.CopyInputs(); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return a.NewSpace, err
}
if err = a.CopyOutputs(); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return a.NewSpace, err
}
a.NewSpace.Status = apistructs.TestSpaceOpen
if _, err = a.svc.UpdateAutoTestSpace(*a.NewSpace, a.UserID); err != nil {
logrus.Error(apierrors.ErrCopyAutoTestSpace.InternalError(err))
return a.NewSpace, err
}

return a.NewSpace, nil
}

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,6 +84,9 @@ func (ca *ComponentAction) Render(ctx context.Context, c *apistructs.Component,
}
c.State["createStepID"] = stepID
c.State["visible"] = false
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