Skip to content

Commit

Permalink
add test for As and Is function checking with standard library
Browse files Browse the repository at this point in the history
  • Loading branch information
aperezg committed Sep 22, 2019
1 parent d8ab995 commit e697750
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package errors

import (
"errors"
stdlib_errors "errors"
"fmt"
"io"
"reflect"
Expand Down Expand Up @@ -249,3 +250,25 @@ func TestErrorEquality(t *testing.T) {
}
}
}

func TestIs(t *testing.T) {
sentinelError := stdlib_errors.New("sentinel error")
wrap := Wrap(sentinelError, "wrap error")
if !Is(wrap, sentinelError) {
t.Errorf("Expected that '%v' error and the '%v' error should be of the same type", sentinelError, wrap)
}
}

func TestAs(t *testing.T) {
type myError struct {
error
}
err := &myError{stdlib_errors.New("error")}
wrap := Wrap(err, "wrap error")

var tt *myError
if !As(wrap, &tt) {
t.Errorf("Expected that '%v' error and the '%v' error should be of the same type", err, wrap)
}

}

0 comments on commit e697750

Please sign in to comment.