-
Notifications
You must be signed in to change notification settings - Fork 18
/
assert_require.go
69 lines (51 loc) · 1.26 KB
/
assert_require.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
package cute
import (
"net/http"
"github.com/ozontech/cute/errors"
)
func requireAssertHeaders(assert AssertHeaders) AssertHeaders {
return func(headers http.Header) error {
err := assert(headers)
return wrapRequireError(err)
}
}
func requireAssertBody(assert AssertBody) AssertBody {
return func(body []byte) error {
err := assert(body)
return wrapRequireError(err)
}
}
func requireAssertResponse(assert AssertResponse) AssertResponse {
return func(resp *http.Response) error {
err := assert(resp)
return wrapRequireError(err)
}
}
func requireAssertHeadersT(assert AssertHeadersT) AssertHeadersT {
return func(t T, headers http.Header) error {
err := assert(t, headers)
return wrapRequireError(err)
}
}
func requireAssertBodyT(assert AssertBodyT) AssertBodyT {
return func(t T, body []byte) error {
err := assert(t, body)
return wrapRequireError(err)
}
}
func requireAssertResponseT(assert AssertResponseT) AssertResponseT {
return func(t T, resp *http.Response) error {
err := assert(t, resp)
return wrapRequireError(err)
}
}
func wrapRequireError(err error) error {
if err == nil {
return nil
}
if tErr, ok := err.(errors.RequireError); ok {
tErr.SetRequire(true)
return tErr.(error)
}
return errors.WrapRequireError(err)
}