-
Notifications
You must be signed in to change notification settings - Fork 18
/
step.go
93 lines (74 loc) · 1.98 KB
/
step.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
package cute
import (
"fmt"
"github.com/ozontech/allure-go/pkg/allure"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/cute/errors"
)
func (it *Test) executeWithStep(t internalT, stepName string, execute func(t T) []error) []error {
var (
errs []error
)
// Add attempt indication in Allure if more than 1 attempt
if it.Retry.MaxAttempts != 1 {
stepName = fmt.Sprintf("[Attempt #%d] %v", it.Retry.currentCount, stepName)
}
t.WithNewStep(stepName, func(stepCtx provider.StepCtx) {
errs = execute(stepCtx)
processStepErrors(stepCtx, errs)
})
return errs
}
func processStepErrors(stepCtx provider.StepCtx, errs []error) {
var (
step = stepCtx.CurrentStep()
statuses = make([]allure.Status, 0)
)
if len(errs) == 0 {
return
}
for _, err := range errs {
currentStatus := allure.Failed
currentStep := step
if tErr, ok := err.(errors.OptionalError); ok {
if tErr.IsOptional() {
currentStatus = allure.Skipped
}
}
if tErr, ok := err.(errors.BrokenError); ok {
if tErr.IsBroken() {
currentStatus = allure.Broken
}
}
if tErr, ok := err.(errors.WithNameError); ok {
currentStep = allure.NewSimpleStep(tErr.GetName())
currentStep.Status = currentStatus
currentStep.WithParent(step)
}
if tErr, ok := err.(errors.WithFields); ok {
for k, v := range tErr.GetFields() {
if v == nil {
continue
}
currentStep.WithNewParameters(k, v)
}
}
if tErr, ok := err.(errors.WithAttachments); ok {
for _, v := range tErr.GetAttachments() {
if v == nil {
continue
}
currentStep.WithAttachments(allure.NewAttachment(v.Name, allure.MimeType(v.MimeType), v.Content))
}
}
statuses = append(statuses, currentStatus)
currentStep.WithAttachments(allure.NewAttachment("Error", allure.Text, []byte(err.Error())))
}
// If one error was not optional, parent step should be failed
for _, status := range statuses {
step.Status = status
if status == allure.Failed {
break
}
}
}