File tree Expand file tree Collapse file tree 3 files changed +8
-15
lines changed
Expand file tree Collapse file tree 3 files changed +8
-15
lines changed Original file line number Diff line number Diff line change @@ -10,15 +10,11 @@ import (
1010 pipeline "github.com/ccremer/go-command-pipeline"
1111)
1212
13- type PipelineLogger struct {}
14-
15- func (l * PipelineLogger ) Accept (step pipeline.Step ) {
16- fmt .Println (fmt .Sprintf ("Executing step: %s" , step .Name ))
17- }
18-
1913func TestExample_Hooks (t * testing.T ) {
2014 p := pipeline .NewPipeline ()
21- p .AddBeforeHook (& PipelineLogger {})
15+ p .AddBeforeHook (func (step pipeline.Step ) {
16+ fmt .Println (fmt .Sprintf ("Executing step: %s" , step .Name ))
17+ })
2218 p .WithSteps (
2319 pipeline .NewStep ("hook demo" , AfterHookAction ()),
2420 )
Original file line number Diff line number Diff line change @@ -38,11 +38,8 @@ type (
3838 }
3939 // Context contains arbitrary data relevant for the pipeline execution.
4040 Context interface {}
41- // Listener is a simple interface that listens to Pipeline events.
42- Listener interface {
43- // Accept takes the given Step.
44- Accept (step Step )
45- }
41+ // Listener is a simple func that listens to Pipeline events.
42+ Listener func (step Step )
4643 // ActionFunc is the func that contains your business logic.
4744 // The context is a user-defined arbitrary data of type interface{} that gets provided in every Step, but may be nil if not set.
4845 ActionFunc func (ctx Context ) Result
@@ -132,8 +129,8 @@ func (p *Pipeline) Run() Result {
132129
133130func (p * Pipeline ) doRun () Result {
134131 for _ , step := range p .steps {
135- for _ , listener := range p .beforeHooks {
136- listener . Accept (step )
132+ for _ , hooks := range p .beforeHooks {
133+ hooks (step )
137134 }
138135
139136 result := step .F (p .context )
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ func TestPipeline_Run(t *testing.T) {
4242 return Result {}
4343 }),
4444 },
45- givenBeforeHook : hook ,
45+ givenBeforeHook : hook . Accept ,
4646 expectedCalls : 2 ,
4747 },
4848 "GivenPipelineWithFinalizer_WhenRunning_ThenCallHandler" : {
You can’t perform that action at this time.
0 commit comments