-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathone_step.go
152 lines (136 loc) · 3.83 KB
/
one_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
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
package suite
import (
"context"
"net/http"
"net/url"
"path"
"time"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/cute"
"github.com/ozontech/cute/asserts/headers"
"github.com/ozontech/cute/asserts/json"
"github.com/ozontech/cute/examples"
)
/*
Example testing HTTP GET and validate body.
Validate:
1) Execute time
2) Status code
3) Validate body by json schema
4) Validate fields in json
Response:
[
{
"postId": 1,
"id": 1,
"name": "id labore ex et quam laborum",
"email": "Eliseo@gardner.biz",
"body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
},
{
"postId": 1,
"id": 2,
"name": "quo vero reiciendis velit similique earum",
"email": "Jayne_Kuhic@sydney.com",
"body": "est natus enim nihil est dolore omnis voluptatem numquam\net omnis occaecati quod ullam at\nvoluptatem error expedita pariatur\nnihil sint nostrum voluptatem reiciendis et"
},
{
"postId": 1,
"id": 3,
"name": "odio adipisci rerum aut animi",
"email": "Nikita@garfield.biz",
"body": "quia molestiae reprehenderit quasi aspernatur\naut expedita occaecati aliquam eveniet laudantium\nomnis quibusdam delectus saepe quia accusamus maiores nam est\ncum et ducimus et vero voluptates excepturi deleniti ratione"
},
{
"postId": 1,
"id": 4,
"name": "alias odio sit",
"email": "Lew@alysha.tv",
"body": "non et atque\noccaecati deserunt quas accusantium unde odit nobis qui voluptatem\nquia voluptas consequuntur itaque dolor\net qui rerum deleniti ut occaecati"
},
{
"postId": 1,
"id": 5,
"name": "vero eaque aliquid doloribus et culpa",
"email": "Hayden@althea.biz",
"body": "harum non quasi et ratione\ntempore iure ex voluptates in ratione\nharum architecto fugit inventore cupiditate\nvoluptates magni quo et"
}
]
*/
func (i *ExampleSuite) Test_OneStep(t provider.T) {
var (
testBuilder = i.testMaker.NewTestBuilder()
)
u, _ := url.Parse(i.host.String())
u.Path = path.Join(u.Path, "/posts/1/comments")
testBuilder.
Title("Test with one step").
Tags("one_stp", "some_local_tag", "suite", "json").
Feature("some_feature").
Epic("some_epic").
Description("some_description").
Parallel().
CreateStep("Example GET json request").
AfterExecuteT(func(t cute.T, resp *http.Response, errs []error) error {
if len(errs) != 0 {
return nil
}
/*
Implement some logic
*/
return nil
},
// After failed test
func(t cute.T, resp *http.Response, errs []error) error {
if len(errs) == 0 {
return nil
}
/*
Implement some logic
*/
return nil
},
).
RequestBuilder(
cute.WithHeaders(map[string][]string{
"some_header": []string{"something"},
"some_array_header": []string{"1", "2", "3", "some_thing"},
}),
cute.WithURL(u),
cute.WithMethod(http.MethodGet),
).
ExpectExecuteTimeout(10*time.Second).
ExpectJSONSchemaFile("file://./resources/example_valid_request.json").
ExpectStatus(http.StatusOK).
AssertBody(
json.Equal("$[0].email", "Eliseo@gardner.biz"),
json.Present("$[1].name"),
json.NotPresent("$[1].some_not_present"),
json.LengthGreaterThan("$", 3),
json.Length("$", 5),
json.LengthLessThan("$", 100),
json.NotEqual("$[3].name", "kekekekeke"),
// Custom assert body
examples.CustomAssertBody(),
).
AssertBodyT(
// Custom assert body with testing.tb
examples.CustomAssertBodyT(),
func(t cute.T, body []byte) error {
/*
Implement here logic with TB
*/
time.Sleep(5 * time.Second)
return nil
},
).
AssertHeaders(
headers.Present("Content-Type"),
// Custom assert headers
examples.CustomAssertHeaders(),
).
AssertResponse(
examples.CustomAssertResponse(),
).
ExecuteTest(context.Background(), t)
}