Skip to content

Commit

Permalink
fix: void groups
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 committed Aug 8, 2024
1 parent ab52702 commit 6cd61f3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/testworkflows/testworkflowprocessor/action/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ func Finalize(groups actiontypes.ActionGroups, isolatedContainers bool) actionty
}

// Move non-executable steps from the 2nd group into setup
for groups[0][0].Type() != lite.ActionTypeContainerTransition {
for len(groups[0]) > 0 && groups[0][0].Type() != lite.ActionTypeContainerTransition {
setup = append(setup, groups[0][0])
groups[0] = groups[0][1:]
}
if len(groups[0]) == 0 {
groups = groups[1:]
}
return append(actiontypes.ActionGroups{setup}, groups...)
}
58 changes: 58 additions & 0 deletions pkg/testworkflows/testworkflowprocessor/presets/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,3 +1056,61 @@ func TestProcessConditionWithMultipleOperations(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, want, res.LiteActions())
}

func TestProcessNamedGroupWithSkippedSteps(t *testing.T) {
wf := &testworkflowsv1.TestWorkflow{
Spec: testworkflowsv1.TestWorkflowSpec{
TestWorkflowSpecBase: testworkflowsv1.TestWorkflowSpecBase{
System: &testworkflowsv1.TestWorkflowSystem{
IsolatedContainers: common.Ptr(true),
},
},
Steps: []testworkflowsv1.Step{
{StepMeta: testworkflowsv1.StepMeta{Name: "test-group", Condition: "always"}, Steps: []testworkflowsv1.Step{
{StepMeta: testworkflowsv1.StepMeta{Condition: "never"}, StepOperations: testworkflowsv1.StepOperations{Shell: "shell-test-1"}},
{StepMeta: testworkflowsv1.StepMeta{Condition: "never"}, StepOperations: testworkflowsv1.StepOperations{Shell: "shell-test-2"}},
}},
},
},
}

res, err := proc.Bundle(context.Background(), wf, execMachine)
sig := res.Signature

want := lite.NewLiteActionGroups().
Append(func(list lite.LiteActionList) lite.LiteActionList {
return list.
// configure
Setup(false, false, false).
Declare(constants.RootOperationName, "true").
Declare(sig[0].Ref(), "true", constants.RootOperationName).
Declare(sig[0].Children()[0].Ref(), "false").
Declare(sig[0].Children()[1].Ref(), "false").
Result(sig[0].Ref(), "true").
Result(constants.RootOperationName, sig[0].Ref()).
Result("", constants.RootOperationName).
Start("").
CurrentStatus("true").
Start(constants.RootOperationName).
CurrentStatus(constants.RootOperationName).

// start the group
Start(sig[0].Ref()).
CurrentStatus(and(sig[0].Ref(), constants.RootOperationName)).

// void operations
Start(sig[0].Children()[0].Ref()).
End(sig[0].Children()[0].Ref()).
CurrentStatus(and(sig[0].Ref(), constants.RootOperationName)).
Start(sig[0].Children()[1].Ref()).
End(sig[0].Children()[1].Ref()).

// finish all
End(sig[0].Ref()).
End(constants.RootOperationName).
End("")
})

assert.NoError(t, err)
assert.Equal(t, want, res.LiteActions())
}

0 comments on commit 6cd61f3

Please sign in to comment.