Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hosekpeter committed Feb 13, 2025
1 parent 97e6093 commit 4f29632
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions internal/pkg/service/cli/dialog/use_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (d *useTmplInputsDialog) ask(ctx context.Context, isForTest bool, inputsFil
err := d.groups.VisitInputs(func(group *input.StepsGroupExt, step *input.StepExt, inputDef *input.Input) error {
// Print info about group and select steps
if !group.Announced {
if err := d.announceGroup(group); err != nil {
if err := d.announceGroup(group, isForTest); err != nil {
return err
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func (d *useTmplInputsDialog) ask(ctx context.Context, isForTest bool, inputsFil
return d.out, warnings, err
}

func (d *useTmplInputsDialog) announceGroup(group *input.StepsGroupExt) error {
func (d *useTmplInputsDialog) announceGroup(group *input.StepsGroupExt, isForTest bool) error {
// Only once
if group.Announced {
return nil
Expand Down Expand Up @@ -164,7 +164,7 @@ func (d *useTmplInputsDialog) announceGroup(group *input.StepsGroupExt) error {
for i, v := range answers {
values[i] = v.Value
}
return group.ValidateStepsCount(len(group.Steps), len(values))
return group.ValidateStepsCount(len(group.Steps), len(values), isForTest)
},
}

Expand All @@ -173,7 +173,7 @@ func (d *useTmplInputsDialog) announceGroup(group *input.StepsGroupExt) error {
}

// Validate steps count
if err := group.ValidateStepsCount(len(group.Steps), len(selectedSteps)); err != nil {
if err := group.ValidateStepsCount(len(group.Steps), len(selectedSteps), isForTest); err != nil {
details := errors.NewMultiError()
details.Append(err)
details.Append(errors.Errorf("number of selected steps (%d) is incorrect", len(selectedSteps)))
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/service/templates/api/service/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func validateInputs(ctx context.Context, backends []string, groups template.Step
}

// Check if required number of steps is configured
if err := group.ValidateStepsCount(stepsCount, configuredSteps); err != nil {
if err := group.ValidateStepsCount(stepsCount, configuredSteps, false); err != nil {
msg := strhelper.AsSentence(err.Error())
outGroup.Error = &msg
outGroup.Valid = false
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/template/input/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ func (g StepsGroup) AreStepsSelectable() bool {
(len(g.Steps) > 1 || (g.Required != RequiredAtLeastOne && g.Required != RequiredExactlyOne))
}

func (g StepsGroup) ValidateStepsCount(all, selected int) error {
func (g StepsGroup) ValidateStepsCount(all, selected int, isTest bool) error {
if g.Required == RequiredAll && selected < all {
return errors.Errorf(requiredAllDescription, all)
}
if g.Required == RequiredAtLeastOne && selected < 1 {
return errors.New(requiredAtLeastOneDescription)
}
if g.Required == RequiredExactlyOne && selected != 1 {
if g.Required == RequiredExactlyOne && selected != 1 && !isTest {
return errors.New(requiredExactlyOneDescription)
}
if g.Required == RequiredZeroOrOne && selected > 1 {
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/template/test/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func ReadInputValues(ctx context.Context, tmpl *template.Template, test *templat
inputValues := make(template.InputsValues, 0)
err = tmpl.Inputs().ToExtended().VisitInputs(func(group *input.StepsGroupExt, step *input.StepExt, inputDef *input.Input) error {
var inputValue template.InputValue
if v, found := inputsFile[inputDef.ID]; found {
inputValue, err = template.ParseInputValue(ctx, v, inputDef, true)
if value, found := inputsFile[inputDef.ID]; found {
inputValue, err = template.ParseInputValue(ctx, value, inputDef, true)
if err != nil {
return errors.NewNestedError(err, errors.New("please fix the value in the inputs JSON file"))
}
Expand Down

0 comments on commit 4f29632

Please sign in to comment.