forked from getgauge/gauge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
specResult.go
191 lines (158 loc) · 6.16 KB
/
specResult.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package main
import (
"code.google.com/p/goprotobuf/proto"
)
type suiteResult struct {
specResults []*specResult
preSuite *ProtoHookFailure
postSuite *ProtoHookFailure
isFailed bool
specsFailedCount int
executionTime int64
}
type specResult struct {
protoSpec *ProtoSpec
scenarioFailedCount int
scenarioCount int
isFailed bool
failedDataTableRows []int32
executionTime int64
}
type scenarioResult struct {
protoScenario *ProtoScenario
}
type result interface {
getPreHook() **ProtoHookFailure
getPostHook() **ProtoHookFailure
setFailure()
}
type execTimeTracker interface {
addExecTime(int64)
}
func (suiteResult *suiteResult) getPreHook() **ProtoHookFailure {
return &suiteResult.preSuite
}
func (suiteResult *suiteResult) getPostHook() **ProtoHookFailure {
return &suiteResult.postSuite
}
func (suiteResult *suiteResult) setFailure() {
suiteResult.isFailed = true
}
func (specResult *specResult) getPreHook() **ProtoHookFailure {
return &specResult.protoSpec.PreHookFailure
}
func (specResult *specResult) getPostHook() **ProtoHookFailure {
return &specResult.protoSpec.PostHookFailure
}
func (specResult *specResult) setFailure() {
specResult.isFailed = true
}
func (scenarioResult *scenarioResult) getPreHook() **ProtoHookFailure {
return &scenarioResult.protoScenario.PreHookFailure
}
func (scenarioResult *scenarioResult) getPostHook() **ProtoHookFailure {
return &scenarioResult.protoScenario.PostHookFailure
}
func (scenarioResult *scenarioResult) setFailure() {
scenarioResult.protoScenario.Failed = proto.Bool(true)
}
func (scenarioResult *scenarioResult) getFailure() bool {
return scenarioResult.protoScenario.GetFailed()
}
func (specResult *specResult) addSpecItems(resolvedItems []*ProtoItem) {
specResult.protoSpec.Items = append(specResult.protoSpec.Items, resolvedItems...)
}
func newSuiteResult() *suiteResult {
result := new(suiteResult)
result.specResults = make([]*specResult, 0)
return result
}
func addPreHook(result result, executionResult *ProtoExecutionResult) {
if executionResult.GetFailed() {
*(result.getPreHook()) = getProtoHookFailure(executionResult)
result.setFailure()
}
}
func addPostHook(result result, executionResult *ProtoExecutionResult) {
if executionResult.GetFailed() {
*(result.getPostHook()) = getProtoHookFailure(executionResult)
result.setFailure()
}
}
func (suiteResult *suiteResult) addSpecResult(specResult *specResult) {
if specResult.isFailed {
suiteResult.isFailed = true
suiteResult.specsFailedCount++
}
suiteResult.executionTime += specResult.executionTime
suiteResult.specResults = append(suiteResult.specResults, specResult)
}
func getProtoHookFailure(executionResult *ProtoExecutionResult) *ProtoHookFailure {
return &ProtoHookFailure{StackTrace: executionResult.StackTrace, ErrorMessage: executionResult.ErrorMessage, ScreenShot: executionResult.ScreenShot}
}
func (specResult *specResult) setFileName(fileName string) {
specResult.protoSpec.FileName = proto.String(fileName)
}
func (specResult *specResult) addScenarioResults(scenarioResults []*scenarioResult) {
for _, scenarioResult := range scenarioResults {
if scenarioResult.protoScenario.GetFailed() {
specResult.isFailed = true
specResult.scenarioFailedCount++
}
specResult.addExecTime(scenarioResult.protoScenario.GetExecutionTime())
specResult.protoSpec.Items = append(specResult.protoSpec.Items, &ProtoItem{ItemType: ProtoItem_Scenario.Enum(), Scenario: scenarioResult.protoScenario})
}
specResult.scenarioCount += len(scenarioResults)
}
func (specResult *specResult) addTableDrivenScenarioResult(scenarioResults [][](*scenarioResult)) {
numberOfScenarios := len(scenarioResults[0])
for scenarioIndex := 0; scenarioIndex < numberOfScenarios; scenarioIndex++ {
protoTableDrivenScenario := &ProtoTableDrivenScenario{Scenarios: make([]*ProtoScenario, 0)}
scenarioFailed := false
for rowIndex, eachRow := range scenarioResults {
protoScenario := eachRow[scenarioIndex].protoScenario
protoTableDrivenScenario.Scenarios = append(protoTableDrivenScenario.GetScenarios(), protoScenario)
specResult.addExecTime(protoScenario.GetExecutionTime())
if protoScenario.GetFailed() {
scenarioFailed = true
specResult.failedDataTableRows = append(specResult.failedDataTableRows, int32(rowIndex))
}
}
if scenarioFailed {
specResult.scenarioFailedCount++
specResult.isFailed = true
}
protoItem := &ProtoItem{ItemType: ProtoItem_TableDrivenScenario.Enum(), TableDrivenScenario: protoTableDrivenScenario}
specResult.protoSpec.Items = append(specResult.protoSpec.Items, protoItem)
}
specResult.protoSpec.IsTableDriven = proto.Bool(true)
specResult.scenarioCount += numberOfScenarios
}
func (specResult *specResult) addExecTime(execTime int64) {
specResult.executionTime += execTime
}
func (scenarioResult *scenarioResult) addItems(protoItems []*ProtoItem) {
scenarioResult.protoScenario.ScenarioItems = append(scenarioResult.protoScenario.ScenarioItems, protoItems...)
}
func (scenarioResult *scenarioResult) addContexts(contextProtoItems []*ProtoItem) {
scenarioResult.protoScenario.Contexts = append(scenarioResult.protoScenario.Contexts, contextProtoItems...)
}
func (scenarioResult *scenarioResult) updateExecutionTime() {
scenarioResult.updateExecutionTimeFromItems(scenarioResult.protoScenario.GetContexts())
scenarioResult.updateExecutionTimeFromItems(scenarioResult.protoScenario.GetScenarioItems())
}
func (scenarioResult *scenarioResult) updateExecutionTimeFromItems(protoItems []*ProtoItem) {
for _, item := range protoItems {
if item.GetItemType() == ProtoItem_Step {
stepExecTime := item.GetStep().GetStepExecutionResult().GetExecutionResult().GetExecutionTime()
scenarioResult.addExecTime(stepExecTime)
} else if item.GetItemType() == ProtoItem_Concept {
conceptExecTime := item.GetConcept().GetConceptExecutionResult().GetExecutionResult().GetExecutionTime()
scenarioResult.addExecTime(conceptExecTime)
}
}
}
func (scenarioResult *scenarioResult) addExecTime(execTime int64) {
currentScenarioExecTime := scenarioResult.protoScenario.GetExecutionTime()
scenarioResult.protoScenario.ExecutionTime = proto.Int64(currentScenarioExecTime + execTime)
}