-
Notifications
You must be signed in to change notification settings - Fork 18
/
assert_optional_test.go
98 lines (76 loc) · 2.21 KB
/
assert_optional_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
package cute
import (
"errors"
"net/http"
"testing"
cuteErrors "github.com/ozontech/cute/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestOptionalAssertResponse(t *testing.T) {
v := &http.Response{}
f := func(*http.Response) error {
return errors.New("test error")
}
err := optionalAssertResponse(f)(v)
if optionalError, ok := err.(cuteErrors.OptionalError); assert.True(t, ok) {
require.True(t, optionalError.IsOptional())
}
}
func TestOptionalAssertResponseT(t *testing.T) {
v := &http.Response{}
f := func(T, *http.Response) error {
return errors.New("test error")
}
err := optionalAssertResponseT(f)(nil, v)
if optionalError, ok := err.(cuteErrors.OptionalError); assert.True(t, ok) {
require.True(t, optionalError.IsOptional())
}
}
func TestOptionalAssertHeaders(t *testing.T) {
h := http.Header{}
f := func(http.Header) error {
return errors.New("test error")
}
err := optionalAssertHeaders(f)(h)
if optionalError, ok := err.(cuteErrors.OptionalError); assert.True(t, ok) {
require.True(t, optionalError.IsOptional())
}
}
func TestOptionalAssertHeadersT(t *testing.T) {
h := http.Header{}
f := func(T, http.Header) error {
return errors.New("test error")
}
err := optionalAssertHeadersT(f)(nil, h)
if optionalError, ok := err.(cuteErrors.OptionalError); assert.True(t, ok) {
require.True(t, optionalError.IsOptional())
}
}
func TestOptionalAssertBody(t *testing.T) {
v := []byte{}
f := func([]byte) error {
return errors.New("test error")
}
err := optionalAssertBody(f)(v)
if optionalError, ok := err.(cuteErrors.OptionalError); assert.True(t, ok) {
require.True(t, optionalError.IsOptional())
}
}
func TestOptionalAssertBodyT(t *testing.T) {
v := []byte{}
f := func(T, []byte) error {
return errors.New("test error")
}
err := optionalAssertBodyT(f)(nil, v)
if optionalError, ok := err.(cuteErrors.OptionalError); assert.True(t, ok) {
require.True(t, optionalError.IsOptional())
}
}
func TestWrapOptionalError(t *testing.T) {
err := errors.New("test error")
optError := wrapOptionalError(err)
if optionalError, ok := optError.(cuteErrors.OptionalError); assert.True(t, ok) {
require.True(t, optionalError.IsOptional())
}
}