File tree Expand file tree Collapse file tree 4 files changed +24
-6
lines changed
Expand file tree Collapse file tree 4 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ func TestExample_Abort(t *testing.T) {
1919 )
2020 result := p .Run ()
2121 assert .True (t , result .IsSuccessful ())
22+ assert .True (t , result .IsAborted ())
2223}
2324
2425func doNotExecute (_ pipeline.Context ) error {
Original file line number Diff line number Diff line change @@ -17,10 +17,13 @@ type (
1717 // Result is the object that is returned after each step and after running a pipeline.
1818 Result struct {
1919 // Err contains the step's returned error, nil otherwise.
20+ // In an aborted pipeline with ErrAbort it will still be nil.
2021 Err error
2122 // Name is an optional identifier for a result.
2223 // ActionFunc may set this property before returning to help a ResultHandler with further processing.
2324 Name string
25+
26+ aborted bool
2427 }
2528 // Step is an intermediary action and part of a Pipeline.
2629 Step struct {
@@ -144,7 +147,7 @@ func (p *Pipeline) doRun() Result {
144147 if err != nil {
145148 if errors .Is (err , ErrAbort ) {
146149 // Abort pipeline without error
147- return Result {}
150+ return Result {aborted : true }
148151 }
149152 if p .disableErrorWrapping {
150153 return Result {Err : err }
Original file line number Diff line number Diff line change @@ -20,11 +20,12 @@ func TestPipeline_Run(t *testing.T) {
2020 callCount := 0
2121 hook := & hook {}
2222 tests := map [string ]struct {
23- givenSteps []Step
24- givenBeforeHook Listener
25- givenFinalizer ResultHandler
26- expectErrorString string
27- expectedCalls int
23+ givenSteps []Step
24+ givenBeforeHook Listener
25+ givenFinalizer ResultHandler
26+ expectErrorString string
27+ expectedCalls int
28+ additionalAssertions func (t * testing.T , result Result )
2829 }{
2930 "GivenSingleStep_WhenRunning_ThenCallStep" : {
3031 givenSteps : []Step {
@@ -74,6 +75,9 @@ func TestPipeline_Run(t *testing.T) {
7475 }),
7576 },
7677 expectedCalls : 1 ,
78+ additionalAssertions : func (t * testing.T , result Result ) {
79+ assert .True (t , result .IsAborted ())
80+ },
7781 },
7882 "GivenSingleStepWithHandler_WhenRunningWithError_ThenAbortWithError" : {
7983 givenSteps : []Step {
@@ -153,6 +157,9 @@ func TestPipeline_Run(t *testing.T) {
153157 assert .True (t , actualResult .IsSuccessful ())
154158 }
155159 assert .Equal (t , tt .expectedCalls , callCount )
160+ if tt .additionalAssertions != nil {
161+ tt .additionalAssertions (t , actualResult )
162+ }
156163 })
157164 }
158165}
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ import "errors"
66var ErrAbort = errors .New ("abort" )
77
88// IsSuccessful returns true if the contained error is nil.
9+ // Aborted pipelines (with ErrAbort) are still reported as success.
10+ // To query if a pipeline is aborted early, use IsAborted.
911func (r Result ) IsSuccessful () bool {
1012 return r .Err == nil
1113}
@@ -14,3 +16,8 @@ func (r Result) IsSuccessful() bool {
1416func (r Result ) IsFailed () bool {
1517 return r .Err != nil
1618}
19+
20+ // IsAborted returns true if the pipeline didn't stop with an error, but just aborted early with ErrAbort.
21+ func (r Result ) IsAborted () bool {
22+ return r .aborted
23+ }
You can’t perform that action at this time.
0 commit comments