-
Notifications
You must be signed in to change notification settings - Fork 18
/
before.go
79 lines (69 loc) · 2.03 KB
/
before.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
package allure
import (
"fmt"
"github.com/fatih/camelcase"
"github.com/jtolds/gls"
"log"
"runtime/debug"
"strings"
"testing"
)
// BeforeTest executes a setup phase of the test and adds parameters to the Allure container object
func BeforeTest(t *testing.T, testOptions ...Option) {
testPhaseObject := getCurrentTestPhaseObject(t)
if testPhaseObject.Test != nil {
log.Printf("Test's \"%s\" allure setup is being executed after allure test!\n", t.Name())
}
before := newBefore()
testPhaseObject.Befores = append(testPhaseObject.Befores, before)
beforeSubContainer := before.Befores[0]
before.UUID = generateUUID()
beforeSubContainer.Start = getTimestampMs()
beforeSubContainer.Steps = make([]stepObject, 0)
for _, option := range testOptions {
option(beforeSubContainer)
}
defer func() {
panicObject := recover()
beforeSubContainer.Stop = getTimestampMs()
beforeSubContainer.Status = getTestStatus(t)
beforeSubContainer.Stage = "finished"
if panicObject != nil {
t.Fail()
beforeSubContainer.StatusDetails = &statusDetails{
Message: fmt.Sprintf("%+v", panicObject),
Trace: filterStackTrace(debug.Stack()),
}
beforeSubContainer.Status = broken
r := newResult()
r.Stop = getTimestampMs()
r.Name = strings.Join(camelcase.Split(t.Name())[1:], " ")
r.Description = t.Name()
r.setDefaultLabels(t)
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)
}
}
panic(panicObject)
}
}()
ctxMgr.SetValues(gls.Values{
testResultKey: beforeSubContainer,
nodeKey: beforeSubContainer,
testInstanceKey: t,
}, beforeSubContainer.Action)
}
func newBefore() *container {
return &container{
Befores: []*subContainer{newHelper()},
}
}