Skip to content

Commit

Permalink
Automated test step running uses the last execution record of the cur…
Browse files Browse the repository at this point in the history
…rent scene to render the ${{ outputs.xxx.xxx }} placeholders in it (#1781)
  • Loading branch information
kakj-go authored Sep 10, 2021
1 parent d85b150 commit af547b8
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions modules/dop/services/autotest_v2/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ func (svc *Service) ExecuteDiceAutotestSceneStep(req apistructs.AutotestExecuteS
apiTestStr = strings.ReplaceAll(apiTestStr, expression.OldLeftPlaceholder+expression.Params+"."+param.Name+expression.OldRightPlaceholder, expression.ReplaceRandomParams(param.Temp))
}

apiTestStr = svc.renderPreSceneStepsOutput(step.SceneID, apiTestStr)

for _, conf := range configs.Data {
switch conf.Key {
case autotest.CmsCfgKeyAPIGlobalConfig:
Expand Down Expand Up @@ -596,6 +598,50 @@ func (svc *Service) ExecuteDiceAutotestSceneStep(req apistructs.AutotestExecuteS
return &respData, nil
}

func (svc *Service) renderPreSceneStepsOutput(sceneID uint64, replaceYml string) string {
var pipelinePageListRequest = apistructs.PipelinePageListRequest{
PageNum: 1,
PageSize: 1,
Sources: []apistructs.PipelineSource{
apistructs.PipelineSourceAutoTest,
},
YmlNames: []string{
strconv.Itoa(int(sceneID)),
},
Statuses: []string{apistructs.PipelineStatusSuccess.String(), apistructs.PipelineStatusFailed.String()},
DescCols: []string{"id"},
}
pagePipeline, err := svc.bdl.PageListPipeline(pipelinePageListRequest)
if err != nil {
logrus.Errorf("renderPreSceneStepsOutput, pageListPipeline error %v", err)
return replaceYml
}

if pagePipeline == nil || len(pagePipeline.Pipelines) <= 0 {
return replaceYml
}

pipeline, err := svc.bdl.GetPipeline(pagePipeline.Pipelines[0].ID)
if err != nil {
logrus.Errorf("renderPreSceneStepsOutput, GetPipeline error %v", err)
return replaceYml
}

if pipeline == nil {
return replaceYml
}

for _, stage := range pipeline.PipelineStages {
for _, task := range stage.PipelineTasks {
for _, result := range task.Result.Metadata {
replaceYml = strings.ReplaceAll(replaceYml, expression.GenOutputRef(task.Name, result.Name), result.Value)
}
}
}

return replaceYml
}

func (svc *Service) SceneToYml(scene uint64) (string, error) {
sceneInputs, err := svc.ListAutoTestSceneInput(scene)
if err != nil {
Expand Down

0 comments on commit af547b8

Please sign in to comment.