-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathcustom_asserts.go
78 lines (62 loc) · 1.58 KB
/
custom_asserts.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
package examples
import (
"errors"
"net/http"
"github.com/ozontech/allure-go/pkg/allure"
"github.com/ozontech/cute"
cuteErrors "github.com/ozontech/cute/errors"
"github.com/stretchr/testify/require"
)
func CustomAssertBodyWithCustomError() cute.AssertBody {
return func(bytes []byte) error {
if len(bytes) == 0 {
return cuteErrors.NewAssertError("customAssertBodyWithCustomError", "body must be not empty", "len is 0", "len more 0")
}
return nil
}
}
func CustomAssertBody() cute.AssertBody {
return func(bytes []byte) error {
if len(bytes) == 0 {
return errors.New("response body is empty")
}
return nil
}
}
func CustomAssertBodyT() cute.AssertBodyT {
return func(t cute.T, bytes []byte) error {
t.WithNewParameters("example_parameter", "example")
require.GreaterOrEqual(t, len(bytes), 100)
return nil
}
}
func CustomAssertBodyWithAllureStep() cute.AssertBodyT {
return func(t cute.T, bytes []byte) error {
step := allure.NewSimpleStep("Custom assert step")
defer func() {
t.Step(step)
}()
if len(bytes) == 0 {
step.Status = allure.Failed
step.WithAttachments(allure.NewAttachment("Error", allure.Text, []byte("response body is empty")))
return nil
}
return nil
}
}
func CustomAssertHeaders() cute.AssertHeaders {
return func(headers http.Header) error {
if len(headers) == 0 {
return errors.New("response without headers")
}
return nil
}
}
func CustomAssertResponse() cute.AssertResponse {
return func(resp *http.Response) error {
if resp.ContentLength == 0 {
return errors.New("content length is zero")
}
return nil
}
}