本文整理匯總了Golang中github.com/evergreen-ci/evergreen/command.Expansions.Put方法的典型用法代碼示例。如果您正苦於以下問題:Golang Expansions.Put方法的具體用法?Golang Expansions.Put怎麽用?Golang Expansions.Put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/evergreen-ci/evergreen/command.Expansions
的用法示例。
在下文中一共展示了Expansions.Put方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestExpansionsPlugin
func TestExpansionsPlugin(t *testing.T) {
Convey("Should be able to update expansions", t, func() {
updateCommand := UpdateCommand{
Updates: []PutCommandParams{
{
Key: "base",
Value: "eggs",
},
{
Key: "topping",
Concat: ",sausage",
},
},
}
expansions := command.Expansions{}
expansions.Put("base", "not eggs")
expansions.Put("topping", "bacon")
taskConfig := model.TaskConfig{
Expansions: &expansions,
}
updateCommand.ExecuteUpdates(&taskConfig)
So(expansions.Get("base"), ShouldEqual, "eggs")
So(expansions.Get("topping"), ShouldEqual, "bacon,sausage")
})
}
示例2: buildMatrixVariant
// buildMatrixVariant does the heavy lifting of building a matrix variant based on axis information.
// We do this by iterating over all axes and merging the axis value's settings when applicable. Expansions
// are evaluated during this process. Rules are parsed and added to the resulting parserBV for later
// excecution.
func buildMatrixVariant(axes []matrixAxis, mv matrixValue, m *matrix, ase *axisSelectorEvaluator) (*parserBV, error) {
v := parserBV{
matrixVal: mv,
matrixId: m.Id,
Stepback: m.Stepback,
BatchTime: m.BatchTime,
Modules: m.Modules,
RunOn: m.RunOn,
Expansions: *command.NewExpansions(mv),
}
// we declare a separate expansion map for evaluating the display name
displayNameExp := command.Expansions{}
// build up the variant id while iterating through axis values
idBuf := bytes.Buffer{}
idBuf.WriteString(m.Id)
idBuf.WriteString("__")
// track how many axes we cover, so we know the value is only using real axes
usedAxes := 0
// we must iterate over axis definitions to have a consistent ordering for our axis priority
for _, a := range axes {
// skip any axes that aren't used in the variant's definition
if _, ok := mv[a.Id]; !ok {
continue
}
usedAxes++
axisVal, err := a.find(mv[a.Id])
if err != nil {
return nil, err
}
if err := v.mergeAxisValue(axisVal); err != nil {
return nil, fmt.Errorf("processing axis value %v,%v: %v", a.Id, axisVal.Id, err)
}
// for display names, fall back to the axis values id so we have *something*
if axisVal.DisplayName != "" {
displayNameExp.Put(a.Id, axisVal.DisplayName)
} else {
displayNameExp.Put(a.Id, axisVal.Id)
}
// append to the variant's name
idBuf.WriteString(a.Id)
idBuf.WriteRune('~')
idBuf.WriteString(axisVal.Id)
if usedAxes < len(mv) {
idBuf.WriteRune('_')
}
}
if usedAxes != len(mv) {
// we could make this error more helpful at the expense of extra complexity
return nil, fmt.Errorf("cell %v uses undefined axes", mv)
}
v.Name = idBuf.String()
disp, err := displayNameExp.ExpandString(m.DisplayName)
if err != nil {
return nil, fmt.Errorf("processing display name: %v", err)
}
v.DisplayName = disp
// add final matrix-level tags and tasks
if err := v.mergeAxisValue(axisValue{Tags: m.Tags}); err != nil {
return nil, fmt.Errorf("processing matrix tags: %v", err)
}
for _, t := range m.Tasks {
expTask, err := expandParserBVTask(t, v.Expansions)
if err != nil {
return nil, fmt.Errorf("processing task %v: %v", t.Name, err)
}
v.Tasks = append(v.Tasks, expTask)
}
// evaluate rules for matching matrix values
for i, rule := range m.Rules {
r, err := expandRule(rule, v.Expansions)
if err != nil {
return nil, fmt.Errorf("processing rule[%v]: %v", i, err)
}
matchers, errs := r.If.evaluatedCopies(ase) // we could cache this
if len(errs) > 0 {
return nil, fmt.Errorf("evaluating rules for matrix %v: %v", m.Id, errs)
}
if matchers.contain(mv) {
if r.Then.Set != nil {
if err := v.mergeAxisValue(*r.Then.Set); err != nil {
return nil, fmt.Errorf("evaluating %v rule %v: %v", m.Id, i, err)
}
}
// we append add/remove task rules internally and execute them
// during task evaluation, when other tasks are being evaluated.
if len(r.Then.RemoveTasks) > 0 || len(r.Then.AddTasks) > 0 {
v.matrixRules = append(v.matrixRules, r.Then)
}
}
}
//.........這裏部分代碼省略.........