-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE-44] add broken validation (#61)
* [ISSUE-44] add broken validation * [ISSUE-44] add wrappers for errors, fix docs and linter * [ISSUE-44] fix docs, test * [ISSUE-44] fix linter
- Loading branch information
Showing
29 changed files
with
925 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cute | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/ozontech/cute/errors" | ||
) | ||
|
||
func brokenAssertHeaders(assert AssertHeaders) AssertHeaders { | ||
return func(headers http.Header) error { | ||
err := assert(headers) | ||
|
||
return wrapBrokenError(err) | ||
} | ||
} | ||
|
||
func brokenAssertBody(assert AssertBody) AssertBody { | ||
return func(body []byte) error { | ||
err := assert(body) | ||
|
||
return wrapBrokenError(err) | ||
} | ||
} | ||
|
||
func brokenAssertResponse(assert AssertResponse) AssertResponse { | ||
return func(resp *http.Response) error { | ||
err := assert(resp) | ||
|
||
return wrapBrokenError(err) | ||
} | ||
} | ||
|
||
func brokenAssertHeadersT(assert AssertHeadersT) AssertHeadersT { | ||
return func(t T, headers http.Header) error { | ||
err := assert(t, headers) | ||
|
||
return wrapBrokenError(err) | ||
} | ||
} | ||
|
||
func brokenAssertBodyT(assert AssertBodyT) AssertBodyT { | ||
return func(t T, body []byte) error { | ||
err := assert(t, body) | ||
|
||
return wrapBrokenError(err) | ||
} | ||
} | ||
|
||
func brokenAssertResponseT(assert AssertResponseT) AssertResponseT { | ||
return func(t T, resp *http.Response) error { | ||
err := assert(t, resp) | ||
|
||
return wrapBrokenError(err) | ||
} | ||
} | ||
|
||
func wrapBrokenError(err error) error { | ||
if err == nil { | ||
return nil | ||
} | ||
|
||
if tErr, ok := err.(errors.BrokenError); ok { | ||
tErr.SetBroken(true) | ||
|
||
return tErr.(error) | ||
} | ||
|
||
return errors.WrapBrokenError(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 TestBrokenAssertResponse(t *testing.T) { | ||
v := &http.Response{} | ||
f := func(_ *http.Response) error { | ||
return errors.New("test error") | ||
} | ||
|
||
err := brokenAssertResponse(f)(v) | ||
|
||
if BrokenError, ok := err.(cuteErrors.BrokenError); assert.True(t, ok) { | ||
require.True(t, BrokenError.IsBroken()) | ||
} | ||
} | ||
|
||
func TestBrokenAssertResponseT(t *testing.T) { | ||
v := &http.Response{} | ||
f := func(T, *http.Response) error { | ||
return errors.New("test error") | ||
} | ||
|
||
err := brokenAssertResponseT(f)(nil, v) | ||
|
||
if BrokenError, ok := err.(cuteErrors.BrokenError); assert.True(t, ok) { | ||
require.True(t, BrokenError.IsBroken()) | ||
} | ||
} | ||
|
||
func TestBrokenAssertHeaders(t *testing.T) { | ||
h := http.Header{} | ||
f := func(_ http.Header) error { | ||
return errors.New("test error") | ||
} | ||
|
||
err := brokenAssertHeaders(f)(h) | ||
|
||
if BrokenError, ok := err.(cuteErrors.BrokenError); assert.True(t, ok) { | ||
require.True(t, BrokenError.IsBroken()) | ||
} | ||
} | ||
|
||
func TestBrokenAssertHeadersT(t *testing.T) { | ||
h := http.Header{} | ||
f := func(T, http.Header) error { | ||
return errors.New("test error") | ||
} | ||
|
||
err := brokenAssertHeadersT(f)(nil, h) | ||
|
||
if BrokenError, ok := err.(cuteErrors.BrokenError); assert.True(t, ok) { | ||
require.True(t, BrokenError.IsBroken()) | ||
} | ||
} | ||
|
||
func TestBrokenAssertBody(t *testing.T) { | ||
v := []byte{} | ||
f := func(_ []byte) error { | ||
return errors.New("test error") | ||
} | ||
|
||
err := brokenAssertBody(f)(v) | ||
|
||
if BrokenError, ok := err.(cuteErrors.BrokenError); assert.True(t, ok) { | ||
require.True(t, BrokenError.IsBroken()) | ||
} | ||
} | ||
|
||
func TestBrokenAssertBodyT(t *testing.T) { | ||
v := []byte{} | ||
f := func(T, []byte) error { | ||
return errors.New("test error") | ||
} | ||
|
||
err := brokenAssertBodyT(f)(nil, v) | ||
|
||
if BrokenError, ok := err.(cuteErrors.BrokenError); assert.True(t, ok) { | ||
require.True(t, BrokenError.IsBroken()) | ||
} | ||
} | ||
|
||
func TestWrapBrokenError(t *testing.T) { | ||
err := errors.New("test error") | ||
|
||
optError := wrapBrokenError(err) | ||
if BrokenError, ok := optError.(cuteErrors.BrokenError); assert.True(t, ok) { | ||
require.True(t, BrokenError.IsBroken()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.