-
Notifications
You must be signed in to change notification settings - Fork 338
/
stepResult.go
105 lines (85 loc) · 3.64 KB
/
stepResult.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*----------------------------------------------------------------
* Copyright (c) ThoughtWorks, Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE in the project root for license information.
*----------------------------------------------------------------*/
package result
import "github.com/getgauge/gauge-proto/go/gauge_messages"
// StepResult represents the result of step execution
type StepResult struct {
ProtoStep *gauge_messages.ProtoStep
StepFailed bool
}
// NewStepResult is a constructor for StepResult
func NewStepResult(ps *gauge_messages.ProtoStep) *StepResult {
return &StepResult{ProtoStep: ps}
}
func (s *StepResult) GetPreHook() []*gauge_messages.ProtoHookFailure {
if s.ProtoStep.StepExecutionResult.PreHookFailure == nil {
return []*gauge_messages.ProtoHookFailure{}
}
return []*gauge_messages.ProtoHookFailure{s.ProtoStep.StepExecutionResult.PreHookFailure}
}
func (s *StepResult) GetPostHook() []*gauge_messages.ProtoHookFailure {
if s.ProtoStep.StepExecutionResult.PostHookFailure == nil {
return []*gauge_messages.ProtoHookFailure{}
}
return []*gauge_messages.ProtoHookFailure{s.ProtoStep.StepExecutionResult.PostHookFailure}
}
func (s *StepResult) AddPreHook(f ...*gauge_messages.ProtoHookFailure) {
s.ProtoStep.StepExecutionResult.PreHookFailure = f[0]
}
func (s *StepResult) AddPostHook(f ...*gauge_messages.ProtoHookFailure) {
s.ProtoStep.StepExecutionResult.PostHookFailure = f[0]
}
// SetFailure sets the result to failed
func (s *StepResult) SetFailure() {
s.ProtoStep.StepExecutionResult.ExecutionResult.Failed = true
}
// GetFailed returns the state of the result
func (s *StepResult) GetFailed() bool {
return s.ProtoStep.StepExecutionResult.ExecutionResult.GetFailed()
}
// GetFailed returns true if the actual step failed, and not step hook.
func (s *StepResult) GetStepFailed() bool {
return s.StepFailed
}
// GetStackTrace returns the stacktrace for step failure
func (s *StepResult) GetStackTrace() string {
return s.ProtoStep.GetStepExecutionResult().GetExecutionResult().GetStackTrace()
}
// GetErrorMessage returns the error message for step failure
func (s *StepResult) GetErrorMessage() string {
return s.ProtoStep.GetStepExecutionResult().GetExecutionResult().GetErrorMessage()
}
// GetStepActualText returns the Actual text of step from step result
func (s *StepResult) GetStepActualText() string {
return s.ProtoStep.GetActualText()
}
// SetStepFailure sets the actual step as failed. StepResult.ProtoStep.GetFailed() returns true even if hook failed and not actual step.
func (s *StepResult) SetStepFailure() {
s.StepFailed = true
}
func (s *StepResult) Item() interface{} {
return s.ProtoStep
}
// ExecTime returns the time taken to execute the step
func (s *StepResult) ExecTime() int64 {
return s.ProtoStep.StepExecutionResult.ExecutionResult.GetExecutionTime()
}
// AddExecTime increments the execution time by the given value
func (s *StepResult) AddExecTime(t int64) {
if s.ProtoStep.StepExecutionResult.ExecutionResult == nil {
s.ProtoStep.StepExecutionResult.ExecutionResult = &gauge_messages.ProtoExecutionResult{Failed: false}
}
currentTime := s.ProtoStep.StepExecutionResult.ExecutionResult.GetExecutionTime()
s.ProtoStep.StepExecutionResult.ExecutionResult.ExecutionTime = currentTime + t
}
// ProtoStepExecResult returns the step execution result used at the proto layer
func (s *StepResult) ProtoStepExecResult() *gauge_messages.ProtoStepExecutionResult {
return s.ProtoStep.StepExecutionResult
}
// SetProtoExecResult sets the execution result
func (s *StepResult) SetProtoExecResult(r *gauge_messages.ProtoExecutionResult) {
s.ProtoStep.StepExecutionResult.ExecutionResult = r
}