-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtwo_steps.go
96 lines (83 loc) · 1.9 KB
/
two_steps.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
package suite
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"path"
"strings"
"time"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/cute"
"github.com/ozontech/cute/examples"
)
/*
Example testing HTTP POST, validate body and make second request.
Validate:
1) Execute time
2) Status code
*/
func (i *ExampleSuite) Test_TwoSteps(t provider.T) {
var (
testBuilder = i.testMaker.NewTestBuilder()
// Request body
r = `
{
"result": {
"author": "Yours Truly",
"date": "15.11.1993",
"slides": [
{
"title": "Beer",
"type": "drink"
},
{
"title": "Apple",
"type": "fruit"
},
{
"title": "Orange",
"type": "fruit"
}
],
"Info": {
"shop": "BigShopPlus",
"address": "address"
},
"title": "Sample Show"
}
}
`
)
u, _ := url.Parse(i.host.String())
u.Path = path.Join(u.Path, "/posts/1/comments")
req, _ := http.NewRequest(http.MethodPost, u.String(), ioutil.NopCloser(strings.NewReader(r)))
req.Header = map[string][]string{
"some_auth_token": []string{fmt.Sprint(11111)},
}
testBuilder.
Title("Test in suite with two steps").
Tags("suite", "some_tag").
Parallel().
CreateStep("Creat entry /posts/1").
// CreateWithStep first step
Request(req).
ExpectExecuteTimeout(10*time.Second).
ExpectStatus(http.StatusCreated).
AssertBody(
// Custom assert body
examples.CustomAssertBody(),
).
NextTest().
CreateStep("Delete entry").
// CreateWithStep second step for delete
RequestBuilder(
cute.WithURL(u),
cute.WithMethod(http.MethodDelete),
cute.WithHeaders(map[string][]string{
"some_auth_token": []string{fmt.Sprint(11111)},
}),
).
ExecuteTest(context.Background(), t)
}