-
Notifications
You must be signed in to change notification settings - Fork 18
/
cute.go
180 lines (141 loc) · 3.89 KB
/
cute.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package cute
import (
"context"
"strings"
"testing"
"github.com/ozontech/allure-go/pkg/allure"
"github.com/ozontech/allure-go/pkg/framework/core/allure_manager/manager"
"github.com/ozontech/allure-go/pkg/framework/core/common"
"github.com/ozontech/allure-go/pkg/framework/provider"
)
type cute struct {
baseProps *HTTPTestMaker
parallel bool
allureInfo *allureInformation
allureLinks *allureLinks
allureLabels *allureLabels
countTests int // Общее количество тестов.
isTableTest bool
tests []*Test
}
type allureInformation struct {
title string
description string
stage string
}
type allureLabels struct {
id string
feature string
epic string
tag string
tags []string
suiteLabel string
subSuite string
parentSuite string
story string
severity allure.SeverityType
owner string
lead string
label *allure.Label
labels []*allure.Label
allureID string
layer string
}
type allureLinks struct {
issue string
testCase string
link *allure.Link
tmsLink string
tmsLinks []string
}
func (qt *cute) ExecuteTest(ctx context.Context, t tProvider) []ResultsHTTPBuilder {
var internalT allureProvider
if t == nil {
panic("could not start test without testing.T")
}
stepCtx, isStepCtx := t.(provider.StepCtx)
if isStepCtx {
return qt.executeTestsInsideStep(ctx, stepCtx)
}
tOriginal, ok := t.(*testing.T)
if ok {
newT := createAllureT(tOriginal)
if !qt.isTableTest {
defer newT.FinishTest() //nolint
}
internalT = newT
}
allureT, ok := t.(provider.T)
if ok {
internalT = allureT
}
if qt.parallel {
internalT.Parallel()
}
return qt.executeTests(ctx, internalT)
}
func createAllureT(t *testing.T) *common.Common {
var (
newT = common.NewT(t)
callers = strings.Split(t.Name(), "/")
providerCfg = manager.NewProviderConfig().
WithFullName(t.Name()).
WithPackageName("package").
WithSuiteName(t.Name()).
WithRunner(callers[0])
newProvider = manager.NewProvider(providerCfg)
)
newProvider.NewTest(t.Name(), "package")
newT.SetProvider(newProvider)
newT.Provider.TestContext()
return newT
}
// executeTests is method for run tests
// It's could be table tests or usual tests
func (qt *cute) executeTests(ctx context.Context, allureProvider allureProvider) []ResultsHTTPBuilder {
var (
res = make([]ResultsHTTPBuilder, 0)
)
// Cycle for change number of Test
for i := 0; i <= qt.countTests; i++ {
currentTest := qt.tests[i]
// Execute by new T for table tests
if qt.isTableTest {
tableTestName := currentTest.Name
allureProvider.Run(tableTestName, func(inT provider.T) {
// Set current test name
inT.Title(tableTestName)
res = append(res, qt.executeInsideAllure(ctx, inT, currentTest))
})
} else {
currentTest.Name = allureProvider.Name()
// set labels
qt.setAllureInformation(allureProvider)
res = append(res, qt.executeInsideAllure(ctx, allureProvider, currentTest))
}
}
return res
}
// executeInsideAllure is method for run test inside allure
// It's could be table tests or usual tests
func (qt *cute) executeInsideAllure(ctx context.Context, allureProvider allureProvider, currentTest *Test) ResultsHTTPBuilder {
resT := currentTest.executeInsideAllure(ctx, allureProvider)
// Remove from base struct all asserts
currentTest.clearFields()
return resT
}
// executeTestsInsideStep is method for run group of tests inside provider.StepCtx
func (qt *cute) executeTestsInsideStep(ctx context.Context, stepCtx provider.StepCtx) []ResultsHTTPBuilder {
var (
res = make([]ResultsHTTPBuilder, 0)
)
// Cycle for change number of Test
for i := 0; i <= qt.countTests; i++ {
currentTest := qt.tests[i]
result := currentTest.executeInsideStep(ctx, stepCtx)
// Remove from base struct all asserts
currentTest.clearFields()
res = append(res, result)
}
return res
}