-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathone_step_errors.go
81 lines (76 loc) · 2.12 KB
/
one_step_errors.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
package suite
import (
"context"
"errors"
"net/http"
"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"
cuteErrors "github.com/ozontech/cute/errors"
"github.com/ozontech/cute/examples"
)
func (i *ExampleSuite) Test_OneStep_Errors(t provider.T) {
var (
testBuilder = i.testMaker.NewTestBuilder()
)
testBuilder.
Title("Test with errors").
Tags("one_step", "some_local_tag", "suite", "json").
Parallel().
CreateStep("Example GET json request").
RequestBuilder(
cute.WithHeaders(map[string][]string{
"some_header": []string{"something"},
"some_array_header": []string{"1", "2", "3", "some_thing"},
}),
cute.WithURI(i.host.String()+"/posts/1/comments"),
cute.WithMethod(http.MethodGet),
cute.WithMarshalBody(
map[string]interface{}{
"key": "value",
"more_key": map[string]interface{}{
"some_value": "sss",
},
},
),
).
ExpectExecuteTimeout(10*time.Second).
ExpectJSONSchemaFile("file://./resources/example_valid_request.json").
AssertBody(
json.Equal("$[0].email", "something"),
json.Present("$[1].not_present"),
json.LengthGreaterThan("$", 99999),
json.Length("$", 0),
// Custom assert body
examples.CustomAssertBody(),
examples.CustomAssertBodyWithCustomError(),
).
AssertHeaders(
headers.Present("Content-Type"),
// Custom assert headers
examples.CustomAssertHeaders(),
).
AssertResponse(
examples.CustomAssertResponse(),
).
AssertHeadersT(
func(t cute.T, headers http.Header) error {
// Example pretty print error
return cuteErrors.NewAssertError("custom_assert", "example custom assert", "empty", "not empty") //
},
).
// Example optional
OptionalAssertBody( // example optional assert
func(body []byte) error {
return errors.New("some optional error from OptionalAssert")
},
).
AssertBody(
func(body []byte) error {
return cuteErrors.NewOptionalError("some optional error from creator") // example optional error
},
).
ExecuteTest(context.Background(), t)
}