forked from dailymotion/allure-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
128 lines (119 loc) · 2.8 KB
/
test.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
package allure
import (
"fmt"
"github.com/dailymotion/allure-go/severity"
"github.com/fatih/camelcase"
"github.com/jtolds/gls"
"log"
"runtime/debug"
"strings"
"testing"
)
type testLabels struct {
Epic string
Lead string
Owner string
Severity severity.Severity
Story []string
Feature []string
ParentSuite string
Suite string
SubSuite string
Host string
Thread string
Framework string
Language string
}
func SkipTest(t *testing.T, testOptions ...Option) {
var r *result
r = newResult()
r.UUID = generateUUID()
r.Start = getTimestampMs()
r.Name = strings.Join(camelcase.Split(t.Name())[1:], " ")
r.Description = t.Name()
r.setDefaultLabels(t)
r.Steps = make([]stepObject, 0)
for _, option := range testOptions {
option(r)
}
getCurrentTestPhaseObject(t).Test = r
r.Stop = getTimestampMs()
r.Stage = "finished"
r.Status = skipped
err := r.writeResultsFile()
if err != nil {
log.Println("Failed to write content of result to json file", err)
}
setups := getCurrentTestPhaseObject(t).Befores
for _, setup := range setups {
setup.Children = append(setup.Children, r.UUID)
err := setup.writeResultsFile()
if err != nil {
log.Println("Failed to write content of result to json file", err)
}
}
defer func() {
if r.StatusDetails != nil {
t.Skip(r.StatusDetails.Message)
} else {
t.Skip()
}
}()
}
//Test execute the test and creates an Allure result used by Allure reports
func Test(t *testing.T, testOptions ...Option) {
var r *result
r = newResult()
r.UUID = generateUUID()
r.Start = getTimestampMs()
r.Name = strings.Join(camelcase.Split(t.Name())[1:], " ")
r.Description = t.Name()
r.setDefaultLabels(t)
r.Steps = make([]stepObject, 0)
for _, option := range testOptions {
option(r)
}
if r.Test == nil {
r.Test = func() {}
}
defer func() {
panicObject := recover()
getCurrentTestPhaseObject(t).Test = r
r.Stop = getTimestampMs()
if panicObject != nil {
isFailed := t.Failed()
t.Fail()
r.StatusDetails = &statusDetails{
Message: fmt.Sprintf("%+v", panicObject),
Trace: filterStackTrace(debug.Stack()),
}
if !isFailed {
r.Status = broken
}
}
if r.Status == "" {
r.Status = getTestStatus(t)
}
r.Stage = "finished"
err := r.writeResultsFile()
if err != nil {
log.Println("Failed to write content of result to json file", err)
}
setups := getCurrentTestPhaseObject(t).Befores
for _, setup := range setups {
setup.Children = append(setup.Children, r.UUID)
err := setup.writeResultsFile()
if err != nil {
log.Println("Failed to write content of result to json file", err)
}
}
//if panicObject != nil {
// panic(panicObject)
//}
}()
ctxMgr.SetValues(gls.Values{
testResultKey: r,
nodeKey: r,
testInstanceKey: t,
}, r.Test)
}