Skip to content

Commit f9e8d8a

Browse files
erda-botchengjoey
andauthored
fix imported autotest config sheet display outputs error (#2609) (#2614)
Co-authored-by: chengjoey <[email protected]>
1 parent 3d9d339 commit f9e8d8a

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
lines changed

modules/openapi/component-protocol/pkg/autotest/step/output.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ package step
1616

1717
import (
1818
"encoding/json"
19+
"fmt"
1920
"strconv"
2021

2122
"github.com/erda-project/erda/apistructs"
2223
"github.com/erda-project/erda/bundle"
24+
protocol "github.com/erda-project/erda/modules/openapi/component-protocol"
2325
"github.com/erda-project/erda/pkg/expression"
2426
)
2527

@@ -29,14 +31,14 @@ type APISpec struct {
2931
Loop *apistructs.PipelineTaskLoop `json:"loop"`
3032
}
3133

32-
func GetStepAllOutput(steps []apistructs.AutoTestSceneStep, bdl *bundle.Bundle) (map[string]map[string]string, error) {
34+
func GetStepAllOutput(steps []apistructs.AutoTestSceneStep, bdl *bundle.Bundle, gs *apistructs.GlobalStateData) (map[string]map[string]string, error) {
3335
var outputs = map[string]map[string]string{}
3436
apiOutput, err := buildStepOutPut(steps)
3537
if err != nil {
3638
return nil, err
3739
}
3840

39-
configSheetOutput, err := buildConfigSheetStepOutPut(steps, bdl)
41+
configSheetOutput, err := buildConfigSheetStepOutPut(steps, bdl, gs)
4042
if err != nil {
4143
return nil, err
4244
}
@@ -132,7 +134,7 @@ func MakeStepOutputSelectKey(stepID string, stepName string, key string) string
132134
return "#" + stepID + "-" + stepName + ":" + key
133135
}
134136

135-
func buildConfigSheetStepOutPut(steps []apistructs.AutoTestSceneStep, bdl *bundle.Bundle) (map[string]map[string]string, error) {
137+
func buildConfigSheetStepOutPut(steps []apistructs.AutoTestSceneStep, bdl *bundle.Bundle, gs *apistructs.GlobalStateData) (map[string]map[string]string, error) {
136138

137139
outputs := make(map[string]map[string]string, 0)
138140

@@ -177,7 +179,7 @@ func buildConfigSheetStepOutPut(steps []apistructs.AutoTestSceneStep, bdl *bundl
177179
req.SnippetConfigs = snippetConfigs
178180
detail, err := bdl.GetPipelineActionParamsAndOutputs(req)
179181
if err != nil {
180-
return nil, err
182+
(*gs)[protocol.GlobalInnerKeyError.String()] = fmt.Sprintf("failed to query step outputs, please check config sheets")
181183
}
182184

183185
for alias, detail := range detail {
@@ -198,7 +200,7 @@ func buildConfigSheetStepOutPut(steps []apistructs.AutoTestSceneStep, bdl *bundl
198200
return outputs, nil
199201
}
200202

201-
func GetConfigSheetStepOutPut(steps []apistructs.AutoTestSceneStep, bdl *bundle.Bundle) (map[string]map[string]string, error) {
203+
func GetConfigSheetStepOutPut(steps []apistructs.AutoTestSceneStep, bdl *bundle.Bundle, gs *apistructs.GlobalStateData) (map[string]map[string]string, error) {
202204

203205
outputs := make(map[string]map[string]string, 0)
204206

@@ -247,7 +249,7 @@ func GetConfigSheetStepOutPut(steps []apistructs.AutoTestSceneStep, bdl *bundle.
247249
req.SnippetConfigs = snippetConfigs
248250
detail, err := bdl.GetPipelineActionParamsAndOutputs(req)
249251
if err != nil {
250-
return nil, err
252+
(*gs)[protocol.GlobalInnerKeyError.String()] = fmt.Sprintf("failed to query step outputs, err: %v", err)
251253
}
252254

253255
for alias, detail := range detail {

modules/openapi/component-protocol/pkg/autotest/step/output_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,14 @@ func TestGetStepAllOutput(t *testing.T) {
187187
t.Run(tt.name, func(t *testing.T) {
188188
var bdl = &bundle.Bundle{}
189189
var patch *monkey.PatchGuard
190+
var gs = &apistructs.GlobalStateData{}
190191
if tt.args.ConfigOutput != nil {
191192
patch = monkey.PatchInstanceMethod(reflect.TypeOf(bdl), "GetPipelineActionParamsAndOutputs", func(b *bundle.Bundle, req apistructs.SnippetQueryDetailsRequest) (map[string]apistructs.SnippetQueryDetail, error) {
192193
return tt.args.ConfigOutput, nil
193194
})
194195
}
195196

196-
got, err := GetStepAllOutput(tt.args.steps, bdl)
197+
got, err := GetStepAllOutput(tt.args.steps, bdl, gs)
197198
if (err != nil) != tt.wantErr {
198199
t.Errorf("GetStepAllOutput() error = %v, wantErr %v", err, tt.wantErr)
199200
return
@@ -288,13 +289,14 @@ func TestGetConfigSheetStepOutPut(t *testing.T) {
288289

289290
var bdl = &bundle.Bundle{}
290291
var patch *monkey.PatchGuard
292+
var gs = &apistructs.GlobalStateData{}
291293
if tt.args.ConfigOutput != nil {
292294
patch = monkey.PatchInstanceMethod(reflect.TypeOf(bdl), "GetPipelineActionParamsAndOutputs", func(b *bundle.Bundle, req apistructs.SnippetQueryDetailsRequest) (map[string]apistructs.SnippetQueryDetail, error) {
293295
return tt.args.ConfigOutput, nil
294296
})
295297
}
296298

297-
got, err := GetConfigSheetStepOutPut(tt.args.steps, bdl)
299+
got, err := GetConfigSheetStepOutPut(tt.args.steps, bdl, gs)
298300
if (err != nil) != tt.wantErr {
299301
t.Errorf("GetConfigSheetStepOutPut() error = %v, wantErr %v", err, tt.wantErr)
300302
return

modules/openapi/component-protocol/scenarios/auto-test-scenes/components/apiEditor/render.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ LABEL:
185185
}
186186
inputs = append(inputs, Input{Label: "前置接口出参", Value: "前置接口出参", IsLeaf: false, Children: stepChildren1})
187187

188-
maps, err = step.GetConfigSheetStepOutPut(steps, bdl.Bdl)
188+
maps, err = step.GetConfigSheetStepOutPut(steps, bdl.Bdl, gs)
189189
if err != nil {
190190
return err
191191
}

modules/openapi/component-protocol/scenarios/auto-test-scenes/components/configSheetInParams/render.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ func (ca *ComponentAction) Render(ctx context.Context, c *apistructs.Component,
175175
return err
176176
}
177177
case apistructs.InitializeOperation, apistructs.RenderingOperation:
178-
err := ca.handleDefault()
178+
err := ca.handleDefault(gs)
179179
if err != nil {
180180
return err
181181
}
182182
}
183183
return nil
184184
}
185185

186-
func (i *ComponentAction) handleDefault() error {
186+
func (i *ComponentAction) handleDefault(gs *apistructs.GlobalStateData) error {
187187
// 选中的 step
188188
var configSheetID string
189189
var autotestGetSceneStepReq apistructs.AutotestGetSceneStepReq
@@ -233,7 +233,8 @@ func (i *ComponentAction) handleDefault() error {
233233
}
234234
result, err := i.CtxBdl.Bdl.GetFileTreeNode(req, uint64(orgID))
235235
if err != nil {
236-
return err
236+
(*gs)[protocol.GlobalInnerKeyError.String()] = fmt.Sprintf("failed to query file tree nodes, please check config sheets")
237+
result = &apistructs.UnifiedFileTreeNode{Meta: map[string]interface{}{}}
237238
}
238239
_, ok := result.Meta[apistructs.AutoTestFileTreeNodeMetaKeyPipelineYml]
239240
if ok {

modules/openapi/component-protocol/scenarios/auto-test-scenes/components/outPutForm/outPutForm.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/erda-project/erda/modules/openapi/component-protocol/pkg/autotest/step"
2222
)
2323

24-
func (i *ComponentOutPutForm) SetProps() error {
24+
func (i *ComponentOutPutForm) SetProps(gs *apistructs.GlobalStateData) error {
2525
paramsNameProp := PropColumn{
2626
Title: "参数名",
2727
Key: PropsKeyParamsName,
@@ -58,7 +58,7 @@ func (i *ComponentOutPutForm) SetProps() error {
5858
Props: PropRenderProp{},
5959
},
6060
}
61-
lt, err := i.RenderOnChange()
61+
lt, err := i.RenderOnChange(gs)
6262
if err != nil {
6363
return err
6464
}
@@ -67,7 +67,7 @@ func (i *ComponentOutPutForm) SetProps() error {
6767
return nil
6868
}
6969

70-
func (i *ComponentOutPutForm) RenderListOutPutForm() error {
70+
func (i *ComponentOutPutForm) RenderListOutPutForm(gs *apistructs.GlobalStateData) error {
7171
rsp, err := i.ctxBdl.Bdl.ListAutoTestSceneOutput(i.State.AutotestSceneRequest)
7272
if err != nil {
7373
return err
@@ -83,7 +83,7 @@ func (i *ComponentOutPutForm) RenderListOutPutForm() error {
8383
list = append(list, pd)
8484
}
8585
i.Data.List = list
86-
if err = i.SetProps(); err != nil {
86+
if err = i.SetProps(gs); err != nil {
8787
return err
8888
}
8989
return nil
@@ -104,7 +104,7 @@ func (i *ComponentOutPutForm) RenderUpdateOutPutForm() error {
104104
}
105105

106106
// 可编辑器的初始值
107-
func (i *ComponentOutPutForm) RenderOnChange() ([]PropChangeOption, error) {
107+
func (i *ComponentOutPutForm) RenderOnChange(gs *apistructs.GlobalStateData) ([]PropChangeOption, error) {
108108
list, err := i.ctxBdl.Bdl.ListAutoTestSceneStep(i.State.AutotestSceneRequest)
109109
if err != nil {
110110
return nil, err
@@ -123,7 +123,7 @@ func (i *ComponentOutPutForm) RenderOnChange() ([]PropChangeOption, error) {
123123
stepNameMap[strconv.FormatUint(s.ID, 10)] = s.Name
124124
}
125125

126-
outputs, err := step.GetStepAllOutput(steps, i.ctxBdl.Bdl)
126+
outputs, err := step.GetStepAllOutput(steps, i.ctxBdl.Bdl, gs)
127127
if err != nil {
128128
return nil, err
129129
}

modules/openapi/component-protocol/scenarios/auto-test-scenes/components/outPutForm/render.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (i *ComponentOutPutForm) Render(ctx context.Context, c *apistructs.Componen
143143

144144
switch event.Operation {
145145
case apistructs.InitializeOperation, apistructs.RenderingOperation:
146-
err = i.RenderListOutPutForm()
146+
err = i.RenderListOutPutForm(gs)
147147
if err != nil {
148148
return err
149149
}
@@ -152,7 +152,7 @@ func (i *ComponentOutPutForm) Render(ctx context.Context, c *apistructs.Componen
152152
if err != nil {
153153
return err
154154
}
155-
err = i.RenderListOutPutForm()
155+
err = i.RenderListOutPutForm(gs)
156156
if err != nil {
157157
return err
158158
}

0 commit comments

Comments
 (0)