Skip to content

Commit

Permalink
Merge pull request #22 from ccremer/predicate-if
Browse files Browse the repository at this point in the history
Rename predicate.WrapIn() to If()
  • Loading branch information
ccremer committed Dec 20, 2021
2 parents 54dca67 + 1000e95 commit 782ba46
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions predicate/predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func ToNestedStep(name string, p *pipeline.Pipeline, predicate Predicate) pipeli
return step
}

// WrapIn returns a new step that wraps the given step and executes its action only if the given Predicate evaluates true.
// If returns a new step that wraps the given step and executes its action only if the given Predicate evaluates true.
// The pipeline.Context from the pipeline is passed through the given action.
func WrapIn(originalStep pipeline.Step, predicate Predicate) pipeline.Step {
func If(predicate Predicate, originalStep pipeline.Step) pipeline.Step {
wrappedStep := pipeline.Step{Name: originalStep.Name}
wrappedStep.F = func(ctx pipeline.Context) pipeline.Result {
if predicate(ctx, wrappedStep) {
Expand Down
4 changes: 2 additions & 2 deletions predicate/predicate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestToNestedStep(t *testing.T) {
}
}

func TestWrapIn(t *testing.T) {
func TestIf(t *testing.T) {
counter := 0
tests := map[string]struct {
givenPredicate Predicate
Expand All @@ -122,7 +122,7 @@ func TestWrapIn(t *testing.T) {
counter++
return pipeline.Result{}
})
wrapped := WrapIn(step, tt.givenPredicate)
wrapped := If(tt.givenPredicate, step)
result := wrapped.F(nil)
require.NoError(t, result.Err)
assert.Equal(t, tt.expectedCalls, counter)
Expand Down

0 comments on commit 782ba46

Please sign in to comment.