-
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.
Added
UseArguments
field to specify which arguments to use [#6]
Merge pull request #6 from TanmoySG/runner-func-sig-change --- Added `UseArguments` field to specify which arguments to use In this PR, added the feature to pick between previous step returned values, or current step's arguments or use both as arguments to run the current step. ```go var steps = gosteps.Step{ Name: "add", Function: funcs.Add, StepArgs: []interface{}{2, 3}, NextStep: gosteps.Steps{ Name: "sub", Function: funcs.Sub, StepArgs: []interface{}{4, 6}, UseArguments: gosteps.CurrentStepArgs, }, } ``` Available configurations for `UseArguments` ```go // only previous step return will be passed to current step as arguments PreviousStepReturns stepArgChainingType = "PreviousStepReturns" // only current step arguments (StepArgs) will be passed to current step as arguments CurrentStepArgs stepArgChainingType = "CurrentStepArgs" // both previous step returns and current step arguments (StepArgs) will be passed // to current step as arguments - previous step returns, followed by current step args, PreviousReturnsWithCurrentStepArgs stepArgChainingType = "PreviousReturnsWithCurrentStepArgs" // both previous step returns and current step arguments (StepArgs) will be passed // to current step as arguments - current step args, followed by previous step returns CurrentStepArgsWithPreviousReturns stepArgChainingType = "CurrentStepArgsWithPreviousReturns" ``` Also refactored and added Unit Tests.
- Loading branch information
Showing
11 changed files
with
325 additions
and
64 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,7 @@ | ||
coverage: | ||
go test ./... -coverpkg=./... -coverprofile ./coverage.out | ||
go tool cover -func ./coverage.out | ||
|
||
run-example: | ||
go run example/multistep-example/main.go | ||
go run example/dynamic-steps-example/main.go |
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
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
module github.com/TanmoySG/go-steps | ||
|
||
go 1.18 | ||
|
||
require github.com/stretchr/testify v1.8.4 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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,10 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= | ||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,31 @@ | ||
package gosteps | ||
|
||
import "time" | ||
|
||
// StepName type defined the name of the step | ||
type StepName string | ||
|
||
// StepFn type defines the Step's Function | ||
type StepFn func(...interface{}) ([]interface{}, error) | ||
|
||
// PossibleNextSteps type is a list/array of Step objects | ||
type PossibleNextSteps []Step | ||
|
||
// Step type defines a step with all configurations for the step | ||
type Step struct { | ||
Name StepName | ||
Function StepFn | ||
UseArguments stepArgChainingType | ||
StepArgs []interface{} | ||
NextStep *Step | ||
PossibleNextSteps PossibleNextSteps | ||
NextStepResolver interface{} | ||
ErrorsToRetry []error | ||
StrictErrorCheck bool | ||
SkipRetry bool | ||
MaxAttempts int | ||
RetrySleep time.Duration | ||
} | ||
|
||
// enum type for step arguments chaining | ||
type stepArgChainingType string |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package gosteps | ||
|
||
import ( | ||
"math" | ||
) | ||
|
||
const ( | ||
// to avoid infinite runs due to the MaxAttempts not being set, we're keeping the default attempts to 100 | ||
// if required, import and use the MaxMaxAttempts in the step.MaxAttempts field | ||
DefaultMaxAttempts = 100 | ||
|
||
// the Max value is 9223372036854775807, which is not infinite but a huge number of attempts | ||
MaxMaxAttempts = math.MaxInt | ||
) | ||
|
||
var ( | ||
// only previous step return will be passed to current step as arguments | ||
PreviousStepReturns stepArgChainingType = "PreviousStepReturns" | ||
|
||
// only current step arguments (StepArgs) will be passed to current step as arguments | ||
CurrentStepArgs stepArgChainingType = "CurrentStepArgs" | ||
|
||
// both previous step returns and current step arguments (StepArgs) will be passed | ||
// to current step as arguments - previous step returns, followed by current step args, | ||
PreviousReturnsWithCurrentStepArgs stepArgChainingType = "PreviousReturnsWithCurrentStepArgs" | ||
|
||
// both previous step returns and current step arguments (StepArgs) will be passed | ||
// to current step as arguments - current step args, followed by previous step returns | ||
CurrentStepArgsWithPreviousReturns stepArgChainingType = "CurrentStepArgsWithPreviousReturns" | ||
) |
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,5 @@ | ||
package gosteps | ||
|
||
var ( | ||
unresolvedStepError = "error: step [%s] is unresolved, no step found with this name." | ||
) |
Oops, something went wrong.