Skip to content

Commit

Permalink
fix: parse missing vars (#337)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Nov 26, 2020
1 parent 56cccf9 commit 9eb3367
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 19 deletions.
2 changes: 1 addition & 1 deletion executors/dbfixtures/dbfixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (e Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, er
return r, nil
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Result struct {
TimeSeconds float64 `json:"timeseconds,omitempty" yaml:"timeseconds,omitempty"`
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c *customHandler) OnReceiveTrailers(stat *status.Status, met metadata.MD)
c.target.Code = strconv.Itoa(int(uint32(stat.Code())))
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type HTTPRequest struct {
PostForm url.Values `json:"post_form,omitempty"`
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/imap/imap.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Result struct {
TimeSeconds float64 `json:"timeSeconds,omitempty" yaml:"timeSeconds,omitempty"`
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type (
consumeFunc = func(message *sarama.ConsumerMessage) (Message, interface{}, error)
)

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/ovhapi/ovhapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Result struct {
Headers Headers `json:"headers" yaml:"headers"`
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (e Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, er
return r, nil
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (e Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/plugins/hello/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (e Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, er
return r, nil
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (e Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/plugins/odbc/odbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (e Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, er
return r, nil
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/rabbitmq/rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type Result struct {
Err string `json:"error" yaml:"error"`
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/readfile/readfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Result struct {
Mod map[string]string `json:"mod,omitempty" yaml:"mod,omitempty"`
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
r := Result{
Md5sum: make(map[string]string),
Expand Down
2 changes: 1 addition & 1 deletion executors/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Result struct {
Commands []Command `json:"commands,omitempty" yaml:"commands,omitempty"`
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/smtp/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Result struct {
TimeSeconds float64 `json:"timeSeconds,omitempty" yaml:"timeSeconds,omitempty"`
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (e Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, er
return r, nil
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Result struct {
TimeSeconds float64 `json:"timeseconds,omitempty" yaml:"timeseconds,omitempty"`
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
2 changes: 1 addition & 1 deletion executors/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Result struct {
Value string `json:"value,omitempty" yaml:"value,omitempty"`
}

// ZeroValueResult return an empty implemtation of this executor result
// ZeroValueResult return an empty implementation of this executor result
func (Executor) ZeroValueResult() interface{} {
return Result{}
}
Expand Down
11 changes: 10 additions & 1 deletion process_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ func (v *Venom) parseTestCase(ts *TestSuite, tc *TestCase) ([]string, []string,
return nil, nil, err
}
for k := range dumpE {
var found bool
for i := 0; i < len(vars); i++ {
if vars[i] == k {
found = true
break
}
}
if !found {
extractedVars = append(extractedVars, k)
}
extractedVars = append(extractedVars, tc.Name+"."+k)
if strings.HasSuffix(k, "__type__") && dumpE[k] == "Map" {
// go-dump doesnt dump the map name, here is a workaround
Expand Down Expand Up @@ -100,7 +110,6 @@ func (v *Venom) parseTestCase(ts *TestSuite, tc *TestCase) ([]string, []string,
}
}
}

}
return vars, extractedVars, nil
}
Expand Down
7 changes: 6 additions & 1 deletion tests/user_executor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ testcases:
- type: hello
myarg: World
assertions:
- result.display.hello ShouldContainSubstring World
- result.display.hello ShouldContainSubstring World
- name: testB
steps:
- script: echo "{{.testA.result.display.hello}}"
assertions:
- result.systemout ShouldContainSubstring {{.testA.result.display.hello}}
20 changes: 20 additions & 0 deletions types_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ func (ux UserExecutor) Run(ctx context.Context, step TestStep) (interface{}, err
return nil, errors.New("Run not implemented for user interface, use RunUserExecutor instead")
}

func (ux UserExecutor) ZeroValueResult() interface{} {
type Output struct {
Result interface{} `json:"result"`
}
output := &Output{
Result: ux.Output,
}
outputS, err := json.Marshal(output)
if err != nil {
return ""
}

result := make(map[string]interface{})
err = json.Unmarshal(outputS, &result)
if err != nil {
return ""
}
return result
}

func (v *Venom) RunUserExecutor(ctx context.Context, ux UserExecutor, step TestStep) (interface{}, error) {
vrs := H{}
for k, va := range ux.Input {
Expand Down

0 comments on commit 9eb3367

Please sign in to comment.