forked from getgauge-contrib/gauge-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helper.go
43 lines (40 loc) · 1.14 KB
/
Helper.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
package messageprocessors
import (
m "github.com/getgauge-contrib/gauge-go/gauge_messages"
t "github.com/getgauge-contrib/gauge-go/testsuit"
)
func executeHooks(hooks []t.Hook, msg *m.Message) *m.Message {
var res *m.ProtoExecutionResult
var totalExecutionTime int64
for _, hook := range hooks {
res = hook.Execute()
totalExecutionTime += res.GetExecutionTime()
if res.GetFailed() {
return &m.Message{
MessageType: m.Message_ExecutionStatusResponse,
MessageId: msg.MessageId,
ExecutionStatusResponse: &m.ExecutionStatusResponse{ExecutionResult: res},
}
}
}
return createResponseMessage(msg.MessageId, totalExecutionTime, nil)
}
func createResponseMessage(msgId int64, executionTime int64, err error) *m.Message {
failed := false
errorMsg := ""
if err != nil {
failed = true
errorMsg = err.Error()
}
return &m.Message{
MessageType: m.Message_ExecutionStatusResponse,
MessageId: msgId,
ExecutionStatusResponse: &m.ExecutionStatusResponse{
ExecutionResult: &m.ProtoExecutionResult{
Failed: failed,
ExecutionTime: executionTime,
ErrorMessage: errorMsg,
},
},
}
}