Skip to content

Commit

Permalink
chore: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtomasi committed Sep 19, 2021
1 parent 5783b21 commit 0b1946d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ func functionThatWrapsError() error {
return nil
}

func functionThatWrapsErrorWithFormat() error {
err := functionThatReturnsInitialError()
if err != nil {
return z.Wrapf(functionThatReturnsInitialError(), "Wrapf %s", "error")
}

return nil
}

func functionThatWrapsErrorUsingPtr() (err error) {
defer z.WrapPtr(&err, "WrapPtr error")

Expand All @@ -32,6 +41,17 @@ func functionThatWrapsErrorUsingPtr() (err error) {
return nil
}

func functionThatWrapsErrorUsingPtrWithFormat() (err error) {
defer z.WrapPtrf(&err, "WrapPtrf %s", "error")

err = functionThatReturnsInitialError()
if err != nil {
return err
}

return nil
}

func TestWrap_Integration(t *testing.T) {
err := functionThatWrapsError()
assert.Error(t, err)
Expand All @@ -44,6 +64,18 @@ func TestWrapPtr_Integration(t *testing.T) {
assert.Equal(t, "WrapPtr error: initial error", err.Error())
}

func TestWrapf_Integration(t *testing.T) {
err := functionThatWrapsErrorWithFormat()
assert.Error(t, err)
assert.Equal(t, "Wrapf error: initial error", err.Error())
}

func TestWrapPtrf_Integration(t *testing.T) {
err := functionThatWrapsErrorUsingPtrWithFormat()
assert.Error(t, err)
assert.Equal(t, "WrapPtrf error: initial error", err.Error())
}

func TestWrapWithOpts_WithType(t *testing.T) {
errorType := z.ErrorType("foo")
baseErr := functionThatWrapsError()
Expand Down

0 comments on commit 0b1946d

Please sign in to comment.