-
Notifications
You must be signed in to change notification settings - Fork 18
/
two_step_test.go
110 lines (95 loc) · 2.85 KB
/
two_step_test.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
//go:build example
// +build example
package examples
import (
"context"
"errors"
"fmt"
"net/http"
"testing"
"time"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/runner"
"github.com/ozontech/cute"
)
func Test_TwoSteps_1(t *testing.T) {
cute.NewTestBuilder().
Title("Test with two requests.").
Tags("two_steps").
Parallel().
CreateStep("Create entry /posts/1").
// CreateWithStep first step
RequestBuilder(
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodGet),
).
ExpectExecuteTimeout(10*time.Second).
ExpectStatus(http.StatusCreated).
NextTest().
CreateStep("Delete entry").
// CreateWithStep second step for delete
RequestBuilder(
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodDelete),
cute.WithHeaders(map[string][]string{
"some_auth_token": []string{fmt.Sprint(11111)},
}),
).
ExecuteTest(context.Background(), t)
}
func Test_TwoSteps_2_AllureRunner(t *testing.T) {
runner.Run(t, "Test with two steps", func(t provider.T) {
testBuilder := cute.NewHTTPTestMaker().NewTestBuilder()
testBuilder.
Title("Test with two requests executed by allure-go").
Tag("two_steps").
Description("some_description").
CreateStep("Request 1").
RequestBuilder(
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodGet),
).
ExpectStatus(http.StatusOK).
ExecuteTest(context.Background(), t)
testBuilder.
CreateStep("Request 2").
RequestBuilder(
cute.WithURI("https://jsonplaceholder.typicode.com/posts/2/comments"),
cute.WithMethod(http.MethodGet),
).
ExpectExecuteTimeout(10*time.Second).
ExpectStatus(http.StatusOK).
ExecuteTest(context.Background(), t)
})
}
func Test_TwoSteps_3(t *testing.T) {
responseCode := 0
// First step.
cute.NewTestBuilder().
Title("Test with two requests and parse body.").
Tag("two_steps").
Create().
RequestBuilder(
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodGet),
).
ExpectStatus(http.StatusOK).
RequireBody(func(body []byte) error {
return errors.New("example")
}).
NextTest().
AfterTestExecute(func(response *http.Response, errors []error) error { // Execute after first step
responseCode = response.StatusCode
fmt.Println("Hello from after test execute")
fmt.Println("Response code", responseCode)
return nil
}).
// Second step. This test isn't run, because previous test has failed require validation
Create().
RequestBuilder(
cute.WithURI("https://jsonplaceholder.typicode.com/posts/2/comments"),
cute.WithMethod(http.MethodDelete),
).
ExecuteTest(context.Background(), t)
fmt.Println("Response code from first request", responseCode)
}