-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes Pass ...Wrapper list to New constructor #31
- Loading branch information
1 parent
7f25436
commit bffb7f6
Showing
2 changed files
with
47 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package fault | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type testNewExampleWraper struct{ e error } | ||
|
||
func (e *testNewExampleWraper) Error() string { return "example wrapper" } | ||
func (e *testNewExampleWraper) Unwrap() error { return e.e } | ||
|
||
func testNewExampleWrap() func(error) error { | ||
return func(err error) error { | ||
return &testNewExampleWraper{err} | ||
} | ||
} | ||
|
||
func TestNew(t *testing.T) { | ||
r := require.New(t) | ||
var err error | ||
|
||
err = New("TestNew example") | ||
r.Error(err) | ||
|
||
err = New("TestNew example", testNewExampleWrap()) | ||
r.Error(err) | ||
_, casts := err.(*testNewExampleWraper) | ||
r.True(casts) | ||
} | ||
|
||
func TestNewf(t *testing.T) { | ||
r := require.New(t) | ||
|
||
err := Newf("TestNew example %s", "one") | ||
r.Error(err) | ||
r.Equal("TestNew example one", err.Error()) | ||
} |