-
Notifications
You must be signed in to change notification settings - Fork 50
/
result.go
74 lines (62 loc) · 1.4 KB
/
result.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
package models
import "errors"
type DatabaseResult struct {
Query string
Response []string
}
// Result of test execution
type Result struct {
Path string // TODO: remove
Query string // TODO: remove
RequestBody string
ResponseStatusCode int
ResponseStatus string
ResponseContentType string
ResponseBody string
ResponseHeaders map[string][]string
Errors []error
Test TestInterface
DatabaseResult []DatabaseResult
}
func allureStatus(status string) bool {
switch status {
case "passed", "failed", "broken", "skipped":
return true
default:
return false
}
}
func notRunnedStatus(status string) bool {
switch status {
case "broken", "skipped":
return true
default:
return false
}
}
func (r *Result) AllureStatus() (string, error) {
testStatus := r.Test.GetStatus()
if testStatus != "" && allureStatus(testStatus) && notRunnedStatus(testStatus) {
return testStatus, nil
}
var (
status = "passed"
testErrors []error
)
if len(r.Errors) != 0 {
status = "failed"
testErrors = r.Errors
}
if len(testErrors) != 0 {
errText := ""
for _, err := range testErrors {
errText = errText + err.Error() + "\n"
}
return status, errors.New(errText)
}
return status, nil
}
// Passed returns true if test passed (false otherwise)
func (r *Result) Passed() bool {
return len(r.Errors) == 0
}