-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
152 additions
and
82 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
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,74 @@ | ||
## Venom Executor | ||
|
||
### Write your executor | ||
|
||
An executor have to implement this interface | ||
|
||
```go | ||
|
||
// Executor execute a testStep. | ||
type Executor interface { | ||
// Run run a Test Step | ||
Run(ctx context.Content, TestStep) (interface{}, error) | ||
} | ||
``` | ||
|
||
Example | ||
|
||
```go | ||
|
||
|
||
// Name of executor | ||
const Name = "myexecutor" | ||
|
||
// New returns a new Executor | ||
func New() venom.Executor { | ||
return &Executor{} | ||
} | ||
|
||
// Executor struct | ||
type Executor struct { | ||
Command string `json:"command,omitempty" yaml:"command,omitempty"` | ||
} | ||
|
||
// Result represents a step result | ||
type Result struct { | ||
Code int `json:"code,omitempty" yaml:"code,omitempty"` | ||
Command string `json:"command,omitempty" yaml:"command,omitempty"` | ||
Systemout string `json:"systemout,omitempty" yaml:"systemout,omitempty"` // put in testcase.Systemout by venom if present | ||
Systemerr string `json:"systemerr,omitempty" yaml:"systemerr,omitempty"` // put in testcase.Systemerr by venom if present | ||
} | ||
|
||
// GetDefaultAssertions return default assertions for this executor | ||
// Optional | ||
func (Executor) GetDefaultAssertions() *venom.StepAssertions { | ||
return venom.StepAssertions{Assertions: []string{"result.code ShouldEqual 0"}} | ||
} | ||
|
||
// Run execute TestStep | ||
func (Executor) Run(context.Context, TestStep, string) (interface{}, error) { | ||
// transform step to Executor Instance | ||
var e Executor | ||
if err := mapstructure.Decode(step, &e); err != nil { | ||
return nil, err | ||
} | ||
|
||
// to something with e.Command here... | ||
//... | ||
|
||
systemout := "foo" | ||
ouputCode := 0 | ||
|
||
// prepare result | ||
r := Result{ | ||
Code: ouputCode, // return Output Code | ||
Command: e.Command, // return Command executed | ||
Systemout: systemout, // return Output string | ||
} | ||
|
||
return r | ||
} | ||
|
||
``` | ||
|
||
Feel free to open a Pull Request with your executors. |