Esempio n. 1
0
func (parser *Parser) mapStage(stageMap map[interface{}]interface{},
	requiredStages map[string]map[interface{}]interface{}) (stages.Stage, error) {
	mergedStageMap, err := parser.extractStage(stageMap, requiredStages)
	if err != nil {
		return nil, err
	}
	stage, err := parser.initStage(mergedStageMap)
	if err != nil {
		return nil, err
	}

	if stageName := mergedStageMap["name"]; stageName != nil {
		stage.SetStageName(mergedStageMap["name"].(string))
	} else if stageName := mergedStageMap["stage_name"]; stageName != nil {
		log.Warn("found property \"stage_name\"")
		log.Warn("property \"stage_name\" is deprecated. please use \"stage\" instead.")
		stage.SetStageName(mergedStageMap["stage_name"].(string))
	}

	stageOpts := stages.NewStageOpts()
	if reportingFullOutput := mergedStageMap["report_full_output"]; reportingFullOutput != nil {
		stageOpts.ReportingFullOutput = true
	}
	stage.SetStageOpts(*stageOpts)

	newStageValue := reflect.ValueOf(stage).Elem()
	newStageType := reflect.TypeOf(stage).Elem()
	for i := 0; i < newStageType.NumField(); i++ {
		tagName := newStageType.Field(i).Tag.Get("config")
		isReplace := newStageType.Field(i).Tag.Get("is_replace")
		for stageOptKey, stageOptVal := range mergedStageMap {
			if tagName == stageOptKey {
				if stageOptVal == nil {
					log.Warnf("stage option \"%s\" is not specified", stageOptKey)
				} else {
					parser.setFieldVal(newStageValue.Field(i), stageOptVal, isReplace)
				}
			}
		}
	}

	parallelStages := mergedStageMap["parallel"]
	if parallelStages == nil {
		if parallelStages = mergedStageMap["run_after"]; parallelStages != nil {
			log.Warn("`run_after' will be obsoleted in near future. Use `parallel' instead.")
		}
	}

	if parallelStages != nil {
		for _, parallelStage := range parallelStages.([]interface{}) {
			childStage, err := parser.mapStage(parallelStage.(map[interface{}]interface{}), requiredStages)
			if err != nil {
				return nil, err
			}
			stage.AddChildStage(childStage)
		}
	}
	return stage, nil
}
Esempio n. 2
0
func TestReportStageResult(t *testing.T) {
	mock := &MockMessenger{}
	p := Resources{
		Reporter: mock,
	}

	stage := createStage("command")
	stage.SetStageName("test")

	opts := stages.NewStageOpts()

	stage.SetStageOpts(*opts)

	p.ReportStageResult(stage, "true")

	assert.Equal(t, 1, len(mock.Posts))
}