Skip to content

Commit 059c650

Browse files
siller174samybenattSamuel Benattar
authored
Release/v0.1.22 (#84)
New functionality Retry test Rename functions RequestRepeat* to RequestRetry* Fix broken tests --------- Co-authored-by: Sam B. <[email protected]> Co-authored-by: Samuel Benattar <[email protected]>
1 parent b1e4e33 commit 059c650

21 files changed

+719
-169
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- name: Run examples
4646
run: make examples
4747
- name: Archive code coverage results
48-
uses: actions/upload-artifact@v2
48+
uses: actions/upload-artifact@v3
4949
with:
5050
name: allure-results
5151
path: ./examples/allure-results

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (i *ExampleSuite) BeforeAll(t provider.T) {
209209
// Preparing host
210210
host, err := url.Parse("https://jsonplaceholder.typicode.com/")
211211
if err != nil {
212-
t.Fatalf("could not parse url, error %v", err)
212+
t.Fatalf("could not parse url, error %w", err)
213213
}
214214

215215
i.host = host

assert.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (it *Test) assertHeaders(t internalT, headers http.Header) []error {
5353
return nil
5454
}
5555

56-
return executeWithStep(t, "Assert headers", func(t T) []error {
56+
return it.executeWithStep(t, "Assert headers", func(t T) []error {
5757
errs := make([]error, 0)
5858
// Execute assert only response
5959
for _, f := range asserts {
@@ -85,7 +85,7 @@ func (it *Test) assertResponse(t internalT, resp *http.Response) []error {
8585
return nil
8686
}
8787

88-
return executeWithStep(t, "Assert response", func(t T) []error {
88+
return it.executeWithStep(t, "Assert response", func(t T) []error {
8989
errs := make([]error, 0)
9090
// Execute assert only response
9191
for _, f := range asserts {
@@ -117,7 +117,7 @@ func (it *Test) assertBody(t internalT, body []byte) []error {
117117
return nil
118118
}
119119

120-
return executeWithStep(t, "Assert body", func(t T) []error {
120+
return it.executeWithStep(t, "Assert body", func(t T) []error {
121121
errs := make([]error, 0)
122122
// Execute assert only response
123123
for _, f := range asserts {

builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func createDefaultTest(m *HTTPTestMaker) *Test {
103103
Middleware: createMiddlewareFromTemplate(m.middleware),
104104
AllureStep: new(AllureStep),
105105
Request: &Request{
106-
Repeat: new(RequestRepeatPolitic),
106+
Retry: new(RequestRetryPolitic),
107107
},
108108
Expect: &Expect{JSONSchema: new(ExpectJSONSchema)},
109109
}

builder_request.go

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ import (
88
// RequestRepeat is a function for set options in request
99
// if response.Code != Expect.Code, than request will repeat Count counts with Delay delay.
1010
// Default delay is 1 second.
11+
// Deprecated: use RequestRetry instead
1112
func (qt *cute) RequestRepeat(count int) RequestHTTPBuilder {
12-
qt.tests[qt.countTests].Request.Repeat.Count = count
13+
qt.tests[qt.countTests].Request.Retry.Count = count
1314

1415
return qt
1516
}
1617

1718
// RequestRepeatDelay set delay for request repeat.
1819
// if response.Code != Expect.Code, than request will repeat Count counts with Delay delay.
1920
// Default delay is 1 second.
21+
// Deprecated: use RequestRetryDelay instead
2022
func (qt *cute) RequestRepeatDelay(delay time.Duration) RequestHTTPBuilder {
21-
qt.tests[qt.countTests].Request.Repeat.Delay = delay
23+
qt.tests[qt.countTests].Request.Retry.Delay = delay
2224

2325
return qt
2426
}
@@ -27,28 +29,84 @@ func (qt *cute) RequestRepeatDelay(delay time.Duration) RequestHTTPBuilder {
2729
// if response.Code != Expect.Code, than request will repeat Count counts with Delay delay.
2830
// if Optional is true and request is failed, than test step allure will be skipped, and t.Fail() will not execute.
2931
// If Broken is true and request is failed, than test step allure will be broken, and t.Fail() will not execute.
32+
// Deprecated: use RequestRetryPolitic instead
3033
func (qt *cute) RequestRepeatPolitic(politic *RequestRepeatPolitic) RequestHTTPBuilder {
3134
if politic == nil {
32-
panic("politic is nil in RequestRepeatPolitic")
35+
panic("politic is nil in RequestRetryPolitic")
3336
}
3437

35-
qt.tests[qt.countTests].Request.Repeat = politic
38+
qt.tests[qt.countTests].Request.Retry = &RequestRetryPolitic{
39+
Count: politic.Count,
40+
Delay: politic.Delay,
41+
Optional: politic.Optional,
42+
Broken: politic.Broken,
43+
}
3644

3745
return qt
3846
}
3947

4048
// RequestRepeatOptional set option politic for request repeat.
4149
// if Optional is true and request is failed, than test step allure will be skipped, and t.Fail() will not execute.
50+
// Deprecated: use RequestRetryOptional instead
4251
func (qt *cute) RequestRepeatOptional(option bool) RequestHTTPBuilder {
43-
qt.tests[qt.countTests].Request.Repeat.Optional = option
52+
qt.tests[qt.countTests].Request.Retry.Optional = option
4453

4554
return qt
4655
}
4756

4857
// RequestRepeatBroken set broken politic for request repeat.
4958
// If Broken is true and request is failed, than test step allure will be broken, and t.Fail() will not execute.
59+
// Deprecated: use RequestRetryBroken instead
5060
func (qt *cute) RequestRepeatBroken(broken bool) RequestHTTPBuilder {
51-
qt.tests[qt.countTests].Request.Repeat.Broken = broken
61+
qt.tests[qt.countTests].Request.Retry.Broken = broken
62+
63+
return qt
64+
}
65+
66+
// RequestRetry is a function for set options in request
67+
// if response.Code != Expect.Code, than request will repeat Count counts with Delay delay.
68+
// Default delay is 1 second.
69+
func (qt *cute) RequestRetry(count int) RequestHTTPBuilder {
70+
qt.tests[qt.countTests].Request.Retry.Count = count
71+
72+
return qt
73+
}
74+
75+
// RequestRetryDelay set delay for request repeat.
76+
// if response.Code != Expect.Code, than request will repeat Count counts with Delay delay.
77+
// Default delay is 1 second.
78+
func (qt *cute) RequestRetryDelay(delay time.Duration) RequestHTTPBuilder {
79+
qt.tests[qt.countTests].Request.Retry.Delay = delay
80+
81+
return qt
82+
}
83+
84+
// RequestRetryPolitic set politic for request repeat.
85+
// if response.Code != Expect.Code, than request will repeat Count counts with Delay delay.
86+
// if Optional is true and request is failed, than test step allure will be skipped, and t.Fail() will not execute.
87+
// If Broken is true and request is failed, than test step allure will be broken, and t.Fail() will not execute.
88+
func (qt *cute) RequestRetryPolitic(politic *RequestRetryPolitic) RequestHTTPBuilder {
89+
if politic == nil {
90+
panic("politic is nil in RequestRetryPolitic")
91+
}
92+
93+
qt.tests[qt.countTests].Request.Retry = politic
94+
95+
return qt
96+
}
97+
98+
// RequestRetryOptional set option politic for request repeat.
99+
// if Optional is true and request is failed, than test step allure will be skipped, and t.Fail() will not execute.
100+
func (qt *cute) RequestRetryOptional(option bool) RequestHTTPBuilder {
101+
qt.tests[qt.countTests].Request.Retry.Optional = option
102+
103+
return qt
104+
}
105+
106+
// RequestRetryBroken set broken politic for request repeat.
107+
// If Broken is true and request is failed, than test step allure will be broken, and t.Fail() will not execute.
108+
func (qt *cute) RequestRetryBroken(broken bool) RequestHTTPBuilder {
109+
qt.tests[qt.countTests].Request.Retry.Broken = broken
52110

53111
return qt
54112
}

builder_retry.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cute
2+
3+
import "time"
4+
5+
// Retry is a function for configure test repeat
6+
// if response.Code != Expect.Code or any of asserts are failed/broken than test will repeat counts with delay.
7+
// Default delay is 1 second.
8+
func (qt *cute) Retry(count int) MiddlewareRequest {
9+
if count < 1 {
10+
panic("count must be greater than 0")
11+
}
12+
13+
qt.tests[qt.countTests].Retry.MaxAttempts = count
14+
15+
return qt
16+
}
17+
18+
// RetryDelay set delay for test repeat.
19+
// if response.Code != Expect.Code or any of asserts are failed/broken than test will repeat counts with delay.
20+
// Default delay is 1 second.
21+
func (qt *cute) RetryDelay(delay time.Duration) MiddlewareRequest {
22+
if delay < 0 {
23+
panic("delay must be greater than or equal to 0")
24+
}
25+
26+
qt.tests[qt.countTests].Retry.Delay = delay
27+
28+
return qt
29+
}

builder_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ func TestHTTPTestMaker(t *testing.T) {
285285
Link(link).
286286
Description(desc).
287287
CreateStep(stepName).
288-
RequestRepeat(repeatCount).
289-
RequestRepeatDelay(repeatDelay).
288+
RequestRetry(repeatCount).
289+
RequestRetryDelay(repeatDelay).
290290
Request(req).
291291
ExpectExecuteTimeout(executeTime).
292292
ExpectStatus(status).
@@ -330,8 +330,8 @@ func TestHTTPTestMaker(t *testing.T) {
330330
require.Equal(t, setIssue, resHt.allureLinks.issue)
331331
require.Equal(t, setTestCase, resHt.allureLinks.testCase)
332332
require.Equal(t, link, resHt.allureLinks.link)
333-
require.Equal(t, repeatCount, resTest.Request.Repeat.Count)
334-
require.Equal(t, repeatDelay, resTest.Request.Repeat.Delay)
333+
require.Equal(t, repeatCount, resTest.Request.Retry.Count)
334+
require.Equal(t, repeatDelay, resTest.Request.Retry.Delay)
335335

336336
require.Equal(t, len(assertHeaders), len(resTest.Expect.AssertHeaders))
337337
require.Equal(t, len(assertHeadersT), len(resTest.Expect.AssertHeadersT))
@@ -360,7 +360,7 @@ func TestCreateDefaultTest(t *testing.T) {
360360
BeforeT: make([]BeforeExecuteT, 0),
361361
},
362362
Request: &Request{
363-
Repeat: new(RequestRepeatPolitic),
363+
Retry: new(RequestRetryPolitic),
364364
},
365365
Expect: &Expect{
366366
JSONSchema: new(ExpectJSONSchema),

cute.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,6 @@ func createAllureT(t *testing.T) *common.Common {
113113
return newT
114114
}
115115

116-
// executeTestsInsideStep is method for run group of tests inside provider.StepCtx
117-
func (qt *cute) executeTestsInsideStep(ctx context.Context, stepCtx provider.StepCtx) []ResultsHTTPBuilder {
118-
var (
119-
res = make([]ResultsHTTPBuilder, 0)
120-
)
121-
122-
// Cycle for change number of Test
123-
for i := 0; i <= qt.countTests; i++ {
124-
currentTest := qt.tests[i]
125-
126-
result := currentTest.executeInsideStep(ctx, stepCtx)
127-
128-
// Remove from base struct all asserts
129-
currentTest.clearFields()
130-
131-
res = append(res, result)
132-
}
133-
134-
return res
135-
}
136-
137116
// executeTests is method for run tests
138117
// It's could be table tests or usual tests
139118
func (qt *cute) executeTests(ctx context.Context, allureProvider allureProvider) []ResultsHTTPBuilder {
@@ -153,26 +132,49 @@ func (qt *cute) executeTests(ctx context.Context, allureProvider allureProvider)
153132
// Set current test name
154133
inT.Title(tableTestName)
155134

156-
res = append(res, qt.executeSingleTest(ctx, inT, currentTest))
135+
res = append(res, qt.executeInsideAllure(ctx, inT, currentTest))
157136
})
158137
} else {
159138
currentTest.Name = allureProvider.Name()
160139

161140
// set labels
162141
qt.setAllureInformation(allureProvider)
163142

164-
res = append(res, qt.executeSingleTest(ctx, allureProvider, currentTest))
143+
res = append(res, qt.executeInsideAllure(ctx, allureProvider, currentTest))
165144
}
166145
}
167146

168147
return res
169148
}
170149

171-
func (qt *cute) executeSingleTest(ctx context.Context, allureProvider allureProvider, currentTest *Test) ResultsHTTPBuilder {
150+
// executeInsideAllure is method for run test inside allure
151+
// It's could be table tests or usual tests
152+
func (qt *cute) executeInsideAllure(ctx context.Context, allureProvider allureProvider, currentTest *Test) ResultsHTTPBuilder {
172153
resT := currentTest.executeInsideAllure(ctx, allureProvider)
173154

174155
// Remove from base struct all asserts
175156
currentTest.clearFields()
176157

177158
return resT
178159
}
160+
161+
// executeTestsInsideStep is method for run group of tests inside provider.StepCtx
162+
func (qt *cute) executeTestsInsideStep(ctx context.Context, stepCtx provider.StepCtx) []ResultsHTTPBuilder {
163+
var (
164+
res = make([]ResultsHTTPBuilder, 0)
165+
)
166+
167+
// Cycle for change number of Test
168+
for i := 0; i <= qt.countTests; i++ {
169+
currentTest := qt.tests[i]
170+
171+
result := currentTest.executeInsideStep(ctx, stepCtx)
172+
173+
// Remove from base struct all asserts
174+
currentTest.clearFields()
175+
176+
res = append(res, result)
177+
}
178+
179+
return res
180+
}

examples/single_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func Test_Single_1(t *testing.T) {
3030
Description("some_description").
3131
Parallel().
3232
Create().
33-
RequestRepeat(3).
33+
RequestRetry(3).
3434
RequestBuilder(
3535
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
3636
cute.WithMarshalBody(struct {
@@ -96,14 +96,16 @@ func Test_Single_Broken(t *testing.T) {
9696
},
9797
).
9898
ExecuteTest(context.Background(), t)
99+
100+
t.Skip()
99101
}
100102

101103
func Test_Single_RepeatPolitic_Optional_Success_Test(t *testing.T) {
102104
cute.NewTestBuilder().
103105
Title("Test_Single_RepeatPolitic_Optional_Success_Test").
104106
Create().
105-
RequestRepeat(2).
106-
RequestRepeatOptional(true).
107+
RequestRetry(2).
108+
RequestRetryOptional(true).
107109
RequestBuilder(
108110
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
109111
).
@@ -120,8 +122,8 @@ func Test_Single_RepeatPolitic_Broken_Failed_Test(t *testing.T) {
120122
cute.NewTestBuilder().
121123
Title("Test_Single_RepeatPolitic_Broken_Failed_Test").
122124
Create().
123-
RequestRepeat(2).
124-
RequestRepeatOptional(true).
125+
RequestRetry(2).
126+
RequestRetryOptional(false).
125127
RequestBuilder(
126128
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
127129
).
@@ -173,8 +175,8 @@ func Test_Single_2_AllureRunner(t *testing.T) {
173175
Tag("single_test").
174176
Description("some_description").
175177
Create().
176-
RequestRepeatDelay(3*time.Second). // delay before new try
177-
RequestRepeat(3). // count attempts
178+
RequestRetryDelay(3*time.Second). // delay before new try
179+
RequestRetry(3). // count attempts
178180
RequestBuilder(
179181
cute.WithURL(u),
180182
cute.WithMethod(http.MethodGet),

0 commit comments

Comments
 (0)