-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ErrAbort type that can terminate a pipeline without error
- Loading branch information
Showing
4 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build examples | ||
// +build examples | ||
|
||
package examples | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
pipeline "github.com/ccremer/go-command-pipeline" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestExample_Abort(t *testing.T) { | ||
p := pipeline.NewPipeline() | ||
p.WithSteps( | ||
pipeline.NewStepFromFunc("abort demo", abort), | ||
pipeline.NewStepFromFunc("never executed", doNotExecute), | ||
) | ||
result := p.Run() | ||
assert.True(t, result.IsSuccessful()) | ||
} | ||
|
||
func doNotExecute(_ pipeline.Context) error { | ||
return errors.New("should not execute") | ||
} | ||
|
||
func abort(_ pipeline.Context) error { | ||
// some logic that can handle errors, but you don't want to bubble up the error. | ||
|
||
// terminate pipeline gracefully | ||
return pipeline.ErrAbort | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters